Skip to content

Commit 58a671a

Browse files
committed
Update test
1 parent 3423c53 commit 58a671a

File tree

1 file changed

+93
-73
lines changed

1 file changed

+93
-73
lines changed

hkmc2/shared/src/test/mlscript/lifter/ClassInFun.mls

Lines changed: 93 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,37 @@ fun f() =
1313
1
1414
f() + f() + f()
1515
//│ JS (unsanitized):
16-
//│ let Effect1, tmp, handleBlock$, Cont$func$f$1, Cont$handleBlock$h$1, hdlrFun, Handler$h$1, f$, doUnwind$, Cont$func$f$$ctor, Cont$func$f$$, Cont$handleBlock$h$$ctor, Cont$handleBlock$h$$, hdlrFun$;
16+
//│ let f, Effect1, h, tmp, handleBlock$, hdlrFun, Handler$h$1, Cont$func$f$1, Cont$handleBlock$h$1, doUnwind$, Cont$func$f$$ctor, Cont$func$f$$, doUnwind$1, Cont$handleBlock$h$$ctor, Cont$handleBlock$h$$, hdlrFun$;
1717
//│ Effect1 = class Effect {
1818
//│ constructor() {}
1919
//│ toString() { return "Effect"; }
2020
//│ };
21-
//│ hdlrFun$ = function hdlrFun$(Handler$h$$instance, k) {
22-
//│ return runtime.safeCall(k())
23-
//│ };
24-
//│ hdlrFun = function hdlrFun(Handler$h$$instance) {
25-
//│ return (k) => {
26-
//│ return hdlrFun$(Handler$h$$instance, k)
27-
//│ }
28-
//│ };
29-
//│ Handler$h$1 = class Handler$h$ extends Effect1 {
30-
//│ constructor() {
31-
//│ let tmp1;
32-
//│ tmp1 = super();
33-
//│ }
34-
//│ perform() {
35-
//│ let hdlrFun$this;
36-
//│ hdlrFun$this = runtime.safeCall(hdlrFun(this));
37-
//│ return runtime.mkEffect(this, hdlrFun$this)
38-
//│ }
39-
//│ toString() { return "Handler$h$"; }
40-
//│ };
41-
//│ Cont$handleBlock$h$$ = function Cont$handleBlock$h$$(h$0, tmp$1, tmp$2, tmp$3, tmp$4, pc) {
21+
//│ Cont$handleBlock$h$$ = function Cont$handleBlock$h$$(tmp$0, tmp$1, tmp$2, tmp$3, pc) {
4222
//│ let tmp1;
4323
//│ tmp1 = new Cont$handleBlock$h$1.class(pc);
44-
//│ return tmp1(h$0, tmp$1, tmp$2, tmp$3, tmp$4)
24+
//│ return tmp1(tmp$0, tmp$1, tmp$2, tmp$3)
4525
//│ };
46-
//│ Cont$handleBlock$h$$ctor = function Cont$handleBlock$h$$ctor(h$0, tmp$1, tmp$2, tmp$3, tmp$4) {
26+
//│ Cont$handleBlock$h$$ctor = function Cont$handleBlock$h$$ctor(tmp$0, tmp$1, tmp$2, tmp$3) {
4727
//│ return (pc) => {
4828
//│ let tmp1;
4929
//│ tmp1 = new Cont$handleBlock$h$1.class(pc);
50-
//│ return tmp1(h$0, tmp$1, tmp$2, tmp$3, tmp$4)
30+
//│ return tmp1(tmp$0, tmp$1, tmp$2, tmp$3)
5131
//│ }
5232
//│ };
5333
//│ Cont$handleBlock$h$1 = function Cont$handleBlock$h$(pc1) {
54-
//│ return (h$01, tmp$11, tmp$21, tmp$31, tmp$41) => {
55-
//│ return new Cont$handleBlock$h$.class(pc1)(h$01, tmp$11, tmp$21, tmp$31, tmp$41);
34+
//│ return (tmp$01, tmp$11, tmp$21, tmp$31) => {
35+
//│ return new Cont$handleBlock$h$.class(pc1)(tmp$01, tmp$11, tmp$21, tmp$31);
5636
//│ }
5737
//│ };
5838
//│ Cont$handleBlock$h$1.class = class Cont$handleBlock$h$ extends runtime.FunctionContFrame.class {
5939
//│ constructor(pc) {
60-
//│ return (h$0, tmp$1, tmp$2, tmp$3, tmp$4) => {
40+
//│ return (tmp$0, tmp$1, tmp$2, tmp$3) => {
6141
//│ let tmp1;
6242
//│ tmp1 = super(null);
63-
//│ this.h$0 = h$0;
43+
//│ this.tmp$0 = tmp$0;
6444
//│ this.tmp$1 = tmp$1;
6545
//│ this.tmp$2 = tmp$2;
6646
//│ this.tmp$3 = tmp$3;
67-
//│ this.tmp$4 = tmp$4;
6847
//│ this.pc = pc;
6948
//│ return this;
7049
//│ }
@@ -77,42 +56,53 @@ f() + f() + f()
7756
//│ }
7857
//│ resume(value$) {
7958
//│ if (this.pc === 2) {
80-
//│ this.tmp$1 = value$;
59+
//│ this.tmp$0 = value$;
8160
//│ } else if (this.pc === 3) {
82-
//│ this.tmp$2 = value$;
61+
//│ this.tmp$1 = value$;
8362
//│ } else if (this.pc === 4) {
84-
//│ this.tmp$4 = value$;
63+
//│ this.tmp$3 = value$;
8564
//│ }
8665
//│ contLoop: while (true) {
87-
//│ if (this.pc === 2) {
66+
//│ if (this.pc === 0) {
67+
//│ this.tmp$0 = f();
68+
//│ if (this.tmp$0 instanceof runtime.EffectSig.class) {
69+
//│ return this.doUnwind(this.tmp$0, 2)
70+
//│ }
71+
//│ this.pc = 2;
72+
//│ continue contLoop;
73+
//│ } else if (this.pc === 2) {
8874
//│ this.pc = 6;
8975
//│ continue contLoop;
9076
//│ } else if (this.pc === 6) {
91-
//│ this.tmp$2 = f$(this.h$0);
92-
//│ if (this.tmp$2 instanceof runtime.EffectSig.class) {
93-
//│ return this.doUnwind(this.tmp$2, 3)
77+
//│ this.tmp$1 = f();
78+
//│ if (this.tmp$1 instanceof runtime.EffectSig.class) {
79+
//│ return this.doUnwind(this.tmp$1, 3)
9480
//│ }
9581
//│ this.pc = 3;
9682
//│ continue contLoop;
9783
//│ } else if (this.pc === 3) {
98-
//│ this.tmp$3 = this.tmp$1 + this.tmp$2;
84+
//│ this.tmp$2 = this.tmp$0 + this.tmp$1;
9985
//│ this.pc = 5;
10086
//│ continue contLoop;
10187
//│ } else if (this.pc === 5) {
102-
//│ this.tmp$4 = f$(this.h$0);
103-
//│ if (this.tmp$4 instanceof runtime.EffectSig.class) {
104-
//│ return this.doUnwind(this.tmp$4, 4)
88+
//│ this.tmp$3 = f();
89+
//│ if (this.tmp$3 instanceof runtime.EffectSig.class) {
90+
//│ return this.doUnwind(this.tmp$3, 4)
10591
//│ }
10692
//│ this.pc = 4;
10793
//│ continue contLoop;
10894
//│ } else if (this.pc === 4) {
109-
//│ return this.tmp$3 + this.tmp$4
95+
//│ return this.tmp$2 + this.tmp$3
11096
//│ }
11197
//│ break;
11298
//│ }
11399
//│ }
114100
//│ toString() { return "Cont$handleBlock$h$(" + runtime.render(this.pc) + ")"; }
115101
//│ };
102+
//│ doUnwind$1 = function doUnwind$(tmp1, tmp2, tmp3, tmp4, res, pc) {
103+
//│ res.contTrace.last.next = Cont$handleBlock$h$$(tmp1, tmp2, tmp3, tmp4, pc);
104+
//│ return runtime.handleBlockImpl(res, h)
105+
//│ };
116106
//│ Cont$func$f$$ = function Cont$func$f$$(tmp$0, pc) {
117107
//│ let tmp1;
118108
//│ tmp1 = new Cont$func$f$1.class(pc);
@@ -140,12 +130,25 @@ f() + f() + f()
140130
//│ return this;
141131
//│ }
142132
//│ }
133+
//│ doUnwind(res, newPc) {
134+
//│ this.pc = newPc;
135+
//│ res.contTrace.last.next = this;
136+
//│ res.contTrace.last = this;
137+
//│ return res
138+
//│ }
143139
//│ resume(value$) {
144140
//│ if (this.pc === 1) {
145141
//│ this.tmp$0 = value$;
146142
//│ }
147143
//│ contLoop: while (true) {
148-
//│ if (this.pc === 1) {
144+
//│ if (this.pc === 0) {
145+
//│ this.tmp$0 = runtime.safeCall(h.perform());
146+
//│ if (this.tmp$0 instanceof runtime.EffectSig.class) {
147+
//│ return this.doUnwind(this.tmp$0, 1)
148+
//│ }
149+
//│ this.pc = 1;
150+
//│ continue contLoop;
151+
//│ } else if (this.pc === 1) {
149152
//│ return 1
150153
//│ }
151154
//│ break;
@@ -158,7 +161,7 @@ f() + f() + f()
158161
//│ res.contTrace.last = res.contTrace.last.next;
159162
//│ return res
160163
//│ };
161-
//│ f$ = function f$(h) {
164+
//│ f = function f() {
162165
//│ let tmp1;
163166
//│ tmp1 = runtime.safeCall(h.perform());
164167
//│ if (tmp1 instanceof runtime.EffectSig.class) {
@@ -167,26 +170,43 @@ f() + f() + f()
167170
//│ return 1
168171
//│ };
169172
//│ handleBlock$ = function handleBlock$() {
170-
//│ let h, tmp1, tmp2, tmp3, tmp4;
171-
//│ h = new Handler$h$1();
172-
//│ tmp1 = f$(h);
173+
//│ let tmp1, tmp2, tmp3, tmp4;
174+
//│ tmp1 = f();
173175
//│ if (tmp1 instanceof runtime.EffectSig.class) {
174-
//│ tmp1.contTrace.last.next = Cont$handleBlock$h$$(h, tmp1, tmp2, tmp3, tmp4, 2);
175-
//│ return runtime.handleBlockImpl(tmp1, h)
176+
//│ return doUnwind$1(tmp1, tmp2, tmp3, tmp4, tmp1, 2)
176177
//│ }
177-
//│ tmp2 = f$(h);
178+
//│ tmp2 = f();
178179
//│ if (tmp2 instanceof runtime.EffectSig.class) {
179-
//│ tmp2.contTrace.last.next = Cont$handleBlock$h$$(h, tmp1, tmp2, tmp3, tmp4, 3);
180-
//│ return runtime.handleBlockImpl(tmp2, h)
180+
//│ return doUnwind$1(tmp1, tmp2, tmp3, tmp4, tmp2, 3)
181181
//│ }
182182
//│ tmp3 = tmp1 + tmp2;
183-
//│ tmp4 = f$(h);
183+
//│ tmp4 = f();
184184
//│ if (tmp4 instanceof runtime.EffectSig.class) {
185-
//│ tmp4.contTrace.last.next = Cont$handleBlock$h$$(h, tmp1, tmp2, tmp3, tmp4, 4);
186-
//│ return runtime.handleBlockImpl(tmp4, h)
185+
//│ return doUnwind$1(tmp1, tmp2, tmp3, tmp4, tmp4, 4)
187186
//│ }
188187
//│ return tmp3 + tmp4
189188
//│ };
189+
//│ hdlrFun$ = function hdlrFun$(Handler$h$$instance, k) {
190+
//│ return runtime.safeCall(k())
191+
//│ };
192+
//│ hdlrFun = function hdlrFun(Handler$h$$instance) {
193+
//│ return (k) => {
194+
//│ return hdlrFun$(Handler$h$$instance, k)
195+
//│ }
196+
//│ };
197+
//│ Handler$h$1 = class Handler$h$ extends Effect1 {
198+
//│ constructor() {
199+
//│ let tmp1;
200+
//│ tmp1 = super();
201+
//│ }
202+
//│ perform() {
203+
//│ let hdlrFun$this;
204+
//│ hdlrFun$this = runtime.safeCall(hdlrFun(this));
205+
//│ return runtime.mkEffect(this, hdlrFun$this)
206+
//│ }
207+
//│ toString() { return "Handler$h$"; }
208+
//│ };
209+
//│ h = new Handler$h$1();
190210
//│ tmp = handleBlock$();
191211
//│ if (tmp instanceof runtime.EffectSig.class) {
192212
//│ tmp = runtime.topLevelEffect(tmp, false);
@@ -202,7 +222,7 @@ fun f(x) =
202222
Test()
203223
f(1).get()
204224
//│ JS (unsanitized):
205-
//│ let Test1, f, tmp1, Test$ctor, Test$;
225+
//│ let Test1, f1, tmp1, Test$ctor, Test$;
206226
//│ Test$ = function Test$(x$0) {
207227
//│ let tmp2;
208228
//│ tmp2 = new Test1.class();
@@ -232,10 +252,10 @@ f(1).get()
232252
//│ }
233253
//│ toString() { return "Test(" + "" + ")"; }
234254
//│ };
235-
//│ f = function f(x) {
255+
//│ f1 = function f(x) {
236256
//│ return Test$(x)
237257
//│ };
238-
//│ tmp1 = f(1);
258+
//│ tmp1 = f1(1);
239259
//│ runtime.safeCall(tmp1.get())
240260
//│ = 1
241261

