From 7c83ef38dbad88eae523308adb5288fee082c637 Mon Sep 17 00:00:00 2001 From: pannous Date: Sat, 30 Nov 2024 18:35:54 +0100 Subject: [PATCH] IMPLICIT MULTIPLICATION 2x 2 --- .lldbinit | 1 + docs/assets/wasp-hosted.wasm | Bin 4062188 -> 4062186 bytes docs/examples.js | 4 ++-- docs/index.html | 9 ++++++--- docs/wasp.js | 13 +++++++++---- source/NodeTypes.h | 2 +- source/Wasp.cpp | 17 ++++++++++++----- source/tests.cpp | 11 ++++++++++- source/wasm_emitter.cpp | 9 ++++++++- 9 files changed, 49 insertions(+), 17 deletions(-) diff --git a/.lldbinit b/.lldbinit index 9cc7b40b..bf62d2b1 100644 --- a/.lldbinit +++ b/.lldbinit @@ -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 diff --git a/docs/assets/wasp-hosted.wasm b/docs/assets/wasp-hosted.wasm index e4858fbaf65081c2e530ce169cff1b59b666c595..68aa3e69a5dc4528a7bcf6c84de6ec16dc6dd7ab 100755 GIT binary patch delta 278 zcmWm6JxBrp7>Ds*JuCaN(yY_U>&uV6v{Sp(YsdqKAficdX%KF0Y(3-;2SM}E))Z6+ zE#bS^+}M>|5RGlpu4C8m+a8|ZexG_C0|X!Z5D>sHMlgyX#xRZvOkxTlOk)PK2qS_y zL@|#Ah=?JMMJ!<%2}oGMD%P-$4J4658X0V23)|Si?sN9Yp^8~`vRrj?kuYg)etXP+UeGPy#S0H@I_I;G!pjL=a!4xLn)m87i=KV% zG?l2IdS+KwxT_z0+a&N)xYP;=W%9)==~_KD4YA}Ydn#;*>Q|e7xZ$WbLh!#CA`*hu Q>8n~ZHCJWLJ-ko;0ezunGynhq delta 280 zcmW;Ey-NZC7{_rRy{ohrE6q|X?ai0o&Q9&Ju0e%@putIM3IuCwZ8MG^90birV@psS zw1m%Me?y1jL9{l7yN(?VpY6-{x8J9p;}!%rJP;sa2*VhG7e0()4C9!9ACs8EGy(`> z1|iI14q-$P#XJ_Uh#2Bn!ZKE{iZvvVL<(uFV*{Jm!uGpVw5Y0=EQw22CYT~yuMRR? z9qh;wwfQb7o9A?_E1JxTmNn9J$)B%T`--> - - - + + + diff --git a/docs/wasp.js b/docs/wasp.js index 56651f72..54dd9f63 100644 --- a/docs/wasp.js +++ b/docs/wasp.js @@ -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); @@ -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']}) @@ -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, @@ -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 } } diff --git a/source/NodeTypes.h b/source/NodeTypes.h index c000a411..ea0273f0 100644 --- a/source/NodeTypes.h +++ b/source/NodeTypes.h @@ -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 diff --git a/source/Wasp.cpp b/source/Wasp.cpp index dfacf68a..3df26699 100644 --- a/source/Wasp.cpp +++ b/source/Wasp.cpp @@ -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) { diff --git a/source/tests.cpp b/source/tests.cpp index ca8da750..925b4086 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -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); @@ -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(); @@ -3470,6 +3478,7 @@ void testCurrent() { testTypes(); testPolymorphism(); testPolymorphism2(); + testPolymorphism3(); // testDom(); assert_emit("global x=7", 7); assert_eval("if 0:3", false); @@ -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); @@ -3495,7 +3505,6 @@ void testCurrent() { // assert_emit("√ π ²", pi); // assert_emit("√π²", pi); -// test_implicit_multiplication(); todo in parser how? // testGlobals(); // testTypeConfusion(); diff --git a/source/wasm_emitter.cpp b/source/wasm_emitter.cpp index ebad6daf..46b27894 100644 --- a/source/wasm_emitter.cpp +++ b/source/wasm_emitter.cpp @@ -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); @@ -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!