diff --git a/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala b/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala index d14737e39..edfffb7a4 100644 --- a/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala +++ b/hkmc2/jvm/src/test/scala/hkmc2/JSBackendDiffMaker.scala @@ -13,12 +13,14 @@ import codegen.Block import codegen.js.Scope import hkmc2.syntax.Tree.Ident import hkmc2.codegen.Path +import hkmc2.Diagnostic.Source abstract class JSBackendDiffMaker extends MLsDiffMaker: val debugLowering = NullaryCommand("dl") val js = NullaryCommand("js") - val sjs = NullaryCommand("sjs") + val showSanitizedJS = NullaryCommand("ssjs") + val showJS = NullaryCommand("sjs") val showRepl = NullaryCommand("showRepl") val silent = NullaryCommand("silent") val noSanityCheck = NullaryCommand("noSanityCheck") @@ -49,7 +51,29 @@ abstract class JSBackendDiffMaker extends MLsDiffMaker: override def processTerm(blk: semantics.Term.Blk, inImport: Bool)(using Raise): Unit = super.processTerm(blk, inImport) - if js.isSet then + val outerRaise: Raise = summon + var showingJSYieldedCompileError = false + if showJS.isSet then + given Raise = + case d @ ErrorReport(source = Source.Compilation) => + showingJSYieldedCompileError = true + outerRaise(d) + case d => outerRaise(d) + val low = ltl.givenIn: + new codegen.Lowering + with codegen.LoweringSelSanityChecks(instrument = false) + with codegen.LoweringTraceLog(instrument = false) + given Elaborator.Ctx = curCtx + val jsb = new JSBuilder + with JSBuilderArgNumSanityChecks(instrument = false) + val le = low.program(blk) + val nestedScp = baseScp.nest + val je = nestedScp.givenIn: + jsb.program(le, N, wd) + val jsStr = je.stripBreaks.mkString(100) + output(s"JS (unsanitized):") + output(jsStr) + if js.isSet && !showingJSYieldedCompileError then val low = ltl.givenIn: new codegen.Lowering with codegen.LoweringSelSanityChecks(noSanityCheck.isUnset) @@ -71,7 +95,7 @@ abstract class JSBackendDiffMaker extends MLsDiffMaker: val je = nestedScp.givenIn: jsb.program(le, N, wd) val jsStr = je.stripBreaks.mkString(100) - if sjs.isSet then + if showSanitizedJS.isSet then output(s"JS:") output(jsStr) def mkQuery(prefix: Str, jsStr: Str) = diff --git a/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala b/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala index 20bda70ca..d56db3407 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala @@ -144,7 +144,8 @@ extends Importer: cls.definedSymbols.get(nme.name) match case s @ S(clsSym) => s case N => - raise(ErrorReport(msg"Module '${cls.symbol.nme}' does not contain member '${nme.name}'" -> srcTree.toLoc :: Nil)) + raise(ErrorReport(msg"${cls.k.desc.capitalize} '${cls.symbol.nme + }' does not contain member '${nme.name}'" -> srcTree.toLoc :: Nil)) N case N => N diff --git a/hkmc2/shared/src/test/mlscript/basics/Classes.mls b/hkmc2/shared/src/test/mlscript/basics/Classes.mls index 633cebad3..9371d1ad8 100644 --- a/hkmc2/shared/src/test/mlscript/basics/Classes.mls +++ b/hkmc2/shared/src/test/mlscript/basics/Classes.mls @@ -33,7 +33,7 @@ class Foo(x: Int) { log("Hello!") } //│ ╔══[ERROR] Expected a valid definition head, found block instead //│ ║ l.32: class Foo(x: Int) { log("Hello!") } //│ ╙── ^^^^^^^^^^^^^ -//│ JS: +//│ JS (unsanitized): //│ this. = class { constructor() { } toString() { return ""; } }; null //│ > try { this. = class { constructor() { } toString() { return ""; } }; null } catch (e) { console.log('\u200B' + e + '\u200B'); } //│ > ^ diff --git a/hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls b/hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls index bfe257949..f33673a87 100644 --- a/hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls +++ b/hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls @@ -5,50 +5,28 @@ fun f(n1: Int): Int = n1 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let n1 = args[0]; -//│ return n1; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f(n1) { return n1; } null f(42) -//│ JS: +//│ JS (unsanitized): //│ this.f(42) //│ = 42 fun f(n1: Int)(n2: Int): Int = (10 * n1 + n2) -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let n1 = args[0]; -//│ return (...args1) => { -//│ globalThis.Predef.checkArgs("", 1, true, args1.length); -//│ let n2 = args1[0]; -//│ let tmp; -//│ tmp = 10 * n1; -//│ return tmp + n2; -//│ }; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f(n1) { return (n2) => { let tmp; tmp = 10 * n1; return tmp + n2; }; } null f(4)(2) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.f(4); tmp(2) ?? null //│ = 42 fun f(n1: Int)(n2: Int)(n3: Int): Int = 10 * (10 * n1 + n2) + n3 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let n1 = args[0]; -//│ return (...args1) => { -//│ globalThis.Predef.checkArgs("", 1, true, args1.length); -//│ let n2 = args1[0]; -//│ return (...args2) => { -//│ globalThis.Predef.checkArgs("", 1, true, args2.length); -//│ let n3 = args2[0]; +//│ JS (unsanitized): +//│ function f(n1) { +//│ return (n2) => { +//│ return (n3) => { //│ let tmp, tmp1, tmp2; //│ tmp = 10 * n1; //│ tmp1 = tmp + n2; @@ -60,24 +38,16 @@ fun f(n1: Int)(n2: Int)(n3: Int): Int = 10 * (10 * n1 + n2) + n3 //│ null f(4)(2)(0) -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1; tmp = this.f(4); tmp1 = tmp(2) ?? null; tmp1(0) ?? null //│ = 420 fun f(n1: Int)(n2: Int)(n3: Int)(n4: Int): Int = 10 * (10 * (10 * n1 + n2) + n3) + n4 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let n1 = args[0]; -//│ return (...args1) => { -//│ globalThis.Predef.checkArgs("", 1, true, args1.length); -//│ let n2 = args1[0]; -//│ return (...args2) => { -//│ globalThis.Predef.checkArgs("", 1, true, args2.length); -//│ let n3 = args2[0]; -//│ return (...args3) => { -//│ globalThis.Predef.checkArgs("", 1, true, args3.length); -//│ let n4 = args3[0]; +//│ JS (unsanitized): +//│ function f(n1) { +//│ return (n2) => { +//│ return (n3) => { +//│ return (n4) => { //│ let tmp, tmp1, tmp2, tmp3, tmp4; //│ tmp = 10 * n1; //│ tmp1 = tmp + n2; @@ -92,7 +62,7 @@ fun f(n1: Int)(n2: Int)(n3: Int)(n4: Int): Int = 10 * (10 * (10 * n1 + n2) + n3) //│ null f(3)(0)(3)(1) -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1, tmp2; tmp = this.f(3); tmp1 = tmp(0) ?? null; tmp2 = tmp1(3) ?? null; tmp2(1) ?? null //│ = 3031 diff --git a/hkmc2/shared/src/test/mlscript/codegen/BadInit.mls b/hkmc2/shared/src/test/mlscript/codegen/BadInit.mls index 0b5a3671a..4811fa65f 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/BadInit.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/BadInit.mls @@ -8,20 +8,13 @@ module Bar with val x = 1 module Baz with val a = Bar.x -//│ JS: +//│ JS (unsanitized): //│ const Bar$class = class Bar { //│ constructor() { //│ this.x = 1; //│ const Baz$class = class Baz { //│ constructor() { -//│ let selRes, tmp; -//│ selRes = globalThis.Bar.x; -//│ if (selRes === undefined) { -//│ throw new globalThis.Error("Access to required field 'x' yielded 'undefined'"); -//│ } else { -//│ tmp = selRes; -//│ } -//│ this.a = tmp; +//│ this.a = globalThis.Bar.x; //│ } //│ toString() { return "Baz"; } //│ }; diff --git a/hkmc2/shared/src/test/mlscript/codegen/BadNew.mls b/hkmc2/shared/src/test/mlscript/codegen/BadNew.mls index 6c9390917..205aede86 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/BadNew.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/BadNew.mls @@ -15,9 +15,8 @@ new 2 :ge new 2 + 2 //│ ═══[COMPILATION ERROR] Illegal reference to builtin symbol '+' -//│ JS: +//│ JS (unsanitized): //│ new (()=>{throw globalThis.Error("Illegal reference to builtin symbol '+'")})()(2, 2) -//│ ═══[RUNTIME ERROR] TypeError: (intermediate value) is not a constructor :re new() @@ -40,7 +39,7 @@ new { x = 1 } //│ lhs = Ident of "x" //│ rhs = IntLit of 1 //│ ╔══[ERROR] Name not found: x -//│ ║ l.36: new { x = 1 } +//│ ║ l.35: new { x = 1 } //│ ╙── ^ diff --git a/hkmc2/shared/src/test/mlscript/codegen/BadOpen.mls b/hkmc2/shared/src/test/mlscript/codegen/BadOpen.mls index a1e747b7b..4807000aa 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/BadOpen.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/BadOpen.mls @@ -23,7 +23,7 @@ open Foo { y } :sjs y -//│ JS: +//│ JS (unsanitized): //│ this.Foo.y diff --git a/hkmc2/shared/src/test/mlscript/codegen/BasicTerms.mls b/hkmc2/shared/src/test/mlscript/codegen/BasicTerms.mls index 594c91883..035ff60a4 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/BasicTerms.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/BasicTerms.mls @@ -5,7 +5,7 @@ 1 -//│ JS: +//│ JS (unsanitized): //│ 1 //│ = 1 @@ -16,20 +16,23 @@ //│ ╔══[WARNING] Pure expression in statement position //│ ║ l.14: 1 //│ ╙── ^ +//│ JS (unsanitized): +//│ 2 +//│ ╔══[WARNING] Pure expression in statement position +//│ ║ l.14: 1 +//│ ╙── ^ //│ Lowered: //│ Program: //│ imports = Nil //│ main = Return: //│ res = Lit of IntLit of 2 //│ implct = true -//│ JS: -//│ 2 //│ = 2 :fixme // should be a "linking" error log("Hi") -//│ JS: +//│ JS (unsanitized): //│ this.log("Hi") ?? null //│ ═══[RUNTIME ERROR] TypeError: this.log is not a function @@ -37,6 +40,8 @@ log("Hi") :lot log("Hi") 2 +//│ JS (unsanitized): +//│ let tmp; tmp = this.log("Hi") ?? null; 2 //│ Lowered: //│ Program: //│ imports = Nil @@ -53,14 +58,12 @@ log("Hi") //│ rest = Return: \ //│ res = Lit of IntLit of 2 //│ implct = true -//│ JS: -//│ let tmp; tmp = this.log("Hi") ?? null; 2 //│ ═══[RUNTIME ERROR] TypeError: this.log is not a function :re 2(2) -//│ JS: +//│ JS (unsanitized): //│ 2(2) ?? null //│ ═══[RUNTIME ERROR] TypeError: 2 is not a function diff --git a/hkmc2/shared/src/test/mlscript/codegen/BuiltinOps.mls b/hkmc2/shared/src/test/mlscript/codegen/BuiltinOps.mls index ce5ec9e06..6cacd1f19 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/BuiltinOps.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/BuiltinOps.mls @@ -3,19 +3,19 @@ :sjs 2 + 2 -//│ JS: +//│ JS (unsanitized): //│ 2 + 2 //│ = 4 :sjs 2 +. 2 -//│ JS: +//│ JS (unsanitized): //│ 2 + 2 //│ = 4 :sjs +2 -//│ JS: +//│ JS (unsanitized): //│ + 2 //│ = 2 @@ -24,7 +24,7 @@ fun (+) lol(a, b) = [a, b] :sjs 1 + 2 -//│ JS: +//│ JS (unsanitized): //│ this.lol(1, 2) //│ = [ 1, 2 ] diff --git a/hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls b/hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls index 044290da2..751c7c205 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls @@ -17,10 +17,8 @@ fun test(x) = ) is Some(v) then log(v) None then log("none") -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function test(x) { //│ let param0, v, scrut, param01, v1, tmp, tmp1; //│ if (x instanceof globalThis.Some.class) { //│ param0 = x.value; diff --git a/hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls b/hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls index 27bf7d1d9..4d8f448be 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls @@ -10,38 +10,22 @@ case x then x :sjs case { x then x } -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let caseScrut = args[0]; -//│ let x; -//│ x = caseScrut; -//│ return x; -//│ } +//│ JS (unsanitized): +//│ (caseScrut) => { let x; x = caseScrut; return x; } //│ = [Function (anonymous)] :sjs x => if x is 0 then true -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; -//│ if (x === 0) { -//│ return true; -//│ } else { -//│ throw new this.Error("match error"); -//│ } -//│ } +//│ JS (unsanitized): +//│ (x) => { if (x === 0) { return true; } else { throw new this.Error("match error"); } } //│ = [Function (anonymous)] :sjs case 0 then true -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let caseScrut = args[0]; +//│ JS (unsanitized): +//│ (caseScrut) => { //│ if (caseScrut === 0) { //│ return true; //│ } else { @@ -54,16 +38,8 @@ case case 0 then true _ then false -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let caseScrut = args[0]; -//│ if (caseScrut === 0) { -//│ return true; -//│ } else { -//│ return false; -//│ } -//│ } +//│ JS (unsanitized): +//│ (caseScrut) => { if (caseScrut === 0) { return true; } else { return false; } } //│ = [Function (anonymous)] class Some(value) @@ -73,10 +49,8 @@ module None val isDefined = case Some then true None then false -//│ JS: -//│ this.isDefined = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let caseScrut = args[0]; +//│ JS (unsanitized): +//│ this.isDefined = (caseScrut) => { //│ if (caseScrut instanceof this.Some.class) { //│ return true; //│ } else { diff --git a/hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls b/hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls index fcc70e08a..234a5af8b 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls @@ -16,28 +16,26 @@ class Outer(a, b) with val i = Inner(a) log(i.c) log(i.i1(1)) -//│ JS: -//│ this.Outer = function Outer(...args) { return new Outer.class(...args); }; +//│ JS (unsanitized): +//│ this.Outer = function Outer(a1, b1) { return new Outer.class(a1, b1); }; //│ this.Outer.class = class Outer { //│ constructor(a, b) { //│ this.a = a; //│ this.b = b; -//│ let tmp, selRes, tmp1, tmp2, tmp3; +//│ let tmp, tmp1, tmp2; //│ //│ const this$Outer = this; -//│ this.Inner = function Inner(...args1) { return new Inner.class(...args1); }; +//│ this.Inner = function Inner(c1) { return new Inner.class(c1); }; //│ this.Inner.class = class Inner { //│ constructor(c) { //│ this.c = c; -//│ let tmp4, tmp5, tmp6; -//│ tmp4 = globalThis.log(this$Outer.a); -//│ tmp5 = globalThis.log(this.c); -//│ tmp6 = this.i1(this$Outer.a); -//│ globalThis.log(tmp6) +//│ let tmp3, tmp4, tmp5; +//│ tmp3 = globalThis.log(this$Outer.a); +//│ tmp4 = globalThis.log(this.c); +//│ tmp5 = this.i1(this$Outer.a); +//│ globalThis.log(tmp5) //│ } -//│ i1(...args) { -//│ globalThis.Predef.checkArgs("i1", 1, true, args.length); -//│ let d = args[0]; +//│ i1(d) { //│ return [ //│ this$Outer.b, //│ this.c, @@ -48,25 +46,14 @@ class Outer(a, b) with //│ }; //│ tmp = this.Inner(this.a); //│ this.i = tmp; -//│ selRes = this.i.c; -//│ if (selRes === undefined) { -//│ throw new globalThis.Error("Access to required field 'c' yielded 'undefined'"); -//│ } else { -//│ tmp1 = selRes; -//│ } -//│ tmp2 = globalThis.log(tmp1); -//│ tmp3 = this.i.i1(1) ?? null; -//│ globalThis.log(tmp3) +//│ tmp1 = globalThis.log(this.i.c); +//│ tmp2 = this.i.i1(1) ?? null; +//│ globalThis.log(tmp2) //│ } -//│ o1(...args) { -//│ globalThis.Predef.checkArgs("o1", 1, true, args.length); -//│ let c = args[0]; +//│ o1(c) { //│ return this.Inner(c); //│ } -//│ o2(...args1) { -//│ globalThis.Predef.checkArgs("o2", 2, true, args1.length); -//│ let c1 = args1[0]; -//│ let d = args1[1]; +//│ o2(c1, d) { //│ let tmp; //│ tmp = this.Inner(c1); //│ return tmp.i1(d) ?? null; diff --git a/hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls b/hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls index 185b4f5fc..e44d2183f 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls @@ -8,10 +8,8 @@ fun test(a) = class C with { val x = a } new C -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let a = args[0]; +//│ JS (unsanitized): +//│ function test(a) { //│ class C { //│ constructor() { //│ this.x = a; @@ -30,12 +28,10 @@ test(12) fun test(x) = class Foo(a, b) Foo(x, x + 1) -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function test(x) { //│ let tmp; -//│ function Foo(...args1) { return new Foo.class(...args1); }; +//│ function Foo(a1, b1) { return new Foo.class(a1, b1); }; //│ Foo.class = class Foo { //│ constructor(a, b) { //│ this.a = a; diff --git a/hkmc2/shared/src/test/mlscript/codegen/ClassMatching.mls b/hkmc2/shared/src/test/mlscript/codegen/ClassMatching.mls index 8dfa0c421..cb65c98d6 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ClassMatching.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ClassMatching.mls @@ -11,7 +11,7 @@ object None :sjs if Some(0) is Some(x) then x -//│ JS: +//│ JS (unsanitized): //│ let scrut, param0, x; //│ scrut = this.Some(0); //│ if (scrut instanceof this.Some.class) { @@ -30,7 +30,7 @@ let s = Some(0) :sjs if s is Some(x) then x -//│ JS: +//│ JS (unsanitized): //│ let scrut, param0, x; //│ scrut = this.s; //│ if (scrut instanceof this.Some.class) { @@ -60,10 +60,8 @@ if s is :sjs x => if x is Some(x) then x -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ (x) => { //│ let param0, x1; //│ if (x instanceof this.Some.class) { //│ param0 = x.value; @@ -121,10 +119,8 @@ fun f(x) = if x is Some(x) and x > 0 then 42 None then "ok" else log("oops") -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ let param0, x1, scrut; //│ if (x instanceof globalThis.Some.class) { //│ param0 = x.value; @@ -165,10 +161,8 @@ class Pair[out A, out B](fst: A, snd: B) fun f(x) = if x is Some(u) then u Pair(a, b) then a + b -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ let param0, param1, a, b, param01, u; //│ if (x instanceof globalThis.Some.class) { //│ param01 = x.value; @@ -201,10 +195,8 @@ fun f(x) = log of if x is Some(0) then "0" None then "ok" else "oops" -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ let param0, tmp; //│ if (x instanceof globalThis.Some.class) { //│ param0 = x.value; diff --git a/hkmc2/shared/src/test/mlscript/codegen/Comma.mls b/hkmc2/shared/src/test/mlscript/codegen/Comma.mls index 90150bb0a..e034dabd8 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Comma.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Comma.mls @@ -6,32 +6,16 @@ fun f() = console.log("ok"), 42 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ let tmp; -//│ tmp = globalThis.console.log("ok") ?? null; -//│ return 42; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f() { let tmp; tmp = globalThis.console.log("ok") ?? null; return 42; } null fun f() = { console.log("ok"), 42 } -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ let tmp; -//│ tmp = globalThis.console.log("ok") ?? null; -//│ return 42; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f() { let tmp; tmp = globalThis.console.log("ok") ?? null; return 42; } null fun f() = console.log("ok"), 42 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ return globalThis.console.log("ok") ?? null; -//│ } -//│ 42 +//│ JS (unsanitized): +//│ function f() { return globalThis.console.log("ok") ?? null; } 42 //│ = 42 diff --git a/hkmc2/shared/src/test/mlscript/codegen/ConsoleLog.mls b/hkmc2/shared/src/test/mlscript/codegen/ConsoleLog.mls index dfb05a715..b5dfe98ba 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ConsoleLog.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ConsoleLog.mls @@ -6,14 +6,14 @@ :silent declare val console -//│ JS: +//│ JS (unsanitized): //│ null console.log("a") console.log("b") 123 -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1; tmp = this.console.log("a") ?? null; tmp1 = this.console.log("b") ?? null; 123 //│ > a //│ > b @@ -21,27 +21,19 @@ console.log("b") let l = console.log l(123) -//│ JS: -//│ let selRes, tmp; -//│ selRes = this.console.log; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'log' yielded 'undefined'"); -//│ } else { -//│ tmp = selRes; -//│ } -//│ this.l = tmp; -//│ this.l(123) ?? null +//│ JS (unsanitized): +//│ this.l = this.console.log; this.l(123) ?? null //│ > 123 //│ l = [Function: log] 42 -//│ JS: +//│ JS (unsanitized): //│ 42 //│ = 42 console.log("a") -//│ JS: +//│ JS (unsanitized): //│ this.console.log("a") ?? null //│ > a @@ -53,7 +45,7 @@ console.log("b") let y = x + 1 console.log("c") y * 2 -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1, tmp2, tmp3; //│ tmp = this.console.log("a") ?? null; //│ this.x = 123; diff --git a/hkmc2/shared/src/test/mlscript/codegen/DelayedLetInit.mls b/hkmc2/shared/src/test/mlscript/codegen/DelayedLetInit.mls index dfecf723d..463537c2d 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/DelayedLetInit.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/DelayedLetInit.mls @@ -5,31 +5,31 @@ let x -//│ JS: +//│ JS (unsanitized): //│ null x = 1 -//│ JS: +//│ JS (unsanitized): //│ this.x = 1; null x -//│ JS: +//│ JS (unsanitized): //│ this.x //│ = 1 // TODO forbid redefining a let x = 2 -//│ JS: +//│ JS (unsanitized): //│ this.x = 2; null x -//│ JS: +//│ JS (unsanitized): //│ this.x //│ = 2 let y = 1 -//│ JS: +//│ JS (unsanitized): //│ this.y = 1; null //│ y = 1 @@ -38,44 +38,35 @@ z = 1 //│ ╔══[ERROR] Name not found: z //│ ║ l.37: z = 1 //│ ╙── ^ -//│ JS: +//│ JS (unsanitized): //│ /* error */ fun f() = 1 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ return 1; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f() { return 1; } null f -//│ JS: +//│ JS (unsanitized): //│ this.f //│ = [Function: f] let f f(x) = x + 1 -//│ JS: -//│ this.f = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; -//│ return x + 1; -//│ }; -//│ null +//│ JS (unsanitized): +//│ this.f = (x) => { return x + 1; }; null //│ f = [Function (anonymous)] f(1) -//│ JS: +//│ JS (unsanitized): //│ this.f(1) ?? null //│ = 2 let foo foo = 0 -//│ JS: +//│ JS (unsanitized): //│ this.foo = 0; null //│ foo = 0 @@ -85,9 +76,9 @@ if true then foo = 0 else foo = 1 //│ ╔══[PARSE ERROR] Expected end of input; found '=' keyword instead -//│ ║ l.85: then foo = 0 +//│ ║ l.76: then foo = 0 //│ ╙── ^ -//│ JS: +//│ JS (unsanitized): //│ let scrut; scrut = true; if (scrut) { this.foo } else { throw new this.Error("match error"); } //│ = 0 //│ foo = 0 @@ -98,27 +89,22 @@ then foo = 0 else foo = 1 -//│ JS: +//│ JS (unsanitized): //│ let scrut; scrut = true; if (scrut) { this.foo = 0; null } else { this.foo = 1; null } //│ foo = 0 fun f() = foo = 42 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ globalThis.foo = 42; -//│ return null; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f() { globalThis.foo = 42; return null; } null f() -//│ JS: +//│ JS (unsanitized): //│ this.f() foo -//│ JS: +//│ JS (unsanitized): //│ this.foo //│ = 42 @@ -126,13 +112,9 @@ foo :fixme fun f() = foo = 0 //│ ╔══[PARSE ERROR] Expected end of input; found '=' keyword instead -//│ ║ l.127: fun f() = foo = 0 +//│ ║ l.113: fun f() = foo = 0 //│ ╙── ^ -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 0, true, args.length); -//│ return globalThis.foo; -//│ } -//│ null +//│ JS (unsanitized): +//│ function f() { return globalThis.foo; } null diff --git a/hkmc2/shared/src/test/mlscript/codegen/EarlyReturn.mls b/hkmc2/shared/src/test/mlscript/codegen/EarlyReturn.mls index 6dc7950cd..61037077a 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/EarlyReturn.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/EarlyReturn.mls @@ -20,10 +20,8 @@ fun f(x) = log("whoops") return 0 x + 1 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ let scrut, tmp, tmp1; //│ scrut = x < 0; //│ if (scrut) { diff --git a/hkmc2/shared/src/test/mlscript/codegen/FunInClass.mls b/hkmc2/shared/src/test/mlscript/codegen/FunInClass.mls index 2096e0265..317af5748 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/FunInClass.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/FunInClass.mls @@ -21,34 +21,26 @@ fun test(a) = fun h(e) = [a, b, d, e] h(d) Inner(42) -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let a = args[0]; -//│ function Inner(...args1) { return new Inner.class(...args1); }; +//│ JS (unsanitized): +//│ function test(a) { +//│ function Inner(b1) { return new Inner.class(b1); }; //│ Inner.class = class Inner { //│ constructor(b) { //│ this.b = b; //│ let tmp; //│ tmp = globalThis.log(a); //│ } -//│ f(...args1) { -//│ globalThis.Predef.checkArgs("f", 1, true, args1.length); -//│ let c = args1[0]; +//│ f(c) { //│ return [ //│ a, //│ this.b, //│ c //│ ]; //│ } -//│ g(...args2) { -//│ globalThis.Predef.checkArgs("g", 1, true, args2.length); -//│ let d = args2[0]; +//│ g(d) { //│ //│ const this$Inner = this; -//│ function h(...args1) { -//│ globalThis.Predef.checkArgs("h", 1, true, args1.length); -//│ let e = args1[0]; +//│ function h(e) { //│ return [ //│ a, //│ this$Inner.b, @@ -82,12 +74,10 @@ fun test(a) = class C2(b) with print of [a, b] [C1(1), C2(2)] -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let a = args[0]; +//│ JS (unsanitized): +//│ function test(a) { //│ let tmp, tmp1; -//│ function C1(...args1) { return new C1.class(...args1); }; +//│ function C1(b1) { return new C1.class(b1); }; //│ C1.class = class C1 { //│ constructor(b) { //│ this.b = b; @@ -98,7 +88,7 @@ fun test(a) = //│ } //│ toString() { return "C1(" + this.b + ")"; } //│ }; -//│ function C2(...args1) { return new C2.class(...args1); }; +//│ function C2(b1) { return new C2.class(b1); }; //│ C2.class = class C2 { //│ constructor(b) { //│ this.b = b; @@ -133,24 +123,21 @@ class Foo(a) with baz() foo() Foo(123) -//│ JS: -//│ this.Foo = function Foo(...args1) { return new Foo.class(...args1); }; +//│ JS (unsanitized): +//│ this.Foo = function Foo(a1) { return new Foo.class(a1); }; //│ this.Foo.class = class Foo { //│ constructor(a) { //│ this.a = a; //│ this.foo() //│ } -//│ foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 0, true, args.length); +//│ foo() { //│ let tmp; //│ //│ const this$Foo = this; -//│ function bar(...args1) { -//│ globalThis.Predef.checkArgs("bar", 0, true, args1.length); +//│ function bar() { //│ return this$Foo.a; //│ } -//│ function baz(...args1) { -//│ globalThis.Predef.checkArgs("baz", 0, true, args1.length); +//│ function baz() { //│ return this$Foo.a; //│ } //│ tmp = bar(); diff --git a/hkmc2/shared/src/test/mlscript/codegen/FunctionsThis.mls b/hkmc2/shared/src/test/mlscript/codegen/FunctionsThis.mls index c5ece633c..a1da1cee9 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/FunctionsThis.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/FunctionsThis.mls @@ -8,19 +8,14 @@ val x = 2 fun foo() = x + 1 -//│ JS: -//│ this.x = 2; -//│ function foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 0, true, args.length); -//│ return globalThis.x + 1; -//│ } -//│ null +//│ JS (unsanitized): +//│ this.x = 2; function foo() { return globalThis.x + 1; } null //│ x = 2 :sjs class Test with log(foo()) -//│ JS: +//│ JS (unsanitized): //│ this.Test = class Test { //│ constructor() { //│ let tmp; diff --git a/hkmc2/shared/src/test/mlscript/codegen/GlobalThis.mls b/hkmc2/shared/src/test/mlscript/codegen/GlobalThis.mls index 192b86a00..f99b0fe27 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/GlobalThis.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/GlobalThis.mls @@ -17,7 +17,7 @@ globalThis :sjs :re if false then 0 -//│ JS: +//│ JS (unsanitized): //│ let scrut; scrut = false; if (scrut) { 0 } else { throw new this.Error("match error"); } //│ ═══[RUNTIME ERROR] Error: match error @@ -28,9 +28,8 @@ if false then 0 fun foo() = if false then 0 foo() -//│ JS: -//│ function foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 0, true, args.length); +//│ JS (unsanitized): +//│ function foo() { //│ let scrut; //│ scrut = false; //│ if (scrut) { diff --git a/hkmc2/shared/src/test/mlscript/codegen/Hygiene.mls b/hkmc2/shared/src/test/mlscript/codegen/Hygiene.mls index b187e5c1c..2767cd506 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Hygiene.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Hygiene.mls @@ -5,20 +5,13 @@ module Test with val x = 12 fun foo() = Test.x -//│ JS: +//│ JS (unsanitized): //│ const Test$class = class Test { //│ constructor() { //│ this.x = 12; //│ } -//│ foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 0, true, args.length); -//│ let selRes; -//│ selRes = globalThis.Test.x; -//│ if (selRes === undefined) { -//│ throw new globalThis.Error("Access to required field 'x' yielded 'undefined'"); -//│ } else { -//│ return selRes; -//│ } +//│ foo() { +//│ return globalThis.Test.x; //│ } //│ toString() { return "Test"; } //│ }; @@ -28,13 +21,13 @@ module Test with :sjs Test.foo() -//│ JS: +//│ JS (unsanitized): //│ this.Test.foo() //│ = 12 :sjs val Test = "oops" -//│ JS: +//│ JS (unsanitized): //│ this.Test = "oops"; null //│ Test = 'oops' @@ -49,14 +42,8 @@ let x = 1 let f = () => x let x = 2 f() -//│ JS: -//│ this.x = 1; -//│ this.f = (...args) => { -//│ globalThis.Predef.checkArgs("", 0, true, args.length); -//│ return this.x; -//│ }; -//│ this.x = 2; -//│ this.f() ?? null +//│ JS (unsanitized): +//│ this.x = 1; this.f = () => { return this.x; }; this.x = 2; this.f() ?? null //│ = 2 //│ f = [Function (anonymous)] //│ x = 2 @@ -66,7 +53,7 @@ f() module Test with val x = 1 let x = 2 -//│ JS: +//│ JS (unsanitized): //│ const Test$class = class Test { //│ #x; //│ constructor() { diff --git a/hkmc2/shared/src/test/mlscript/codegen/IfThenElse.mls b/hkmc2/shared/src/test/mlscript/codegen/IfThenElse.mls index 065e682ce..278b23789 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/IfThenElse.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/IfThenElse.mls @@ -11,17 +11,8 @@ if true then 1 else 0 :sjs let f = x => if x then log("ok") else log("ko") -//│ JS: -//│ this.f = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; -//│ if (x) { -//│ return this.log("ok"); -//│ } else { -//│ return this.log("ko"); -//│ } -//│ }; -//│ null +//│ JS (unsanitized): +//│ this.f = (x) => { if (x) { return this.log("ok"); } else { return this.log("ko"); } }; null //│ f = [Function (anonymous)] f(true) @@ -33,10 +24,8 @@ f(false) :sjs let f = x => log((if x then "ok" else "ko") + "!") -//│ JS: -//│ this.f = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ this.f = (x) => { //│ let tmp, tmp1; //│ if (x) { //│ tmp = "ok"; @@ -51,10 +40,8 @@ let f = x => log((if x then "ok" else "ko") + "!") :sjs let f = x => log((if x and x then "ok" else "ko") + "!") -//│ JS: -//│ this.f = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ this.f = (x) => { //│ let tmp, tmp1; //│ if (x) { //│ if (x) { diff --git a/hkmc2/shared/src/test/mlscript/codegen/ImportExample.mls b/hkmc2/shared/src/test/mlscript/codegen/ImportExample.mls index 7f44e519c..62d7461b5 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ImportExample.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ImportExample.mls @@ -17,7 +17,7 @@ let n = 42 :sjs n / 2 -//│ JS: +//│ JS (unsanitized): //│ this.n / 2 //│ = 21 @@ -28,14 +28,14 @@ open Example :sjs inc / 2 -//│ JS: +//│ JS (unsanitized): //│ Example.funnySlash(Example.inc, 2) //│ = 3 :sjs :re n / 2 -//│ JS: +//│ JS (unsanitized): //│ Example.funnySlash(this.n, 2) //│ ═══[RUNTIME ERROR] TypeError: f is not a function diff --git a/hkmc2/shared/src/test/mlscript/codegen/ImportMLs.mls b/hkmc2/shared/src/test/mlscript/codegen/ImportMLs.mls index 7977c81e8..b3a59ada7 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ImportMLs.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ImportMLs.mls @@ -23,7 +23,7 @@ open Option :sjs None isDefined() -//│ JS: +//│ JS (unsanitized): //│ Option.isDefined(Option.None) //│ = false @@ -46,7 +46,7 @@ Some(1) :sjs (new Some(1)) isDefined() -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = new Option.Some.class(1); Option.isDefined(tmp) //│ = true @@ -91,7 +91,7 @@ oops :e :re Option.None.oops -//│ ╔══[ERROR] Module 'None' does not contain member 'oops' +//│ ╔══[ERROR] Object 'None' does not contain member 'oops' //│ ║ l.93: Option.None.oops //│ ╙── ^^^^^ //│ ═══[RUNTIME ERROR] Error: Access to required field 'oops' yielded 'undefined' diff --git a/hkmc2/shared/src/test/mlscript/codegen/ImportedOps.mls b/hkmc2/shared/src/test/mlscript/codegen/ImportedOps.mls index 64a16b55d..c551c63a6 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ImportedOps.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ImportedOps.mls @@ -10,9 +10,8 @@ open M fun foo() = "a" ~ "b" ~ "c" foo() -//│ JS: -//│ function foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 0, true, args.length); +//│ JS (unsanitized): +//│ function foo() { //│ let tmp; //│ tmp = globalThis.M.concat("a", "b"); //│ return globalThis.M.concat(tmp, "c"); diff --git a/hkmc2/shared/src/test/mlscript/codegen/Lambdas.mls b/hkmc2/shared/src/test/mlscript/codegen/Lambdas.mls index 121b0ac4e..8bc695bad 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Lambdas.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Lambdas.mls @@ -7,14 +7,8 @@ x => let y = x y -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; -//│ let y; -//│ y = x; -//│ return y; -//│ } +//│ JS (unsanitized): +//│ (x) => { let y; y = x; return y; } //│ = [Function (anonymous)] diff --git a/hkmc2/shared/src/test/mlscript/codegen/Misc.mls b/hkmc2/shared/src/test/mlscript/codegen/Misc.mls index 7e31562cc..6cec30897 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Misc.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Misc.mls @@ -14,7 +14,7 @@ :sjs 1 + 2 -//│ JS: +//│ JS (unsanitized): //│ 1 + 2 //│ = 3 diff --git a/hkmc2/shared/src/test/mlscript/codegen/ModuleMethods.mls b/hkmc2/shared/src/test/mlscript/codegen/ModuleMethods.mls index 853cf7b5e..e9852a5cf 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ModuleMethods.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ModuleMethods.mls @@ -6,14 +6,12 @@ object Example with val a = 456 fun f(x) = [x, a] -//│ JS: +//│ JS (unsanitized): //│ const Example$class = class Example { //│ constructor() { //│ this.a = 456; //│ } -//│ f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ f(x) { //│ return [ //│ x, //│ this.a diff --git a/hkmc2/shared/src/test/mlscript/codegen/Modules.mls b/hkmc2/shared/src/test/mlscript/codegen/Modules.mls index 6cdc3c9cd..3a03e4171 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Modules.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Modules.mls @@ -6,7 +6,7 @@ :sjs module None -//│ JS: +//│ JS (unsanitized): //│ const None$class = class None { //│ constructor() { //│ @@ -19,20 +19,20 @@ module None :sjs None -//│ JS: +//│ JS (unsanitized): //│ this.None //│ = None { class: [class None] } :sjs :re None() -//│ JS: +//│ JS (unsanitized): //│ this.None() ?? null //│ ═══[RUNTIME ERROR] TypeError: this.None is not a function :sjs new None -//│ JS: +//│ JS (unsanitized): //│ new this.None.class() //│ = None {} @@ -43,7 +43,7 @@ module M with class D() val x = 1 val y = x + 1 -//│ JS: +//│ JS (unsanitized): //│ const M$class = class M { //│ constructor() { //│ let tmp; @@ -53,7 +53,7 @@ module M with //│ } //│ toString() { return "C"; } //│ }; -//│ this.D = function D(...args) { return new D.class(...args); }; +//│ this.D = function D() { return new D.class(); }; //│ this.D.class = class D { //│ constructor() { //│ @@ -97,7 +97,7 @@ M.oops :sjs module M with val m: module M = M -//│ JS: +//│ JS (unsanitized): //│ const M$class = class M { //│ constructor() { //│ this.m = globalThis.M; diff --git a/hkmc2/shared/src/test/mlscript/codegen/Open.mls b/hkmc2/shared/src/test/mlscript/codegen/Open.mls index c0edf285b..4d016a0cd 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Open.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Open.mls @@ -8,7 +8,7 @@ module Foo with :sjs open Foo { x } -//│ JS: +//│ JS (unsanitized): //│ null open Foo { x, y } diff --git a/hkmc2/shared/src/test/mlscript/codegen/OpenWildcard.mls b/hkmc2/shared/src/test/mlscript/codegen/OpenWildcard.mls index 5aae4cf39..1e66663ea 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/OpenWildcard.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/OpenWildcard.mls @@ -9,12 +9,12 @@ module OtherModule with :sjs open Option -//│ JS: +//│ JS (unsanitized): //│ null :sjs None isDefined() -//│ JS: +//│ JS (unsanitized): //│ Option.isDefined(Option.None) //│ = false @@ -51,14 +51,14 @@ none() :sjs val Option = "Oops" -//│ JS: +//│ JS (unsanitized): //│ this.Option = "Oops"; null //│ Option = 'Oops' :fixme :sjs Some(123) -//│ JS: +//│ JS (unsanitized): //│ Option.Some(123) //│ ═══[RUNTIME ERROR] TypeError: Option.Some is not a function @@ -67,17 +67,17 @@ module Option with :sjs open Option -//│ JS: +//│ JS (unsanitized): //│ null :sjs Some -//│ JS: +//│ JS (unsanitized): //│ Option.Some :sjs None -//│ JS: +//│ JS (unsanitized): //│ this.Option.None //│ = 123 diff --git a/hkmc2/shared/src/test/mlscript/codegen/OptMatch.mls b/hkmc2/shared/src/test/mlscript/codegen/OptMatch.mls index a727be9fc..689c05615 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/OptMatch.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/OptMatch.mls @@ -9,10 +9,8 @@ object None fun isDefined(x) = if x is Some then true None then false -//│ JS: -//│ function isDefined(...args) { -//│ globalThis.Predef.checkArgs("isDefined", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function isDefined(x) { //│ if (x instanceof globalThis.Some.class) { //│ return true; //│ } else { @@ -36,10 +34,8 @@ isDefined(None) val isDefined = case Some(_) then true None then false -//│ JS: -//│ this.isDefined = (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let caseScrut = args[0]; +//│ JS (unsanitized): +//│ this.isDefined = (caseScrut) => { //│ let param0; //│ if (caseScrut instanceof this.Some.class) { //│ param0 = caseScrut.value; diff --git a/hkmc2/shared/src/test/mlscript/codegen/ParamClasses.mls b/hkmc2/shared/src/test/mlscript/codegen/ParamClasses.mls index c96aa5a94..86b431247 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ParamClasses.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ParamClasses.mls @@ -8,8 +8,8 @@ class Foo() -//│ JS: -//│ this.Foo = function Foo(...args) { return new Foo.class(...args); }; +//│ JS (unsanitized): +//│ this.Foo = function Foo() { return new Foo.class(); }; //│ this.Foo.class = class Foo { //│ constructor() { //│ @@ -19,30 +19,24 @@ class Foo() //│ null Foo -//│ JS: +//│ JS (unsanitized): //│ this.Foo //│ = [Function: Foo] { class: [class Foo] } Foo() -//│ JS: +//│ JS (unsanitized): //│ this.Foo() //│ = Foo {} Foo.class -//│ JS: -//│ let selRes; -//│ selRes = this.Foo.class; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'class' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ this.Foo.class //│ = [class Foo] class Foo(a) -//│ JS: -//│ this.Foo = function Foo(...args) { return new Foo.class(...args); }; +//│ JS (unsanitized): +//│ this.Foo = function Foo(a1) { return new Foo.class(a1); }; //│ this.Foo.class = class Foo { //│ constructor(a) { //│ this.a = a; @@ -53,42 +47,30 @@ class Foo(a) //│ null Foo -//│ JS: +//│ JS (unsanitized): //│ this.Foo //│ = [Function: Foo] { class: [class Foo] } Foo(1) -//│ JS: +//│ JS (unsanitized): //│ this.Foo(1) //│ = Foo { a: 1 } Foo(1).a -//│ JS: -//│ let tmp, selRes; -//│ tmp = this.Foo(1); -//│ selRes = tmp.a; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'a' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ let tmp; tmp = this.Foo(1); tmp.a //│ = 1 fun foo(y) = Foo(y) foo(27) -//│ JS: -//│ function foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 1, true, args.length); -//│ let y = args[0]; -//│ return globalThis.Foo(y); -//│ } -//│ this.foo(27) +//│ JS (unsanitized): +//│ function foo(y) { return globalThis.Foo(y); } this.foo(27) //│ = Foo { a: 27 } class Foo(a, b) -//│ JS: -//│ this.Foo = function Foo(...args) { return new Foo.class(...args); }; +//│ JS (unsanitized): +//│ this.Foo = function Foo(a1, b1) { return new Foo.class(a1, b1); }; //│ this.Foo.class = class Foo { //│ constructor(a, b) { //│ this.a = a; @@ -100,71 +82,47 @@ class Foo(a, b) //│ null let foo = Foo -//│ JS: +//│ JS (unsanitized): //│ this.foo = this.Foo; null //│ foo = [Function: Foo] { class: [class Foo] } let f = foo(1, 2) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.foo(1, 2) ?? null; this.f = tmp; null //│ f = Foo { a: 1, b: 2 } let f = new foo(1, 2) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = new this.foo(1, 2); this.f = tmp; null //│ f = Foo { a: 1, b: 2 } f.a -//│ JS: -//│ let selRes; -//│ selRes = this.f.a; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'a' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ this.f.a //│ = 1 f.b -//│ JS: -//│ let selRes; -//│ selRes = this.f.b; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'b' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ this.f.b //│ = 2 let f = Foo(1, 2) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.Foo(1, 2); this.f = tmp; null //│ f = Foo { a: 1, b: 2 } f.a -//│ JS: -//│ let selRes; -//│ selRes = this.f.a; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'a' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ this.f.a //│ = 1 f.b -//│ JS: -//│ let selRes; -//│ selRes = this.f.b; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'b' yielded 'undefined'"); -//│ } else { -//│ selRes -//│ } +//│ JS (unsanitized): +//│ this.f.b //│ = 2 Foo(log(1), log(2)) -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1; tmp = this.log(1); tmp1 = this.log(2); this.Foo(tmp, tmp1) //│ > 1 //│ > 2 @@ -174,16 +132,14 @@ Foo(log(1), log(2)) class Inner(c) with fun i1(d) = c + d log(c) -//│ JS: -//│ this.Inner = function Inner(...args1) { return new Inner.class(...args1); }; +//│ JS (unsanitized): +//│ this.Inner = function Inner(c1) { return new Inner.class(c1); }; //│ this.Inner.class = class Inner { //│ constructor(c) { //│ this.c = c; //│ globalThis.log(this.c) //│ } -//│ i1(...args) { -//│ globalThis.Predef.checkArgs("i1", 1, true, args.length); -//│ let d = args[0]; +//│ i1(d) { //│ return this.c + d; //│ } //│ toString() { return "Inner(" + this.c + ")"; } @@ -191,13 +147,13 @@ class Inner(c) with //│ null let i = new Inner(100) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = new this.Inner.class(100); this.i = tmp; null //│ > 100 //│ i = Inner { c: 100 } i.i1(20) -//│ JS: +//│ JS (unsanitized): //│ this.i.i1(20) ?? null //│ = 120 diff --git a/hkmc2/shared/src/test/mlscript/codegen/PlainClasses.mls b/hkmc2/shared/src/test/mlscript/codegen/PlainClasses.mls index 550cefee9..0b72eaedc 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/PlainClasses.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/PlainClasses.mls @@ -8,44 +8,44 @@ class Foo -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { constructor() { } toString() { return "Foo"; } }; null Foo is Foo -//│ JS: +//│ JS (unsanitized): //│ let scrut; scrut = this.Foo; if (scrut instanceof this.Foo) { true } else { false } //│ = false (new Foo) is Foo -//│ JS: +//│ JS (unsanitized): //│ let scrut; scrut = new this.Foo(); if (scrut instanceof this.Foo) { true } else { false } //│ = true new Foo -//│ JS: +//│ JS (unsanitized): //│ new this.Foo() //│ = Foo {} new Foo() -//│ JS: +//│ JS (unsanitized): //│ new this.Foo() //│ = Foo {} Foo -//│ JS: +//│ JS (unsanitized): //│ this.Foo //│ = [class Foo] :re Foo() -//│ JS: +//│ JS (unsanitized): //│ this.Foo() //│ ═══[RUNTIME ERROR] TypeError: Class constructor Foo cannot be invoked without 'new' class Foo with { log("hi") } log("ok") -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { //│ constructor() { //│ globalThis.log("hi") @@ -59,9 +59,8 @@ fun test() = class Foo with { log("hi") } log("ok") Foo -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 0, true, args.length); +//│ JS (unsanitized): +//│ function test() { //│ let tmp; //│ class Foo { //│ constructor() { @@ -75,19 +74,19 @@ fun test() = //│ null let t = test() -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.test(); this.t = tmp; null //│ > ok //│ t = [class Foo] new t -//│ JS: +//│ JS (unsanitized): //│ new this.t() //│ > hi //│ = Foo {} new t() -//│ JS: +//│ JS (unsanitized): //│ new this.t() //│ > hi //│ = Foo {} @@ -97,7 +96,7 @@ class Foo with val x = 1 let y = x + 1 fun z() = y + x -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { //│ #y; //│ constructor() { @@ -106,8 +105,7 @@ class Foo with //│ tmp = this.x + 1; //│ this.#y = tmp; //│ } -//│ z(...args) { -//│ globalThis.Predef.checkArgs("z", 0, true, args.length); +//│ z() { //│ return this.#y + this.x; //│ } //│ toString() { return "Foo"; } @@ -123,7 +121,7 @@ class Foo with fun z1() = 5 fun z2() = 6 log("hello") -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { //│ #y1; //│ #y2; @@ -134,12 +132,10 @@ class Foo with //│ this.#y2 = 4; //│ globalThis.log("hello") //│ } -//│ z1(...args) { -//│ globalThis.Predef.checkArgs("z1", 0, true, args.length); +//│ z1() { //│ return 5; //│ } -//│ z2(...args1) { -//│ globalThis.Predef.checkArgs("z2", 0, true, args1.length); +//│ z2() { //│ return 6; //│ } //│ toString() { return "Foo"; } @@ -151,19 +147,15 @@ class Foo with val x = 1 fun foo(y) = x + y fun bar(z) = foo(z) + 1 -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { //│ constructor() { //│ this.x = 1; //│ } -//│ foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 1, true, args.length); -//│ let y = args[0]; +//│ foo(y) { //│ return this.x + y; //│ } -//│ bar(...args1) { -//│ globalThis.Predef.checkArgs("bar", 1, true, args1.length); -//│ let z = args1[0]; +//│ bar(z) { //│ let tmp; //│ tmp = this.foo(z); //│ return tmp + 1; @@ -176,21 +168,15 @@ let a = new Foo log(a.x) log(a.foo(1)) log(a.bar(1)) -//│ JS: -//│ let tmp, selRes, tmp1, tmp2, tmp3, tmp4, tmp5; +//│ JS (unsanitized): +//│ let tmp, tmp1, tmp2, tmp3, tmp4; //│ tmp = new this.Foo(); //│ this.a = tmp; -//│ selRes = this.a.x; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'x' yielded 'undefined'"); -//│ } else { -//│ tmp1 = selRes; -//│ } -//│ tmp2 = this.log(tmp1); -//│ tmp3 = this.a.foo(1) ?? null; -//│ tmp4 = this.log(tmp3); -//│ tmp5 = this.a.bar(1) ?? null; -//│ this.log(tmp5) +//│ tmp1 = this.log(this.a.x); +//│ tmp2 = this.a.foo(1) ?? null; +//│ tmp3 = this.log(tmp2); +//│ tmp4 = this.a.bar(1) ?? null; +//│ this.log(tmp4) //│ > 1 //│ > 2 //│ > 3 @@ -207,7 +193,7 @@ log(a.bar(1)) class Foo with val x = 1 let x = 2 -//│ JS: +//│ JS (unsanitized): //│ this.Foo = class Foo { //│ #x; //│ constructor() { @@ -222,15 +208,15 @@ class Foo with :fixme class Foo with val x = 1 //│ ╔══[PARSE ERROR] Expected block after type declaration body; found 'val' keyword instead -//│ ║ l.223: class Foo with val x = 1 +//│ ║ l.209: class Foo with val x = 1 //│ ╙── ^^^ //│ ╔══[PARSE ERROR] Expected end of input; found '=' keyword instead -//│ ║ l.223: class Foo with val x = 1 +//│ ║ l.209: class Foo with val x = 1 //│ ╙── ^ //│ ╔══[ERROR] Illegal juxtaposition right-hand side. -//│ ║ l.223: class Foo with val x = 1 +//│ ║ l.209: class Foo with val x = 1 //│ ╙── ^ -//│ JS: +//│ JS (unsanitized): //│ /* error */ diff --git a/hkmc2/shared/src/test/mlscript/codegen/PredefUsage.mls b/hkmc2/shared/src/test/mlscript/codegen/PredefUsage.mls index 05697bdbd..513b80910 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/PredefUsage.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/PredefUsage.mls @@ -13,7 +13,7 @@ print(12) :sjs 12 |> print -//│ JS: +//│ JS (unsanitized): //│ Predef.pipe(12, Predef.print) //│ > 12 diff --git a/hkmc2/shared/src/test/mlscript/codegen/Primes.mls b/hkmc2/shared/src/test/mlscript/codegen/Primes.mls index 42518dc8e..9e77d55eb 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Primes.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Primes.mls @@ -7,7 +7,7 @@ let x = 1 :fixme :sjs let x' = 1 -//│ JS: +//│ JS (unsanitized): //│ this.x' = 1; null //│ > try { this.x' = 1; null } catch (e) { console.log('\u200B' + e + '\u200B'); } //│ > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/hkmc2/shared/src/test/mlscript/codegen/Pwd.mls b/hkmc2/shared/src/test/mlscript/codegen/Pwd.mls index 5e715a994..fa9279704 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Pwd.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Pwd.mls @@ -6,30 +6,18 @@ let folderName1 = process.env.PWD.split("/").pop() in let folderName2 = process.cwd().split("/").pop() in folderName2 === folderName1 || folderName2 === "jvm" -//│ JS: -//│ let selRes, tmp, selRes1, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; -//│ selRes = this.process.env; -//│ if (selRes === undefined) { -//│ throw new this.Error("Access to required field 'env' yielded 'undefined'"); -//│ } else { -//│ tmp = selRes; -//│ } -//│ selRes1 = tmp.PWD; -//│ if (selRes1 === undefined) { -//│ throw new this.Error("Access to required field 'PWD' yielded 'undefined'"); -//│ } else { -//│ tmp1 = selRes1; -//│ } -//│ tmp2 = tmp1.split("/") ?? null; -//│ tmp3 = tmp2.pop() ?? null; -//│ this.folderName1 = tmp3; -//│ tmp4 = this.process.cwd() ?? null; -//│ tmp5 = tmp4.split("/") ?? null; -//│ tmp6 = tmp5.pop() ?? null; -//│ this.folderName2 = tmp6; -//│ tmp7 = this.folderName2 === this.folderName1; -//│ tmp8 = this.folderName2 === "jvm"; -//│ tmp7 || tmp8 +//│ JS (unsanitized): +//│ let tmp, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; +//│ tmp = this.process.env.PWD.split("/") ?? null; +//│ tmp1 = tmp.pop() ?? null; +//│ this.folderName1 = tmp1; +//│ tmp2 = this.process.cwd() ?? null; +//│ tmp3 = tmp2.split("/") ?? null; +//│ tmp4 = tmp3.pop() ?? null; +//│ this.folderName2 = tmp4; +//│ tmp5 = this.folderName2 === this.folderName1; +//│ tmp6 = this.folderName2 === "jvm"; +//│ tmp5 || tmp6 //│ = true diff --git a/hkmc2/shared/src/test/mlscript/codegen/SanityChecks.mls b/hkmc2/shared/src/test/mlscript/codegen/SanityChecks.mls index c57eb3ab6..0e096fc9f 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/SanityChecks.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/SanityChecks.mls @@ -2,7 +2,7 @@ -:sjs +:ssjs fun f(x, y) = x + y f(2, 3) //│ JS: @@ -17,7 +17,7 @@ f(2, 3) :expect NaN -:sjs +:ssjs :noSanityCheck fun f2(x, y) = x + y f2(2) @@ -25,7 +25,7 @@ f2(2) //│ function f2(x, y) { return x + y; } this.f2(2) //│ = NaN -:sjs +:ssjs :re f(2) //│ JS: @@ -33,7 +33,7 @@ f(2) //│ ═══[RUNTIME ERROR] Error: Function 'f' expected 2 arguments but got 1 -:sjs +:ssjs :re fun f(x)(y, z) = x + y + z f(3)(4) @@ -57,14 +57,14 @@ f(3)(4) :expect NaN -:sjs +:ssjs :noSanityCheck let f = (x, y) => x + y in f(2) //│ JS: //│ this.f = (x, y) => { return x + y; }; this.f(2) ?? null //│ = NaN -:sjs +:ssjs :re let f = (x, y) => x + y f(2) @@ -81,7 +81,7 @@ f(2) :expect NaN -:sjs +:ssjs :noSanityCheck class Cls(x, y) with fun f(z, p) = x + y + z + p @@ -107,7 +107,7 @@ Cls(1, 2).f(3) //│ tmp.f(3) ?? null //│ = NaN -:sjs +:ssjs :re class Cls(x, y) with fun f(z, p) = x + y + z + p @@ -137,7 +137,7 @@ Cls(1, 2).f(3) //│ ═══[RUNTIME ERROR] Error: Function 'f' expected 2 arguments but got 1 -:sjs +:ssjs :re class Cls(x, y) with fun f(z, p)(q, s) = x + y + z + p + q + s @@ -175,7 +175,7 @@ Cls(1, 2).f(3, 4)(5) //│ ═══[RUNTIME ERROR] Error: Function expected 2 arguments but got 1 -:sjs +:ssjs console.log(1) //│ JS: //│ this.console.log(1) ?? null @@ -183,7 +183,7 @@ console.log(1) :re -:sjs +:ssjs globalThis.x //│ JS: //│ let selRes; @@ -196,7 +196,7 @@ globalThis.x //│ ═══[RUNTIME ERROR] Error: Access to required field 'x' yielded 'undefined' :re -:sjs +:ssjs globalThis.x() //│ JS: //│ this.x() ?? null @@ -206,7 +206,7 @@ globalThis.x() :re -:sjs +:ssjs module M with class A(x) with fun f(y) = x + y @@ -254,7 +254,7 @@ if M.A(1).y is -:sjs +:ssjs :re M.A(1).y console.log() @@ -272,7 +272,7 @@ M.A(1).y -:sjs +:ssjs :noSanityCheck M.A(1).y console.log() @@ -290,7 +290,7 @@ M.A(2).y > 1 //│ ═══[RUNTIME ERROR] Error: Access to required field 'y' yielded 'undefined' :re -:sjs +:ssjs M.A(1).g(0) //│ JS: //│ let tmp; tmp = this.M.A(1); tmp.g(0) ?? null @@ -298,8 +298,11 @@ M.A(1).g(0) -:sjs +:ssjs M.A(1).f(0) //│ JS: //│ let tmp; tmp = this.M.A(1); tmp.f(0) ?? null //│ = 1 + + + diff --git a/hkmc2/shared/src/test/mlscript/codegen/SetIn.mls b/hkmc2/shared/src/test/mlscript/codegen/SetIn.mls index b1567a110..67c5f7e12 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/SetIn.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/SetIn.mls @@ -9,7 +9,7 @@ let x = 0 :sjs let x += 1 -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.x + 1; this.x = tmp; null //│ x = 1 @@ -18,12 +18,12 @@ x :sjs set x = 0 -//│ JS: +//│ JS (unsanitized): //│ this.x = 0; null :sjs set x += 1 -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.x + 1; this.x = tmp; null x @@ -32,7 +32,7 @@ x :sjs set x += 1 in log(x) -//│ JS: +//│ JS (unsanitized): //│ let old, tmp, tmp1; //│ old = this.x; //│ try { @@ -77,13 +77,11 @@ fun example() = log(x) log(get_x()) example() -//│ JS: -//│ function example(...args) { -//│ globalThis.Predef.checkArgs("example", 0, true, args.length); +//│ JS (unsanitized): +//│ function example() { //│ let x, get_x, old, tmp, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; //│ x = 0; -//│ get_x = (...args1) => { -//│ globalThis.Predef.checkArgs("", 0, true, args1.length); +//│ get_x = () => { //│ return x; //│ }; //│ old = x; @@ -117,13 +115,11 @@ fun example() = log(get_x()) y example() -//│ JS: -//│ function example(...args) { -//│ globalThis.Predef.checkArgs("example", 0, true, args.length); +//│ JS (unsanitized): +//│ function example() { //│ let x, get_x, y, old, tmp, tmp1, tmp2, tmp3, tmp4, tmp5; //│ x = 0; -//│ get_x = (...args1) => { -//│ globalThis.Predef.checkArgs("", 0, true, args1.length); +//│ get_x = () => { //│ return x; //│ }; //│ old = x; diff --git a/hkmc2/shared/src/test/mlscript/codegen/Spreads.mls b/hkmc2/shared/src/test/mlscript/codegen/Spreads.mls index 0c59cc0cc..576c4c0f3 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Spreads.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Spreads.mls @@ -18,7 +18,7 @@ foo(0, ...a) :sjs foo(1, ...[2, 3], 4) -//│ JS: +//│ JS (unsanitized): //│ this.foo(1, ...[ 2, 3 ], 4) //│ = [ 1, 2, 3, 4 ] diff --git a/hkmc2/shared/src/test/mlscript/codegen/This.mls b/hkmc2/shared/src/test/mlscript/codegen/This.mls index a88c75fe8..0ecb43a81 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/This.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/This.mls @@ -4,23 +4,8 @@ :sjs fun test(x) = [this.a, x] -//│ JS: -//│ function test(...args) { -//│ globalThis.Predef.checkArgs("test", 1, true, args.length); -//│ let x = args[0]; -//│ let selRes, tmp; -//│ selRes = globalThis.a; -//│ if (selRes === undefined) { -//│ throw new globalThis.Error("Access to required field 'a' yielded 'undefined'"); -//│ } else { -//│ tmp = selRes; -//│ } -//│ return [ -//│ tmp, -//│ x -//│ ]; -//│ } -//│ null +//│ JS (unsanitized): +//│ function test(x) { return [ globalThis.a, x ]; } null :re test(123) @@ -39,28 +24,17 @@ module Test with test(x) fun test2(x) = [this.a, x] -//│ JS: +//│ JS (unsanitized): //│ const Test$class = class Test { //│ constructor() { //│ this.a = 2; //│ } -//│ test1(...args) { -//│ globalThis.Predef.checkArgs("test1", 1, true, args.length); -//│ let x = args[0]; +//│ test1(x) { //│ return globalThis.test(x); //│ } -//│ test2(...args1) { -//│ globalThis.Predef.checkArgs("test2", 1, true, args1.length); -//│ let x1 = args1[0]; -//│ let selRes, tmp; -//│ selRes = this.a; -//│ if (selRes === undefined) { -//│ throw new globalThis.Error("Access to required field 'a' yielded 'undefined'"); -//│ } else { -//│ tmp = selRes; -//│ } +//│ test2(x1) { //│ return [ -//│ tmp, +//│ this.a, //│ x1 //│ ]; //│ } diff --git a/hkmc2/shared/src/test/mlscript/codegen/ThisCallVariations.mls b/hkmc2/shared/src/test/mlscript/codegen/ThisCallVariations.mls index 9bb52e769..dfa6ae1f7 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ThisCallVariations.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ThisCallVariations.mls @@ -41,7 +41,7 @@ Example . oops(2) //│ Ident of "oops" //│ rhs = Tup of Ls of //│ IntLit of 2 -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.call(this.Example, this.oops); tmp(2) ?? null //│ = [ 2, 1 ] @@ -52,7 +52,7 @@ Example. oops(2) :e :re Example .oops(2) -//│ ╔══[ERROR] Module 'Example' does not contain member 'oops' +//│ ╔══[ERROR] Object 'Example' does not contain member 'oops' //│ ║ l.54: Example .oops(2) //│ ╙── ^^^^^ //│ ═══[RUNTIME ERROR] TypeError: this.Example.oops is not a function @@ -99,7 +99,7 @@ Example .> oops(2) //│ lhs = Ident of "oops" //│ rhs = Tup of Ls of //│ IntLit of 2 -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = this.oops(2) ?? null; this.call(this.Example, tmp) //│ = [Function (anonymous)] diff --git a/hkmc2/shared/src/test/mlscript/codegen/ThisCalls.mls b/hkmc2/shared/src/test/mlscript/codegen/ThisCalls.mls index cde7493a0..776a77ab5 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/ThisCalls.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/ThisCalls.mls @@ -18,7 +18,7 @@ s(123) :sjs ex |>. s(123) -//│ JS: +//│ JS (unsanitized): //│ let tmp; tmp = Predef.call(this.ex, this.s); tmp(123) ?? null //│ = [ 123, 456 ] diff --git a/hkmc2/shared/src/test/mlscript/codegen/Throw.mls b/hkmc2/shared/src/test/mlscript/codegen/Throw.mls index 284b09fbb..69c61a6e9 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/Throw.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/Throw.mls @@ -30,13 +30,8 @@ fun f(x) = let y = throw Error("e") return y f(1) -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; -//│ throw globalThis.Error("e"); -//│ } -//│ this.f(1) +//│ JS (unsanitized): +//│ function f(x) { throw globalThis.Error("e"); } this.f(1) //│ ═══[RUNTIME ERROR] Error: e @@ -45,10 +40,8 @@ f(1) fun f(x) = throw (if x then Error("x") else Error("y")) f(false) -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ if (x) { //│ throw globalThis.Error("x"); //│ } else { diff --git a/hkmc2/shared/src/test/mlscript/codegen/TraceLog.mls b/hkmc2/shared/src/test/mlscript/codegen/TraceLog.mls index 2b0ac991f..d707589ed 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/TraceLog.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/TraceLog.mls @@ -6,29 +6,19 @@ fun fib(a) = if a <= 1 then a else fib(a - 1) + fib(a - 2) -//│ JS: +//│ JS (unsanitized): //│ function fib(a) { -//│ let scrut, traceLogEnterMsg, traceLogPrevIndent, traceLogRes, traceLogRetMsg, traceLogParam_a, traceLogResInspected, tmp, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; -//│ traceLogParam_a = globalThis.util.inspect(a); -//│ traceLogEnterMsg = globalThis.String.prototype.concat.call("CALL fib(", traceLogParam_a, ")"); -//│ tmp = globalThis.Predef.TraceLogger.log(traceLogEnterMsg); -//│ traceLogPrevIndent = globalThis.Predef.TraceLogger.indent(); +//│ let scrut, tmp, tmp1, tmp2, tmp3; //│ scrut = a <= 1; //│ if (scrut) { -//│ tmp1 = a; +//│ return a; //│ } else { -//│ tmp2 = a - 1; +//│ tmp = a - 1; +//│ tmp1 = globalThis.fib(tmp); +//│ tmp2 = a - 2; //│ tmp3 = globalThis.fib(tmp2); -//│ tmp4 = a - 2; -//│ tmp5 = globalThis.fib(tmp4); -//│ tmp1 = tmp3 + tmp5; +//│ return tmp1 + tmp3; //│ } -//│ traceLogRes = tmp1; -//│ traceLogResInspected = globalThis.util.inspect(traceLogRes); -//│ traceLogRetMsg = globalThis.String.prototype.concat.call("=> ", traceLogResInspected); -//│ tmp6 = globalThis.Predef.TraceLogger.resetIndent(traceLogPrevIndent); -//│ tmp7 = globalThis.Predef.TraceLogger.log(traceLogRetMsg); -//│ return traceLogRes; //│ } //│ null diff --git a/hkmc2/shared/src/test/mlscript/codegen/While.mls b/hkmc2/shared/src/test/mlscript/codegen/While.mls index 3c31c6f3b..10fc2b7bc 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/While.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/While.mls @@ -6,9 +6,8 @@ :sjs () => (while true then 0) -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 0, true, args.length); +//│ JS (unsanitized): +//│ () => { //│ let scrut, tmp; //│ tmp1: while (true) { //│ scrut = true; @@ -54,7 +53,7 @@ while x log("Hello World") set x = false else 42 -//│ JS: +//│ JS (unsanitized): //│ let scrut, tmp, tmp1; //│ tmp2: while (true) { //│ scrut = this.x; @@ -107,9 +106,8 @@ while log("checking"); i < 3 while let i = 0 i < 10 do set i += 1 -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 0, true, args.length); +//│ JS (unsanitized): +//│ () => { //│ let i, scrut, tmp, tmp1; //│ tmp2: while (true) { //│ i = 0; @@ -204,10 +202,8 @@ fun f(ls) = set ls = tl log(h) else log("Done!") -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let ls = args[0]; +//│ JS (unsanitized): +//│ function f(ls) { //│ let param0, param1, h, tl, tmp; //│ tmp1: while (true) { //│ if (ls instanceof globalThis.Cons.class) { @@ -264,7 +260,7 @@ while log("Hello World"); false then 0(0) else 1 //│ ╔══[PARSE ERROR] Unexpected 'then' keyword here -//│ ║ l.264: then 0(0) +//│ ║ l.260: then 0(0) //│ ╙── ^^^^ //│ ═══[ERROR] Unrecognized term split (false literal). //│ > Hello World diff --git a/hkmc2/shared/src/test/mlscript/parser/PrefixOps.mls b/hkmc2/shared/src/test/mlscript/parser/PrefixOps.mls index 7c93263dd..a190d5672 100644 --- a/hkmc2/shared/src/test/mlscript/parser/PrefixOps.mls +++ b/hkmc2/shared/src/test/mlscript/parser/PrefixOps.mls @@ -18,8 +18,11 @@ //│ ╔══[WARNING] Pure expression in statement position //│ ║ l.15: 1 //│ ╙── ^ -//│ JS: +//│ JS (unsanitized): //│ let tmp, tmp1; tmp = + 2; tmp1 = + 3; tmp1 +//│ ╔══[WARNING] Pure expression in statement position +//│ ║ l.15: 1 +//│ ╙── ^ //│ = 3 :w @@ -29,10 +32,10 @@ * 2 * 3 //│ ╔══[PARSE ERROR] Expected end of input; found literal instead -//│ ║ l.29: * 2 +//│ ║ l.32: * 2 //│ ╙── ^ //│ ╔══[WARNING] Pure expression in statement position -//│ ║ l.28: 1 +//│ ║ l.31: 1 //│ ╙── ^ //│ ═══[COMPILATION ERROR] Illegal reference to builtin symbol '*' //│ ═══[RUNTIME ERROR] Error: Illegal reference to builtin symbol '*' @@ -42,9 +45,8 @@ :ge + //│ ═══[COMPILATION ERROR] Illegal reference to builtin symbol '+' -//│ JS: +//│ JS (unsanitized): //│ (()=>{throw globalThis.Error("Illegal reference to builtin symbol '+'")})() -//│ ═══[RUNTIME ERROR] Error: Illegal reference to builtin symbol '+' :ge * @@ -60,7 +62,7 @@ //│ IntLit of 1 //│ Ident of "*" //│ ╔══[WARNING] Pure expression in statement position -//│ ║ l.57: 1 +//│ ║ l.59: 1 //│ ╙── ^ //│ ═══[COMPILATION ERROR] Illegal reference to builtin symbol '*' //│ ═══[RUNTIME ERROR] Error: Illegal reference to builtin symbol '*' @@ -90,7 +92,7 @@ fun (??) foo(x, y) = x + y :pe ?? 1 //│ ╔══[PARSE ERROR] Expected end of input; found literal instead -//│ ║ l.91: ?? 1 +//│ ║ l.93: ?? 1 //│ ╙── ^ //│ = [Function: foo] @@ -99,11 +101,11 @@ fun (??) foo(x, y) = x + y 1 ?? 2 //│ ╔══[PARSE ERROR] Expected end of input; found literal instead -//│ ║ l.100: ?? 2 +//│ ║ l.102: ?? 2 //│ ╙── ^ //│ ╔══[WARNING] Pure expression in statement position -//│ ║ l.99: 1 -//│ ╙── ^ +//│ ║ l.101: 1 +//│ ╙── ^ //│ = [Function: foo] :fixme diff --git a/hkmc2/shared/src/test/mlscript/rp/MatchResult.mls b/hkmc2/shared/src/test/mlscript/rp/MatchResult.mls index 1e1067a9a..05fb9033e 100644 --- a/hkmc2/shared/src/test/mlscript/rp/MatchResult.mls +++ b/hkmc2/shared/src/test/mlscript/rp/MatchResult.mls @@ -27,10 +27,8 @@ Cross.unapply("0") :sjs fun foo(x) = x is Cross -//│ JS: -//│ function foo(...args) { -//│ globalThis.Predef.checkArgs("foo", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function foo(x) { //│ let matchResult; //│ matchResult = globalThis.Cross.unapply(x) ?? null; //│ if (matchResult instanceof globalThis.Predef.MatchResult.class) { diff --git a/hkmc2/shared/src/test/mlscript/ucs/normalization/SimplePairMatches.mls b/hkmc2/shared/src/test/mlscript/ucs/normalization/SimplePairMatches.mls index 2de7cb589..3cee46b46 100644 --- a/hkmc2/shared/src/test/mlscript/ucs/normalization/SimplePairMatches.mls +++ b/hkmc2/shared/src/test/mlscript/ucs/normalization/SimplePairMatches.mls @@ -8,10 +8,8 @@ class B :sjs x => if x is Pair(A, B) then 1 -//│ JS: -//│ (...args) => { -//│ globalThis.Predef.checkArgs("", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ (x) => { //│ let param0, param1; //│ if (x instanceof this.Pair.class) { //│ param0 = x.a; @@ -37,10 +35,8 @@ x => if x is Pair(A, B) then 1 fun f(x) = if x is Pair(A, A) then 1 Pair(B, B) then 2 -//│ JS: -//│ function f(...args) { -//│ globalThis.Predef.checkArgs("f", 1, true, args.length); -//│ let x = args[0]; +//│ JS (unsanitized): +//│ function f(x) { //│ let param0, param1; //│ if (x instanceof globalThis.Pair.class) { //│ param0 = x.a; diff --git a/hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls b/hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls index 507066c49..b64d9798f 100644 --- a/hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls +++ b/hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls @@ -16,10 +16,8 @@ tupleGet([1, 2, 3, 4], -1) fun nonsense(xs) = if xs is [..ys] then ys [] then "empty" -//│ JS: -//│ function nonsense(...args) { -//│ globalThis.Predef.checkArgs("nonsense", 1, true, args.length); -//│ let xs = args[0]; +//│ JS (unsanitized): +//│ function nonsense(xs) { //│ let rest, ys; //│ if (globalThis.Array.isArray(xs) && xs.length >= 0) { //│ rest = globalThis.Predef.tupleSlice(xs, 0, 0) ?? null; @@ -41,10 +39,8 @@ nonsense([1, 2, 3, 4]) fun lead_and_last(xs) = if xs is [x, ..ys, y] then x + y [] then 0 -//│ JS: -//│ function lead_and_last(...args) { -//│ globalThis.Predef.checkArgs("lead_and_last", 1, true, args.length); -//│ let xs = args[0]; +//│ JS (unsanitized): +//│ function lead_and_last(xs) { //│ let last0, rest, first0, x, ys, y; //│ if (globalThis.Array.isArray(xs) && xs.length >= 2) { //│ first0 = xs[0]; @@ -81,10 +77,8 @@ lead_and_last(["boom"]) fun nested_tuple_patterns(xs) = if xs is [x, ..[y, z], w] then x + y + z + w [] then 0 -//│ JS: -//│ function nested_tuple_patterns(...args) { -//│ globalThis.Predef.checkArgs("nested_tuple_patterns", 1, true, args.length); -//│ let xs = args[0]; +//│ JS (unsanitized): +//│ function nested_tuple_patterns(xs) { //│ let last0, rest, first0, x, first1, first01, y, z, w, tmp, tmp1; //│ if (globalThis.Array.isArray(xs) && xs.length >= 2) { //│ first0 = xs[0];