|
9 | 9 | :todo
|
10 | 10 |
|
11 | 11 |
|
| 12 | +:effectHandlers |
| 13 | +:sjs |
| 14 | +fun f(x) = f(x) - 1 |
| 15 | +//│ Elab: ( ‹› fun member:f‹689›(Param(‹›,x‹691›,None), ) = builtin:-‹16›#0(member:f‹689›#666(x‹691›#666), 1); ) |
| 16 | +//│ JS (unsanitized): |
| 17 | +//│ let f; |
| 18 | +//│ f = function f(x) { |
| 19 | +//│ let tmp, Cont$func$f$1; |
| 20 | +//│ Cont$func$f$1 = function Cont$func$f$(pc1) { |
| 21 | +//│ return new Cont$func$f$.class(pc1); |
| 22 | +//│ }; |
| 23 | +//│ Cont$func$f$1.class = class Cont$func$f$ extends runtime.FunctionContFrame.class { |
| 24 | +//│ constructor(pc) { |
| 25 | +//│ let tmp1; |
| 26 | +//│ tmp1 = super(null); |
| 27 | +//│ this.pc = pc; |
| 28 | +//│ } |
| 29 | +//│ resume(value$) { |
| 30 | +//│ if (this.pc === 0) { |
| 31 | +//│ tmp = value$; |
| 32 | +//│ } |
| 33 | +//│ contLoop: while (true) { |
| 34 | +//│ if (this.pc === 1) { |
| 35 | +//│ tmp = f(x); |
| 36 | +//│ if (tmp instanceof runtime.EffectSig.class) { |
| 37 | +//│ this.pc = 0; |
| 38 | +//│ tmp.contTrace.last.next = this; |
| 39 | +//│ tmp.contTrace.last = this; |
| 40 | +//│ return tmp |
| 41 | +//│ } |
| 42 | +//│ this.pc = 0; |
| 43 | +//│ continue contLoop; |
| 44 | +//│ } else if (this.pc === 0) { |
| 45 | +//│ return tmp - 1 |
| 46 | +//│ } |
| 47 | +//│ break; |
| 48 | +//│ } |
| 49 | +//│ } |
| 50 | +//│ toString() { return "Cont$func$f$(" + globalThis.Predef.render(this.pc) + ")"; } |
| 51 | +//│ }; |
| 52 | +//│ tmp = f(x); |
| 53 | +//│ if (tmp instanceof runtime.EffectSig.class) { |
| 54 | +//│ tmp.contTrace.last.next = new Cont$func$f$1.class(0); |
| 55 | +//│ tmp.contTrace.last = tmp.contTrace.last.next; |
| 56 | +//│ return tmp |
| 57 | +//│ } |
| 58 | +//│ return tmp - 1 |
| 59 | +//│ }; |
12 | 60 |
|
| 61 | +:effectHandlers |
| 62 | +:sjs |
| 63 | +handle h = Object with |
| 64 | + fun test(x)(r) = x |
| 65 | +h.test(2) |
| 66 | +//│ Elab: ( handle h‹748› = Ref(member:Object‹61›)() List(HandlerTermDefinition(r‹755›,TermDefinition(Some(class:Handler$h$‹749›),Fun,member:test‹752›,List(ParamList(‹›,List(Param(‹›,x‹754›,None)),None)),None,None,Some(Ref(x‹754›)),‹result of member:test‹752››‹756›,‹›,List()))) in App(Sel(Ref(h‹748›),Ident(test)),Tup(List(Fld(‹›,Lit(IntLit(2)),None)))) ) |
| 67 | +//│ JS (unsanitized): |
| 68 | +//│ let tmp, handleBlock$; |
| 69 | +//│ handleBlock$ = function handleBlock$() { |
| 70 | +//│ let h, res, Cont$handleBlock$h$1, Handler$h$1; |
| 71 | +//│ Handler$h$1 = class Handler$h$ extends globalThis.Object { |
| 72 | +//│ constructor() { |
| 73 | +//│ let tmp1; |
| 74 | +//│ tmp1 = super(); |
| 75 | +//│ } |
| 76 | +//│ test(x) { |
| 77 | +//│ return runtime.mkEffect(this, (r) => { |
| 78 | +//│ return x |
| 79 | +//│ }) |
| 80 | +//│ } |
| 81 | +//│ toString() { return "Handler$h$"; } |
| 82 | +//│ }; |
| 83 | +//│ h = new Handler$h$1(); |
| 84 | +//│ Cont$handleBlock$h$1 = function Cont$handleBlock$h$(pc1) { |
| 85 | +//│ return new Cont$handleBlock$h$.class(pc1); |
| 86 | +//│ }; |
| 87 | +//│ Cont$handleBlock$h$1.class = class Cont$handleBlock$h$ extends runtime.FunctionContFrame.class { |
| 88 | +//│ constructor(pc) { |
| 89 | +//│ let tmp1; |
| 90 | +//│ tmp1 = super(null); |
| 91 | +//│ this.pc = pc; |
| 92 | +//│ } |
| 93 | +//│ resume(value$) { |
| 94 | +//│ if (this.pc === 0) { |
| 95 | +//│ res = value$; |
| 96 | +//│ } |
| 97 | +//│ contLoop: while (true) { |
| 98 | +//│ if (this.pc === 1) { |
| 99 | +//│ res = runtime.safeCall(h.test(2)); |
| 100 | +//│ if (res instanceof runtime.EffectSig.class) { |
| 101 | +//│ this.pc = 0; |
| 102 | +//│ res.contTrace.last.next = this; |
| 103 | +//│ res.contTrace.last = this; |
| 104 | +//│ return res |
| 105 | +//│ } |
| 106 | +//│ this.pc = 0; |
| 107 | +//│ continue contLoop; |
| 108 | +//│ } else if (this.pc === 0) { |
| 109 | +//│ return res |
| 110 | +//│ } |
| 111 | +//│ break; |
| 112 | +//│ } |
| 113 | +//│ } |
| 114 | +//│ toString() { return "Cont$handleBlock$h$(" + globalThis.Predef.render(this.pc) + ")"; } |
| 115 | +//│ }; |
| 116 | +//│ res = runtime.safeCall(h.test(2)); |
| 117 | +//│ if (res instanceof runtime.EffectSig.class) { |
| 118 | +//│ res.contTrace.last.next = Cont$handleBlock$h$1(0); |
| 119 | +//│ return runtime.handleBlockImpl(res, h) |
| 120 | +//│ } |
| 121 | +//│ return res |
| 122 | +//│ }; |
| 123 | +//│ tmp = handleBlock$(); |
| 124 | +//│ if (tmp instanceof runtime.EffectSig.class) { |
| 125 | +//│ tmp = runtime.topLevelEffect(tmp, false); |
| 126 | +//│ } |
| 127 | +//│ tmp |
| 128 | +//│ = 2 |
0 commit comments