Skip to content

Commit 2548c78

Browse files
committed
Merge branch 'instrument-with-pretty-print' into instrument
2 parents 7151735 + 71a8918 commit 2548c78

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,28 @@ fun showPath(p) =
7979
DynSelect(qual, fld, idx) then showPath(qual) + "[" + showPath(fld) + "]"
8080
ValueRef(s) then showSymbol(s)
8181
ValueLit(l) then showLiteral(l)
82-
_ then "<unknown>"
82+
_ then "<unknown path>"
8383

8484
fun showArg(a) =
8585
(if a.spread is Some(true) then "..." else "") + showPath(a.value)
8686

8787
fun showArgs(args) =
88-
args.map(showArg)
88+
args.map(showArg).join(",")
8989

9090
fun showResult(r) =
9191
if r is
9292
Call(f, args) then showPath(f) + "(" + showArgs(args) + ")"
9393
Instantiate(cls, args) then "new " + showPath(cls) + "(" + showArgs(args) + ")"
9494
Tuple(elems) then "[" + showArgs(elems) + "]"
9595
Path then showPath(r)
96+
_ then "<unknown result>"
9697

9798
fun showCase(c) =
9899
if c is
99100
Lit(l) then showLiteral(l)
100-
Cls(cls, p) then showSymbol(cls) + "(" + showPath(p) + ")"
101+
Cls(cls, p) then showSymbol(cls)
101102
Tup(len) then "Tuple"
102-
_ then "_"
103+
_ then "<unknown case>"
103104

104105
fun showArm(a) =
105106
showCase(a.cse) + " then " + showBlock(a.body)
@@ -116,11 +117,13 @@ fun showDefn(d) =
116117
if d is
117118
ValDefn(sym, rhs) then
118119
"let " + showSymbol(sym) + " = " + showPath(rhs)
119-
FunDefn(sym, params, body) then
120-
"fun " + showSymbol(sym) + "(" + params.map(showSymbol) + ") =" +
120+
FunDefn(sym, p, body) then
121+
"fun " + showSymbol(sym) + showParams(p) + " =" +
121122
(if body is Return(_, _) then " " else "\n ") + showBlock(body)
122-
ClsLikeDefn(sym, paramsOpt) then
123-
"class " + showSymbol(sym) + showParamsOpt(paramsOpt)
123+
ClsLikeDefn(sym, _) then
124+
if sym is
125+
ClassSymbol(n, paramsOpt) then "class " + n + showParamsOpt(paramsOpt)
126+
_ then "<unknown defn>"
124127

125128
fun showBlock(b) =
126129
if b is
@@ -136,7 +139,7 @@ fun showBlock(b) =
136139
(if dflt is Some(db) then "\nelse " + showBlock(db) else "") +
137140
"\n" + showBlock(rest)
138141
End() then ""
139-
x then x
142+
_ then "<unknown block>"
140143

141144
fun printCode(p: Block) =
142145
let s = showBlock(p) in

hkmc2/shared/src/test/mlscript/staging/Functions.mls

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
//│ }
3434
//│ ShapeSet = class ShapeSet { ShapeSet: fun ShapeSet { class: class ShapeSet } }
3535

