Skip to content

Commit

Permalink
Fix missing semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsonYeung committed Nov 13, 2024
1 parent cc65fc1 commit 5f5ffed
Show file tree
Hide file tree
Showing 31 changed files with 130 additions and 124 deletions.
8 changes: 4 additions & 4 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class JSBuilder extends CodeBuilder:
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
18 changes: 9 additions & 9 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,9 +31,9 @@ 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

Expand All @@ -54,10 +54,10 @@ 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

Expand Down
8 changes: 4 additions & 4 deletions hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ 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");
//│ }
//│ }
//│ };
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
4 changes: 2 additions & 2 deletions hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun test(a) =
//│ }
//│ toString() { return "C"; }
//│ };
//│ return new C()
//│ return new C();
//│ };
//│ undefined

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

Expand Down
24 changes: 12 additions & 12 deletions hkmc2/shared/src/test/mlscript/codegen/ClassMatching.mls
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if Some(0) is Some(x) then x
//│ x = param0;
//│ x
//│ } else {
//│ throw new this.Error("match error")
//│ throw new this.Error("match error");
//│ }
//│ = 0

Expand All @@ -38,7 +38,7 @@ if s is
//│ x = param0;
//│ x
//│ } else {
//│ throw new this.Error("match error")
//│ throw new this.Error("match error");
//│ }
//│ = 0

Expand Down Expand Up @@ -66,9 +66,9 @@ x => if x is Some(x) then x
//│ if (x instanceof this.Some.class) {
//│ param0 = x.value;
//│ x1 = param0;
//│ return x1
//│ return x1;
//│ } else {
//│ throw new this.Error("match error")
//│ throw new this.Error("match error");
//│ }
//│ }
//│ = [Function (anonymous)]
Expand Down Expand Up @@ -127,15 +127,15 @@ fun f(x) = if x is
//│ x1 = param0;
//│ scrut = x1 > 0;
//│ if (scrut) {
//│ return 42
//│ return 42;
//│ } else {
//│ return globalThis.log("oops")
//│ return globalThis.log("oops");
//│ }
//│ } else {
//│ if (x instanceof globalThis.None.class) {
//│ return "ok"
//│ return "ok";
//│ } else {
//│ return globalThis.log("oops")
//│ return globalThis.log("oops");
//│ }
//│ }
//│ };
Expand Down Expand Up @@ -167,16 +167,16 @@ fun f(x) = if x is
//│ if (x instanceof globalThis.Some.class) {
//│ param01 = x.value;
//│ u = param01;
//│ return u
//│ return u;
//│ } else {
//│ if (x instanceof globalThis.Pair.class) {
//│ param0 = x.fst;
//│ param1 = x.snd;
//│ a = param0;
//│ b = param1;
//│ return a + b
//│ return a + b;
//│ } else {
//│ throw new globalThis.Error("match error")
//│ throw new globalThis.Error("match error");
//│ }
//│ }
//│ };
Expand Down Expand Up @@ -212,7 +212,7 @@ fun f(x) = log of if x is
//│ tmp = "oops";
//│ }
//│ }
//│ return globalThis.log(tmp)
//│ return globalThis.log(tmp);
//│ };
//│ undefined

Expand Down
6 changes: 3 additions & 3 deletions hkmc2/shared/src/test/mlscript/codegen/Comma.mls
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
fun f() =
console.log("ok"), 42
//│ JS:
//│ function f() { let tmp; tmp = globalThis.console.log("ok"); return 42 }; undefined
//│ function f() { let tmp; tmp = globalThis.console.log("ok"); return 42; }; undefined

fun f() = { console.log("ok"), 42 }
//│ JS:
//│ function f() { let tmp; tmp = globalThis.console.log("ok"); return 42 }; undefined
//│ function f() { let tmp; tmp = globalThis.console.log("ok"); return 42; }; undefined

fun f() = console.log("ok"), 42
//│ JS:
//│ function f() { return globalThis.console.log("ok") }; 42
//│ function f() { return globalThis.console.log("ok"); }; 42
//│ = 42


2 changes: 1 addition & 1 deletion hkmc2/shared/src/test/mlscript/codegen/DelayedLetInit.mls
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ z = 1

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

f
//│ JS:
Expand Down
4 changes: 2 additions & 2 deletions hkmc2/shared/src/test/mlscript/codegen/EarlyReturn.mls
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fun f(x) =
//│ scrut = x < 0;
//│ if (scrut) {
//│ tmp = globalThis.log("whoops");
//│ return 0
//│ return 0;
//│ } else {
//│ tmp1 = undefined;
//│ }
//│ return x + 1
//│ return x + 1;
//│ };
//│ undefined

Expand Down
Loading

0 comments on commit 5f5ffed

Please sign in to comment.