@@ -252,7 +272,7 @@ fun f(used1, unused1) =
252272
Test(unused1)
253273
f(1, 2).get()
254274
//│ JS (unsanitized):
255-
//│ let Test3, f1, tmp2, Test$ctor1, Test$1, g$, h$;
275+
//│ let Test3, f2, tmp2, Test$ctor1, Test$1, g$, h$;
256276
//│ h$ = function h$(used3) {
257277
//│ return used3
258278
//│ };
@@ -292,12 +312,12 @@ f(1, 2).get()
292312
//│ }
293313
//│ toString() { return "Test(" + runtime.render(this.a) + ")"; }
294314
//│ };
295-
//│ f1 = function f(used1, unused1) {
315+
//│ f2 = function f(used1, unused1) {
296316
//│ let unused2;
297317
//│ unused2 = 2;
298318
//│ return Test$1(used1, unused1)
299319
//│ };
300-
//│ tmp2 = f1(1, 2);
320+
//│ tmp2 = f2(1, 2);
301321
//│ runtime.safeCall(tmp2.get())
302322
//│ = 1
303323

@@ -327,7 +347,7 @@ fun f(used1, unused1) =
327347
new Test
328348
f(1, 2).get()
329349
//│ JS (unsanitized):
330-
//│ let Test7, f3, tmp4, Test$ctor3, Test$3, g$2, h$2;
350+
//│ let Test7, f4, tmp4, Test$ctor3, Test$3, g$2, h$2;
331351
//│ h$2 = function h$(used3) {
332352
//│ return used3
333353
//│ };
@@ -364,12 +384,12 @@ f(1, 2).get()
364384
//│ }
365385
//│ toString() { return "Test"; }
366386
//│ };
367-
//│ f3 = function f(used1, unused1) {
387+
//│ f4 = function f(used1, unused1) {
368388
//│ let unused2;
369389
//│ unused2 = 2;
370390
//│ return Test$3(used1)
371391
//│ };
372-
//│ tmp4 = f3(1, 2);
392+
//│ tmp4 = f4(1, 2);
373393
//│ runtime.safeCall(tmp4.get())
374394
//│ = 1
375395