36-
:slot
3736
:js
38-
staged module Expressions with
37+
staged module Expressions with
3938
fun lit() = 1
4039
fun assign() =
4140
let x = 42
@@ -54,29 +53,6 @@ staged module Expressions with
5453
Bool then 4
5554
// [1, 2] then 5 // TODO: Case.Tup, needs handling for Label, Break
5655
else 0
57-
//│ Pretty Lowered:
58-
//│
59-
//│ define staged class Expressions in
60-
//│ set tmp = Expressions.lit_gen() in
61-
//│ set tmp1 = shapeSet.printShapeSet(tmp.(0)) in
62-
//│ set tmp2 = Block.printCode(tmp.(1)) in
63-
//│ set tmp3 = Expressions.assign_gen() in
64-
//│ set tmp4 = shapeSet.printShapeSet(tmp3.(0)) in
65-
//│ set tmp5 = Block.printCode(tmp3.(1)) in
66-
//│ set tmp6 = Expressions._var_gen() in
67-
//│ set tmp7 = shapeSet.printShapeSet(tmp6.(0)) in
68-
//│ set tmp8 = Block.printCode(tmp6.(1)) in
69-
//│ set tmp9 = Expressions.tup_gen() in
70-
//│ set tmp10 = shapeSet.printShapeSet(tmp9.(0)) in
71-
//│ set tmp11 = Block.printCode(tmp9.(1)) in
72-
//│ set tmp12 = Expressions.dynsel_gen() in
73-
//│ set tmp13 = shapeSet.printShapeSet(tmp12.(0)) in
74-
//│ set tmp14 = Block.printCode(tmp12.(1)) in
75-
//│ set tmp15 = Expressions.match_gen() in
76-
//│ set tmp16 = shapeSet.printShapeSet(tmp15.(0)) in
77-
//│ set tmp17 = Block.printCode(tmp15.(1)) in
78-
//│ set block$res2 = undefined in
79-
//│ end
8056
//│ > Lit(1)
8157
//│ > 1
8258
//│ > Lit(42)
@@ -95,22 +71,22 @@ staged module Expressions with
9571
//│ > Dyn
9672
//│ > let scrut = 9
9773
//│ > if scrut is
98-
//│ > _ then undefined
99-
//│ > _ then undefined
74+
//│ > <unknown case> then <unknown block>
75+
//│ > <unknown case> then <unknown block>
10076
//│ > else 0
10177
//│ >
10278

10379
:js
10480
:staging
10581
class Outside(a)
10682
staged module ClassInstrumentation with
107-
class Inside(a, b)
83+
class Inside(a, b) // not printed correctly
10884
class NoArg
10985
fun inst1() = new Outside(1)
11086
fun inst2() = new NoArg
11187
//│ > class NoArg()
11288
//│ >
113-
//│ > class Inside()
89+
//│ > class Inside(a, b)
11490
//│ >
11591
//│ > Class(Outside, [Lit(1)])
11692
//│ > new Outside(1)
@@ -135,8 +111,8 @@ module A with
135111
fun f() = 1
136112
//│ ╔══[COMPILATION ERROR] No definition found in scope for member 'B'
137113
//│ ╟── which references the symbol introduced here
138-
//│ ║ l.134: staged module B with
114+
//│ ║ l.110: staged module B with
139115
//│ ║ ^^^^^^
140-
//│ ║ l.135: fun f() = 1
116+
//│ ║ l.111: fun f() = 1
141117
//│ ╙── ^^^^^^^^^^^^^^^
142118
//│ ═══[RUNTIME ERROR] ReferenceError: B is not defined

hkmc2/shared/src/test/mlscript/staging/PrintCode.mls

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Block.printCode(Block.Define(Block.FunDefn(Block.Symbol("f"), [Block.Symbol("x")
4444

4545
Block.printCode(
4646
Block.Define(
47-
Block.ClsLikeDefn(Block.Symbol("C"), Some([Block.Symbol("x"), Block.Symbol("y")]), None),
47+
Block.ClsLikeDefn(Block.ClassSymbol("C", Some([Block.Symbol("x"), Block.Symbol("y")])), None),
4848
Block.Assign(
4949
Block.Symbol("x"),
5050
Block.Instantiate(
@@ -61,13 +61,15 @@ Block.printCode(
6161
//│ > let x = new C(1,2)
6262
//│ > x.y
6363

64-
Block.printCode(Block.Return(Block.Tuple([Block.Arg(None, Block.ValueLit(1)), Block.Arg(None, Block.ValueLit(2))]), false))
65-
//│ > [1,2]
66-
67-
Block.printCode(Block.Match(Block.ValueLit(2), [Block.Arm(Block.Lit(1), Block.Return(Block.ValueLit(1), false)), Block.Arm(Block.Lit(2), Block.Return(Block.ValueLit(2), false))], Some(Block.Return(Block.ValueLit(3), false)), Block.End()))
64+
Block.printCode(
65+
Block.Match(
66+
Block.ValueLit(2),
67+
[Block.Arm(Block.Lit(1), Block.Return(Block.ValueLit(1), false)), Block.Arm(Block.Lit(2), Block.Return(Block.ValueLit(2), false))],
68+
Some(Block.Return(Block.ValueLit(3), false)), Block.End()
69+
)
70+
)
6871
//│ > if 2 is
6972
//│ > 1 then 1
7073
//│ > 2 then 2
7174
//│ > else 3
7275
//│ >
73-

0 commit comments

Comments
 (0)