Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing semicolons #234

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ class JSBuilder extends CodeBuilder:
assert(clsDefn.paramsOpt.isEmpty)
// doc"${mkThis(owner)}.${sym.nme} = new ${clsJS}"
doc"const $clsTmp = ${clsJS}; # ${mkThis(owner)}.${sym.nme} = new ${clsTmp
}; # ${mkThis(owner)}.${sym.nme}.class = $clsTmp"
}; # ${mkThis(owner)}.${sym.nme}.class = $clsTmp;"
case N => doc"const $clsTmp = ${clsJS}; const ${sym.nme} = new ${clsTmp
}; # ${sym.nme}.class = $clsTmp"
}; # ${sym.nme}.class = $clsTmp;"
else
val fun = clsDefn.paramsOpt match
case S(params) =>
Expand All @@ -208,19 +208,19 @@ class JSBuilder extends CodeBuilder:
val ths = mkThis(owner)
fun match
case S(f) =>
doc"${ths}.${sym.nme} = ${f}; # ${ths}.${sym.nme}.class = ${clsJS}"
doc"${ths}.${sym.nme} = ${f}; # ${ths}.${sym.nme}.class = ${clsJS};"
case N =>
doc"${ths}.${sym.nme} = ${clsJS}"
doc"${ths}.${sym.nme} = ${clsJS};"
case N =>
fun match
case S(f) => doc"${f}; # ${sym.nme}.class = ${clsJS}"
case S(f) => doc"${f}; # ${sym.nme}.class = ${clsJS};"
case N => clsJS
thisProxy match
case S(proxy) => doc" # const $proxy = this; # ${res.stripBreaks};${returningTerm(rst)}"
case N => doc"$res;${returningTerm(rst)}"
case S(proxy) => doc" # const $proxy = this; # ${res.stripBreaks}${returningTerm(rst)}"
case N => doc"$res${returningTerm(rst)}"
doc" # ${resJS}"
case Return(res, true) => doc" # ${result(res)}"
case Return(res, false) => doc" # return ${result(res)}"
case Return(res, false) => doc" # return ${result(res)};"

// TODO factor out common logic
case Match(scrut, Case.Lit(syntax.Tree.BoolLit(true)) -> trm :: Nil, els, rest) =>
Expand Down Expand Up @@ -262,13 +262,13 @@ class JSBuilder extends CodeBuilder:
doc" # /* $msg */"

case Throw(res) =>
doc" # throw ${result(res)}"
doc" # throw ${result(res)};"

case Break(lbl, false) =>
doc" # break ${getVar(lbl)}"
doc" # break ${getVar(lbl)};"

case Break(lbl, true) =>
doc" # continue ${getVar(lbl)}"
doc" # continue ${getVar(lbl)};"

case Label(lbl, bod, rst) =>
scope.allocateName(lbl)
Expand Down
4 changes: 2 additions & 2 deletions hkmc2/shared/src/test/mlscript-compile/Example.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const Example$class = class Example {

}
funnySlash(f, arg) {
return f(arg)
return f(arg);
}
inc(x) {
return x + 1
return x + 1;
}
toString() { return "Example"; }
}; const Example = new Example$class;
Expand Down
8 changes: 4 additions & 4 deletions hkmc2/shared/src/test/mlscript-compile/Option.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ const Option$class = class Option {
}
isDefined(x) {
if (x instanceof this.Some.class) {
return true
return true;
} else {
if (x instanceof this.None.class) {
return false
return false;
} else {
throw new globalThis.Error("match error")
throw new globalThis.Error("match error");
}
}
}
test() {
return Predef.pipe(2134, Predef.print)
return Predef.pipe(2134, Predef.print);
}
toString() { return "Option"; }
}; const Option = new Option$class;
Expand Down
10 changes: 5 additions & 5 deletions hkmc2/shared/src/test/mlscript-compile/Predef.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ const Predef$class = class Predef {

}
id(x) {
return x
return x;
}
pipe(x1, f) {
return f(x1)
return f(x1);
}
call(receiver, f1) {
return (arg) => {
return f1.call(receiver, arg)
}
return f1.call(receiver, arg);
};
}
print(x2) {
let tmp;
tmp = String(x2);
return console.log(tmp)
return console.log(tmp);
}
toString() { return "Predef"; }
}; const Predef = new Predef$class;
Expand Down
4 changes: 2 additions & 2 deletions hkmc2/shared/src/test/mlscript-compile/Stack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const Stack$class = class Stack {
}
isEmpty(xs) {
if (xs instanceof this.Nil.class) {
return true
return true;
} else {
return false
return false;
}
}
toString() { return "Stack"; }
Expand Down
22 changes: 11 additions & 11 deletions hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

fun f(n1: Int): Int = n1
//│ JS:
//│ function f(n1) { return n1 }; undefined
//│ function f(n1) { return n1; } undefined

f(42)
//│ JS:
Expand All @@ -15,7 +15,7 @@ f(42)

fun f(n1: Int)(n2: Int): Int = (10 * n1 + n2)
//│ JS:
//│ function f(n1) { return (n2) => { let tmp; tmp = 10 * n1; return tmp + n2 } }; undefined
//│ function f(n1) { return (n2) => { let tmp; tmp = 10 * n1; return tmp + n2; }; } undefined