@@ -382,7 +402,7 @@ fun f(x) =
382402
x
383403
f(1)
384404
//│ JS (unsanitized):
385-
//│ let A1, f4, A$ctor, A$, f$capture1;
405+
//│ let A1, f5, A$ctor, A$, f$capture1;
386406
//│ A$ = function A$(f$capture$0) {
387407
//│ let tmp5;
388408
//│ tmp5 = new A1.class();
@@ -422,14 +442,14 @@ f(1)
422442
//│ }
423443
//│ toString() { return "f$capture(" + runtime.render(this.x0$) + ")"; }
424444
//│ };
425-
//│ f4 = function f(x) {
445+
//│ f5 = function f(x) {
426446
//│ let tmp5, tmp6, capture;
427447
//│ capture = new f$capture1(x);
428448
//│ tmp5 = A$(capture);
429449
//│ tmp6 = runtime.safeCall(tmp5.f());
430450
//│ return capture.x0$
431451
//│ };
432-
//│ f4(1)
452+
//│ f5(1)
433453
//│ = 2
434454

435455
// only w should be in a capture
@@ -451,7 +471,7 @@ fun f() =
451471
Good()
452472
f().foo()
453473
//│ JS (unsanitized):
454-
//│ let Bad1, Good1, f5, tmp5, Bad$ctor, Bad$, Good$ctor, Good$, f$capture3;
474+
//│ let Bad1, Good1, f6, tmp5, Bad$ctor, Bad$, Good$ctor, Good$, f$capture3;
455475
//│ Good$ = function Good$(x$1, y$2, z$3, f$capture$0) {
456476
//│ let tmp6;
457477
//│ tmp6 = new Good1.class();
@@ -527,7 +547,7 @@ f().foo()
527547
//│ }
528548
//│ toString() { return "f$capture(" + runtime.render(this.w0$) + ")"; }
529549
//│ };
530-
//│ f5 = function f() {
550+
//│ f6 = function f() {
531551
//│ let x, y, z, tmp6, tmp7, capture;
532552
//│ capture = new f$capture3(null);
533553
//│ x = 1;
@@ -538,7 +558,7 @@ f().foo()
538558
//│ tmp7 = runtime.safeCall(tmp6.foo());
539559
//│ return Good$(x, y, z, capture)
540560
//│ };
541-
//│ tmp5 = f5();
561+
//│ tmp5 = f6();
542562
//│ runtime.safeCall(tmp5.foo())
543563
//│ = 10111
544564

@@ -596,11 +616,11 @@ fun f(x) =
596616
f(2).get()
597617
//│ ═══[WARNING] Cannot yet lift class `Test` as it is used as a first-class class.
598618
//│ JS (unsanitized):
599-
//│ let f8, tmp11, h$3;
619+
//│ let f9, tmp11, h$3;
600620
//│ h$3 = function h$(Test$instance, x) {
601621
//│ return x
602622
//│ };
603-
//│ f8 = function f(x) {
623+
//│ f9 = function f(x) {
604624
//│ let Test10, foo;
605625
//│ Test10 = function Test() {
606626
//│ return new Test.class();
@@ -615,7 +635,7 @@ f(2).get()
615635
//│ foo = Test10;
616636
//│ return runtime.safeCall(foo())
617637
//│ };
618-
//│ tmp11 = f8(2);
638+
//│ tmp11 = f9(2);
619639
//│ runtime.safeCall(tmp11.get())
620640
//│ ═══[WARNING] Cannot yet lift class `Test` as it is used as a first-class class.
621641
//│ = 2

0 commit comments

Comments
 (0)