Skip to content

Commit

Permalink
IMPLICIT MULTIPLICATION 2x 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pannous committed Nov 30, 2024
1 parent 7ba9df3 commit 7c83ef3
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 17 deletions.
1 change: 1 addition & 0 deletions .lldbinit
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type summary add Signature --summary-string "${var.debug_name}"

# type summary add Signature --summary-string "@${var.type_index} args#${var.types._size} ${var.debug_name} -> ${var.wasm_return_type}"

type summary add --summary-string "${var.value} ${var.kind}" Type
type summary add --summary-string "${var%E} ${var%x} ${var%B}" Valtype
type summary add --summary-string "${var%E}" wabt::Result
type summary add --summary-string "${var.offset_}" wabt::Stream
Expand Down
Binary file modified docs/assets/wasp-hosted.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/examples.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let exampleCode = {
// getElementById: '$canvas.style',
getElementById: '$canvas.tagName', // not automatically printed because …?
// getElementById: 'a=$canvas.tagName;print(a)',
// getElementById: '$canvas.tagName', // not automatically printed because …?
getElementById: 'a=$canvas.tagName;print(a)',
// getElementById: 'a:auto=$canvas.tagName;print(a)',
// getElementById: 'a:node=$canvas.tagName;print(a)',// todo not a type!
// getElementById: 'a:string=$canvas.tagName;print(a)',
Expand Down
9 changes: 6 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/hint/show-hint.min.js"></script>-->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/hint/javascript-hint.min.js"></script>-->

<!-- <script src="https://webassembly.github.io/wabt/demo/libwabt.js"></script>-->
<!-- <script> WabtModule().then(function (wabt) {-->

<script src="https://cdn.jsdelivr.net/npm/@webassemblyjs/[email protected]/lib/index.js"></script>
<script src="https://webassembly.github.io/wabt/demo/libwabt.js"></script>
<script> WabtModule().then(function (wabt) {
window.wabt = wabt;
console.log('wabt loaded', wabt);
});</script>
</head>
<body>
<!--<body style="background: cornsilk">-->
Expand Down
13 changes: 9 additions & 4 deletions docs/wasp.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ let imports = {
print("CALLING getExternRefPropertyValue", ref, prop)
if (ref && typeof ref[prop] !== 'undefined') {
print("getExternRefPropertyValue OK ", ref, prop, ref[prop])
return smartResult(ref[prop])
// return String(ref[prop])
return string(ref[prop], app.memory)
// return smartResult(ref[prop])
} else if (ref && typeof ref.getAttribute === 'function') {
// check attribute
let attribute = ref.getAttribute(prop);
Expand Down Expand Up @@ -1026,7 +1026,7 @@ function load_compiler() {
async function run_wasm(buf_pointer, buf_size) {
try { // WE WANT PURE STACK TRACE
wasm_buffer = buffer.subarray(buf_pointer, buf_pointer + buf_size)
// wasm_to_wat(wasm_buffer)
wasm_to_wat(wasm_buffer)
// download_file(wasm_buffer, "emit.wasm", "wasm")

app_module = await WebAssembly.compile(wasm_buffer, {builtins: ['js-string']})
Expand Down Expand Up @@ -1085,6 +1085,10 @@ async function run_wasm(buf_pointer, buf_size) {

function wasm_to_wat(buffer) {
try {
const parsed = window.WebAssemblyParser.decode(buffer);
console.log(parsed)
// editor.setValue(parsed.toText());

wabtFeatures = {
exceptions: true,
mutable_globals: true,
Expand All @@ -1108,7 +1112,8 @@ function wasm_to_wat(buffer) {
// console.log(result);
editor.setValue(result)
} catch (e) {
error(e)
console.log("wasm_to_wat error")
console.log(e) // but don't overwrite the editor
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/NodeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ enum Kind /* 32 bit*/ {// todo: merge Node.kind with Node.class(?)
reals = 0x7C, /* ≠ float64 , just hides bugs, these concepts should not be mixed */
realsF = 0x7D,/* ≠ float32 , just hides bugs, these concepts should not be mixed */
longs = 0x7E, // the signature of parameters/variables is independent!
long32 = 0x7F, /* ≠ int32 , just hides bugs, these concepts should not be mixed */
long32 = 0x7F, /* int stored in long node field ≠ int32 , just hides bugs, these concepts should not be mixed */

flag_entry = longs, // special semantics at compile time for now
enum_entry = longs, // special semantics at compile time for now
Expand Down
17 changes: 12 additions & 5 deletions source/Wasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,20 @@ class Wasp {
}
// if (!isFinite(number)) {
// parseError("Bad number");
// } else {
// }
if (base != 10) todo("base "s + base);
if (is_identifier(ch))
print("IMPLICIT MULTIPLICATION!?"); // now what?
Node &number_node = *new Node(number0);
if (not is_identifier(ch)) {
return number_node;
} else {
// print("IMPLICIT MULTIPLICATION!?"); // YES! now what?
// ch!=' ' and not is_operator(ch) and not isWhiteSpace(ch) and not is_bracket(ch) and not is_grouper(ch) and not and not is_operator(ch) and isDigit(ch)
return *new Node(number0); // {number0}; //wow cPP
// }
Node &mult = *new Node("*");
mult.kind = operators;// binops;
mult.add(number_node);
mult.add(Node(identifier()).setType(reference).clone());
return mult;
}
};

int parseInt(char next_digit, int base) {
Expand Down
11 changes: 10 additions & 1 deletion source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ void testPolymorphism2() {
check_is(function.variants[1].signature.parameters[0].type, (Type) float32);
}


void testPolymorphism3() {
assert_emit("fun test(string a){return a};\nfun test(float b){return b+1};\ntest('ok')", "ok");
assert_emit("fun test(string a){return a};\nfun test(float b){return b+1};\ntest(1.0)", 2.0);
}

//#import "pow.h"
//void testOwnPowerExponentialLogarithm() {
// check_is(exp(1), 2.718281828459045);
Expand Down Expand Up @@ -3457,6 +3463,8 @@ void pleaseFix() {
// 2022-12-28 : 3 sec WITH runtime_emit, wasmedge on M1 WOW ALL TESTS PASSING
// ⚠️ CANNOT USE assert_emit in WASM! ONLY via void testRun();
void testCurrent() {
test_implicit_multiplication(); // todo in parser how?

assert_emit("-42", -42)
#if WEBAPP
testHostIntegration();
Expand All @@ -3470,6 +3478,7 @@ void testCurrent() {
testTypes();
testPolymorphism();
testPolymorphism2();
testPolymorphism3();
// testDom();
assert_emit("global x=7", 7);
assert_eval("if 0:3", false);
Expand All @@ -3486,6 +3495,7 @@ void testCurrent() {

// testInclude();
// check_is("τ≈6.2831853",true);
assert_emit("τ≈6.2831853", true);
// assert_emit("square := it*it; square 3", 9);
// assert_emit("a = [1, 2, 3]; a[1] == a#1", false);
// assert_emit("a = [1, 2, 3]; a[1] == a#1", 0);
Expand All @@ -3495,7 +3505,6 @@ void testCurrent() {
// assert_emit("√ π ²", pi);
// assert_emit("√π²", pi);

// test_implicit_multiplication(); todo in parser how?

// testGlobals();
// testTypeConfusion();
Expand Down
9 changes: 8 additions & 1 deletion source/wasm_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,13 +1400,17 @@ Code emitValue(Node &node, Function &context) {
if (not knownSymbol(name, context))
error("UNKNOWN symbol "s + name + " in context " + context);
if (node.value.node) {
if (name == node.value.string)
goto emit_getter_block;
Node &value = *node.value.node;
warn("HOLUP! x:42 is a reference? then *node.value.node makes no sense!!!");// todo FIX!!
code.add(emitSetter(node, value, context));
} else {
emit_getter_block:
auto local = context.locals[name];
code.addByte(get_local);// todo skip repeats
code.addByte(local.position);// base location stored in variable!
last_type = local.type;
if (node.length > 0) {
if (use_wasm_arrays)
return emitWasmArrayGetter(node, context, local);
Expand Down Expand Up @@ -1816,7 +1820,10 @@ Type commonType(Type lhs, Type rhs) {
if (lhs == rhs)return lhs;
if (lhs == i64 and rhs == int32) return i64;
if (lhs == int32 and rhs == i64) return i64;
if (lhs == unknown_type and rhs == i64) return i64;// bad guess, could be any object * n !
if (lhs == unknown_type) return rhs;// bad guess, could be any object * n !
// if (lhs == reference) return rhs;// bad guess, could be any object * n !
// if(rhs == reference) return lhs;// bad guess, could be any object * n !
// if(rhs == unknown_type) return lhs;// bad guess, could be any object * n !
if (lhs == float64 or rhs == float64)return float64;
if (lhs == float32 or rhs == float32)return float32;
return lhs; // todo!
Expand Down

0 comments on commit 7c83ef3

Please sign in to comment.