f(4)(2)
//│ JS:
Expand All @@ -31,10 +31,10 @@ fun f(n1: Int)(n2: Int)(n3: Int): Int = 10 * (10 * n1 + n2) + n3
//│ tmp = 10 * n1;
//│ tmp1 = tmp + n2;
//│ tmp2 = 10 * tmp1;
//│ return tmp2 + n3
//│ }
//│ }
//│ };
//│ return tmp2 + n3;
//│ };
//│ };
//│ }
//│ undefined

f(4)(2)(0)
Expand All @@ -54,11 +54,11 @@ fun f(n1: Int)(n2: Int)(n3: Int)(n4: Int): Int = 10 * (10 * (10 * n1 + n2) + n3)
//│ tmp2 = 10 * tmp1;
//│ tmp3 = tmp2 + n3;
//│ tmp4 = 10 * tmp3;
//│ return tmp4 + n4
//│ }
//│ }
//│ }
//│ };
//│ return tmp4 + n4;
//│ };
//│ };
//│ };
//│ }
//│ undefined

f(3)(0)(3)(1)
Expand Down
6 changes: 3 additions & 3 deletions hkmc2/shared/src/test/mlscript/codegen/BadThis.mls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:js


globalThis.navigator
//│ = Navigator {}
globalThis.clearInterval
//│ = [Function: clearInterval]

class A

Expand All @@ -16,7 +16,7 @@ if 0 is A then 1
val globalThis = "oops"
//│ globalThis = 'oops'

globalThis.navigator
globalThis.clearInterval

:re
if 0 is A then 1
Expand Down
10 changes: 5 additions & 5 deletions hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ fun test(x) =
//│ if (x instanceof globalThis.None.class) {
//│ tmp1 = globalThis.None;
//│ } else {
//│ throw new globalThis.Error("match error")
//│ throw new globalThis.Error("match error");
//│ }
//│ }
//│ scrut = tmp1;
//│ if (scrut instanceof globalThis.Some.class) {
//│ param01 = scrut.value;
//│ v1 = param01;
//│ return globalThis.log(v1)
//│ return globalThis.log(v1);
//│ } else {
//│ if (scrut instanceof globalThis.None.class) {
//│ return globalThis.log("none")
//│ return globalThis.log("none");
//│ } else {
//│ throw new globalThis.Error("match error")
//│ throw new globalThis.Error("match error");
//│ }
//│ }
//│ };
//│ }
//│ undefined


Expand Down
20 changes: 13 additions & 7 deletions hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,35 @@ case x then x
:sjs
case { x then x }
//│ JS:
//│ (caseScrut) => { let x; x = caseScrut; return x }
//│ (caseScrut) => { let x; x = caseScrut; return x; }
//│ = [Function (anonymous)]

:sjs
x => if x is
0 then true
//│ JS:
//│ (x) => { if (x === 0) { return true } else { throw new this.Error("match error") } }
//│ (x) => { if (x === 0) { return true; } else { throw new this.Error("match error"); } }
//│ = [Function (anonymous)]

:sjs
case
0 then true
//│ JS:
//│ (caseScrut) => { if (caseScrut === 0) { return true } else { throw new this.Error("match error") } }
//│ (caseScrut) => {
//│ if (caseScrut === 0) {
//│ return true;
//│ } else {
//│ throw new this.Error("match error");
//│ }
//│ }
//│ = [Function (anonymous)]

:sjs
case
0 then true
_ then false
//│ JS:
//│ (caseScrut) => { if (caseScrut === 0) { return true } else { return false } }
//│ (caseScrut) => { if (caseScrut === 0) { return true; } else { return false; } }
//│ = [Function (anonymous)]

class Some(value)
Expand All @@ -46,12 +52,12 @@ val isDefined = case
//│ JS:
//│ this.isDefined = (caseScrut) => {
//│ if (caseScrut instanceof this.Some.class) {
//│ return true
//│ return true;
//│ } else {
//│ if (caseScrut instanceof this.None.class) {
//│ return false
//│ return false;
//│ } else {
//│ throw new this.Error("match error")
//│ throw new this.Error("match error");
//│ }
//│ }
//│ };
Expand Down
6 changes: 3 additions & 3 deletions hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Outer(a, b) with
//│ this$Outer.b,
//│ this.c,
//│ d
//│ ]
//│ ];
//│ }
//│ toString() { return "Inner(" + this.c + ")"; }
//│ };
Expand All @@ -51,12 +51,12 @@ class Outer(a, b) with
//│ globalThis.log(tmp2)
//│ }
//│ o1(c) {
//│ return this.Inner(c)
//│ return this.Inner(c);
//│ }
//│ o2(c1, d) {
//│ let tmp;
//│ tmp = this.Inner(c1);
//│ return tmp.i1(d)
//│ return tmp.i1(d);
//│ }
//│ toString() { return "Outer(" + this.a + ", " + this.b + ")"; }
//│ };
Expand Down
10 changes: 5 additions & 5 deletions hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ fun test(a) =
//│ this.x = a;
//│ }
//│ toString() { return "C"; }
//│ };
//│ return new C()
//│ };
//│ }
//│ return new C();
//│ }
//│ undefined

test(12)
Expand All @@ -41,8 +41,8 @@ fun test(x) =
//│ toString() { return "Foo(" + this.a + ", " + this.b + ")"; }
//│ };
//│ tmp = x + 1;
//│ return Foo(x, tmp)
//│ };
//│ return Foo(x, tmp);
//│ }
//│ undefined


Expand Down
Loading
Loading