Skip to content

Commit d706e5a

Browse files
Use sub-module (#380)
1 parent 5ce99a8 commit d706e5a

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ object Elaborator:
309309
val orSymbol = builtinOpsMap("||")
310310
def init(using State): Ctx = Ctx.empty.copy(env = Map(
311311
"globalThis" -> globalThisSymbol,
312-
"Term" -> termSymbol,
313312
))
314313
def dbg: Bool = false
315314
def dbgRefNum(num: Int): Str =

hkmc2/shared/src/test/mlscript-compile/Predef.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import runtime from "./Runtime.mjs";
44
import RuntimeJS from "./RuntimeJS.mjs";
55
import Runtime from "./Runtime.mjs";
66
import Rendering from "./Rendering.mjs";
7+
import Term from "./Term.mjs";
78
let Predef1;
89
(class Predef {
910
static {
@@ -39,6 +40,22 @@ let Predef1;
3940
this.render = Rendering.render;
4041
this.assert = globalThis.console.assert;
4142
this.foldl = Predef.fold;
43+
(class meta {
44+
static {
45+
Predef.meta = this
46+
}
47+
constructor() {
48+
runtime.Unit;
49+
}
50+
static codegen(t, file) {
51+
return Term.codegen(t, file)
52+
}
53+
static print(t) {
54+
return runtime.safeCall(Term.print(t))
55+
}
56+
toString() { return runtime.render(this); }
57+
static [definitionMetadata] = ["class", "meta"];
58+
});
4259
}
4360
static id(x) {
4461
return x

hkmc2/shared/src/test/mlscript-compile/Predef.mls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "./RuntimeJS.mjs"
55
// * TODO: proper caching of parsed/elaborated files
66
import "./Runtime.mjs"
77
import "./Rendering.mjs"
8+
import "./Term.mjs"
89
// import "./Runtime.mls"
910
// import "./Rendering.mls"
1011

@@ -126,3 +127,6 @@ fun raiseUnhandledEffect() =
126127
Runtime.mkEffect(Runtime.FatalEffect, null)
127128

128129

130+
module meta with
131+
fun codegen(t, file) = Term.codegen(t, file)
132+
fun print(t) = Term.print(t)

hkmc2/shared/src/test/mlscript/codegen/QQImport.mls

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@
33

44

55

6-
Term.print
6+
meta.print
77
//│ = fun print
88

99

10-
Term.print(`42)
10+
meta.print(`42)
1111
//│ > 42
1212

1313

14-
Term.print(`+)
14+
meta.print(`+)
1515
//│ > +
1616

1717

18-
Term.print(`1 `+ `2)
18+
meta.print(`1 `+ `2)
1919
//│ > (+)(1, 2)
2020

2121

22-
Term.print(x `=> x)
22+
meta.print(x `=> x)
2323
//│ > (x_0) =>
2424
//│ > x_0
2525

2626

27-
Term.print((x, y) `=> x `+ y)
27+
meta.print((x, y) `=> x `+ y)
2828
//│ > (x_0, y_0) =>
2929
//│ > (+)(x_0, y_0)
3030

3131

32-
Term.print(`let x = `42 `in x)
32+
meta.print(`let x = `42 `in x)
3333
//│ > let x_0
3434
//│ > x_0 = 42
3535
//│ > x_0
3636

3737

38-
Term.print(`if `true then `true else `false)
38+
meta.print(`if `true then `true else `false)
3939
//│ > if
4040
//│ > let scrut_0 = true
4141
//│ > scrut_0 is true then true
4242
//│ > else false
4343

4444

45-
Term.print(x `=> `if x `=== `0.0 then `1.0 else x)
45+
meta.print(x `=> `if x `=== `0.0 then `1.0 else x)
4646
//│ > (x_0) =>
4747
//│ > if
4848
//│ > let scrut_0 = (===)(x_0, 0)
@@ -72,7 +72,7 @@ QuoteInc.res(42)
7272
import "../../mlscript-compile/CSP.mls"
7373

7474

75-
Term.codegen(CSP.foo(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPFoo.mls")
75+
meta.codegen(CSP.foo(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPFoo.mls")
7676

7777

7878
import "../../mlscript-compile/quotes/CSPFoo.mls"
@@ -82,7 +82,7 @@ CSPFoo.res
8282
//│ = 124
8383

8484

85-
Term.codegen(CSP.bar(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPBar.mls")
85+
meta.codegen(CSP.bar(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPBar.mls")
8686

8787

8888
import "../../mlscript-compile/quotes/CSPBar.mls"
@@ -92,7 +92,7 @@ CSPBar.res
9292
//│ = 1
9393

9494

95-
Term.codegen(CSP.baz(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPBaz.mls")
95+
meta.codegen(CSP.baz(), "./hkmc2/shared/src/test/mlscript-compile/quotes/CSPBaz.mls")
9696

9797

9898
import "../../mlscript-compile/quotes/CSPBaz.mls"

hkmc2/shared/src/test/mlscript/ctx/Summon.mls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use[Num]
1919
//│ ║ l.17: use[Num]
2020
//│ ║ ^^^^^^^^
2121
//│ ╟── Required by contextual parameter declaration:
22-
//│ ║ l.115: fun use[T](using instance: T) = instance
22+
//│ ║ l.116: fun use[T](using instance: T) = instance
2323
//│ ║ ^^^^^^^^^^^
2424
//│ ╙── Missing instance: Expected: Num (type parameter T); Available: Int, Str
2525
//│ ═══[RUNTIME ERROR] Error: MLscript call unexpectedly returned `undefined`, the forbidden value.
@@ -55,7 +55,7 @@ fun f(using Int) = use[Num]
5555
//│ ║ l.53: fun f(using Int) = use[Num]
5656
//│ ║ ^^^^^^^^
5757
//│ ╟── Required by contextual parameter declaration:
58-
//│ ║ l.115: fun use[T](using instance: T) = instance
58+
//│ ║ l.116: fun use[T](using instance: T) = instance
5959
//│ ║ ^^^^^^^^^^^
6060
//│ ╙── Missing instance: Expected: Num (type parameter T); Available: Int, Str
6161

@@ -79,7 +79,7 @@ use{[Some[Int]].value}
7979
//│ ║ l.74: use{[Some[Int]].value}
8080
//│ ║ ^^^
8181
//│ ╟── Required by contextual parameter declaration:
82-
//│ ║ l.115: fun use[T](using instance: T) = instance
82+
//│ ║ l.116: fun use[T](using instance: T) = instance
8383
//│ ║ ^^^^^^^^^^^
8484
//│ ╙── Illegal query for an unspecified type variable T.
8585
//│ ═══[RUNTIME ERROR] Error: MLscript call unexpectedly returned `undefined`, the forbidden value.
@@ -91,7 +91,7 @@ use([Some[Int]].value)
9191
//│ ║ l.89: use([Some[Int]].value)
9292
//│ ║ ^^^
9393
//│ ╟── Required by contextual parameter declaration:
94-
//│ ║ l.115: fun use[T](using instance: T) = instance
94+
//│ ║ l.116: fun use[T](using instance: T) = instance
9595
//│ ║ ^^^^^^^^^^^
9696
//│ ╙── Illegal query for an unspecified type variable T.
9797
//│ ═══[RUNTIME ERROR] Error: MLscript call unexpectedly returned `undefined`, the forbidden value.

0 commit comments

Comments
 (0)