diff --git a/co_lc/test/add.co b/co_lc/test/add.co index 3a1a2ee..145e7e3 100644 --- a/co_lc/test/add.co +++ b/co_lc/test/add.co @@ -5,13 +5,12 @@ > +ir -print > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > push 34 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/call.co b/co_lc/test/call.co index ab136f6..e42ec5d 100644 --- a/co_lc/test/call.co +++ b/co_lc/test/call.co @@ -8,65 +8,61 @@ addTo5AndDouble 10 > +ir -print > plus5: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 m -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 m +> % -2 @old_pc +> % -1 @old_fp > plus5: > push 5 -> push fp[-4] +> push fp[-3] > add -> store-into fp[-5] +> store-into fp[-4] > ret > } > > addTo5AndDouble: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n1 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n1 +> % -2 @old_pc +> % -1 @old_fp > addTo5AndDouble: > sp-add 1 > sp-add 1 -> push fp[-4] +> push fp[-3] > call plus5 > sp-sub 1 > call double > sp-sub 1 -> store-into fp[-5] +> store-into fp[-4] > ret > } > > double: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > double: > push 2 -> push fp[-4] +> push fp[-3] > mul -> store-into fp[-5] +> store-into fp[-4] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > sp-add 1 > push 10 > call addTo5AndDouble > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/closure.co b/co_lc/test/closure.co index c8be559..84bdb1a 100644 --- a/co_lc/test/closure.co +++ b/co_lc/test/closure.co @@ -15,39 +15,36 @@ add 5 6 > +ir -print > lam: { > % Stack relative to frame pointer: -> % -6 #return -> % -5 n -> % -4 m -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -5 #return +> % -4 n +> % -3 m +> % -2 @old_pc +> % -1 @old_fp > lam: -> push fp[-5] > push fp[-4] +> push fp[-3] > add -> store-into fp[-6] +> store-into fp[-5] > ret > } > > add: { > % Stack relative to frame pointer: -> % -5 #return.captures.0 -> % -4 m -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return.captures.0 +> % -3 m +> % -2 @old_pc +> % -1 @old_fp > add: -> push fp[-4] -> store-into fp[-5] +> push fp[-3] +> store-into fp[-4] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > sp-add 1 > push 6 @@ -57,7 +54,7 @@ add 5 6 > sp-sub 1 > call lam > sp-sub 2 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/conditional_dispatch.co b/co_lc/test/conditional_dispatch.co index 27404d1..39c24a7 100644 --- a/co_lc/test/conditional_dispatch.co +++ b/co_lc/test/conditional_dispatch.co @@ -36,124 +36,119 @@ let f3 = (f 3) 2 in > +ir -print > lam1: { > % Stack relative to frame pointer: -> % -8 #return -> % -7 w1 -> % -6 y -> % -5 x -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -7 #return +> % -6 w1 +> % -5 y +> % -4 x +> % -2 @old_pc +> % -1 @old_fp > lam1: -> push fp[-6] > push fp[-5] +> push fp[-4] > add -> push fp[-7] +> push fp[-6] > add -> store-into fp[-8] +> store-into fp[-7] > ret > } > > lam2: { > % Stack relative to frame pointer: -> % -8 #return -> % -7 w2 -> % -6 z -> % -5 y -> % -4 x -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -7 #return +> % -6 w2 +> % -5 z +> % -4 y +> % -3 x +> % -2 @old_pc +> % -1 @old_fp > lam2: -> push fp[-6] > push fp[-5] -> add > push fp[-4] > add -> push fp[-7] +> push fp[-3] > add -> store-into fp[-8] +> push fp[-6] +> add +> store-into fp[-7] > ret > } > > lam: { > % Stack relative to frame pointer: -> % -8 #return -> % -7 w -> % -6 x -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -7 #return +> % -6 w +> % -5 x +> % -2 @old_pc +> % -1 @old_fp > lam: +> push fp[-5] > push fp[-6] -> push fp[-7] > add -> store-into fp[-8] +> store-into fp[-7] > ret > } > > f: { > % Stack relative to frame pointer: -> % -11 #return.captures.0 -> % -10 #return.captures.1 -> % -9 #return.captures.2 -> % -8 #return.lambda_tag -> % -7 n -> % -6 z -> % -5 y -> % -4 x -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -10 #return.captures.0 +> % -9 #return.captures.1 +> % -8 #return.captures.2 +> % -7 #return.lambda_tag +> % -6 n +> % -5 z +> % -4 y +> % -3 x +> % -2 @old_pc +> % -1 @old_fp > f: > push 1 -> push fp[-7] +> push fp[-6] > = > jmpz else > then: -> push fp[-4] -> store-into fp[-11] -> push 0 +> push fp[-3] > store-into fp[-10] > push 0 > store-into fp[-9] > push 0 > store-into fp[-8] +> push 0 +> store-into fp[-7] > ret > else: > push 2 -> push fp[-7] +> push fp[-6] > = > jmpz else1 > then1: -> push fp[-5] -> store-into fp[-11] > push fp[-4] > store-into fp[-10] -> push 0 +> push fp[-3] > store-into fp[-9] -> push 1 +> push 0 > store-into fp[-8] +> push 1 +> store-into fp[-7] > ret > else1: -> push fp[-6] -> store-into fp[-11] > push fp[-5] > store-into fp[-10] > push fp[-4] > store-into fp[-9] -> push 2 +> push fp[-3] > store-into fp[-8] +> push 2 +> store-into fp[-7] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -6 #return.2 -> % -5 #return.1 -> % -4 #return.0 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -5 #return.2 +> % -4 #return.1 +> % -3 #return.0 +> % -2 @old_pc +> % -1 @old_fp > % 0 x > % 1 y > % 2 z @@ -251,11 +246,11 @@ let f3 = (f 3) 2 in > sp-sub 4 > store-into fp[8] > push fp[8] -> store-into fp[-6] -> push fp[7] > store-into fp[-5] -> push fp[6] +> push fp[7] > store-into fp[-4] +> push fp[6] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/fib.co b/co_lc/test/fib.co index 2d480c2..79a3488 100644 --- a/co_lc/test/fib.co +++ b/co_lc/test/fib.co @@ -55,21 +55,20 @@ let result = exec {runFib, 0, 0} in > +ir -print > exec: { > % Stack relative to frame pointer: -> % -15 #return.2 -> % -14 #return.1 -> % -13 #return.0.stkdirty -> % -12 #return.0.stkidx -> % -11 #return.0.return -> % -10 #return.0.bit -> % -9 state.2 -> % -8 state.1 -> % -7 state.0.stkdirty -> % -6 state.0.stkidx -> % -5 state.0.return -> % -4 state.0.bit -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -14 #return.2 +> % -13 #return.1 +> % -12 #return.0.stkdirty +> % -11 #return.0.stkidx +> % -10 #return.0.return +> % -9 #return.0.bit +> % -8 state.2 +> % -7 state.1 +> % -6 state.0.stkdirty +> % -5 state.0.stkidx +> % -4 state.0.return +> % -3 state.0.bit +> % -2 @old_pc +> % -1 @old_fp > % 0 n1 > % 1 fib1.stkdirty > % 2 fib1.stkidx @@ -78,113 +77,110 @@ let result = exec {runFib, 0, 0} in > exec: > sp-add 5 > start2: -> push fp[-7] > push fp[-6] > push fp[-5] > push fp[-4] +> push fp[-3] > jmpz pending > done: > store-into fp[0] > sp-sub 2 -> push fp[-9] -> store-into fp[-15] -> push fp[0] +> push fp[-8] > store-into fp[-14] -> push fp[-7] +> push fp[0] +> store-into fp[-13] > push fp[-6] > push fp[-5] > push fp[-4] +> push fp[-3] +> store-into fp[-9] > store-into fp[-10] > store-into fp[-11] > store-into fp[-12] -> store-into fp[-13] > ret > pending: > sp-sub 3 -> push fp[-7] > push fp[-6] > push fp[-5] > push fp[-4] +> push fp[-3] > resume 1 > store-into fp[4] > store-into fp[3] > store-into fp[2] > store-into fp[1] > push 1 -> push fp[-9] +> push fp[-8] > add -> store-into fp[-9] -> push 0 > store-into fp[-8] +> push 0 +> store-into fp[-7] > push fp[1] > push fp[2] > push fp[3] > push fp[4] +> store-into fp[-3] > store-into fp[-4] > store-into fp[-5] > store-into fp[-6] -> store-into fp[-7] > sp-restore-fp > jmp exec > } > > fib: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > fib: > yield > push 2 -> push fp[-4] +> push fp[-3] > < > jmpz else > then: -> push fp[-4] -> store-into fp[-5] +> push fp[-3] +> store-into fp[-4] > ret > else: > sp-add 1 > push 2 -> push fp[-4] +> push fp[-3] > sub > call fib > sp-sub 1 > sp-add 1 > push 1 -> push fp[-4] +> push fp[-3] > sub > call fib > sp-sub 1 > add -> store-into fp[-5] +> store-into fp[-4] > ret > } > > spawn_wrapper: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > spawn_wrapper: > sp-add 1 > push 20 > call fib > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -5 #return.1 -> % -4 #return.0 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return.1 +> % -3 #return.0 +> % -2 @old_pc +> % -1 @old_fp > % 0 runFib.stkdirty > % 1 runFib.stkidx > % 2 runFib.return @@ -219,9 +215,9 @@ let result = exec {runFib, 0, 0} in > store-into fp[5] > store-into fp[4] > push fp[4] -> store-into fp[-5] -> push fp[5] > store-into fp[-4] +> push fp[5] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/fiber.co b/co_lc/test/fiber.co index 681efdb..47bf9ba 100644 --- a/co_lc/test/fiber.co +++ b/co_lc/test/fiber.co @@ -13,41 +13,38 @@ stat child > +ir -print > child: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > child: > yield > push 5 -> push fp[-4] +> push fp[-3] > add -> store-into fp[-5] +> store-into fp[-4] > ret > } > > spawn_wrapper: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > spawn_wrapper: > sp-add 1 > push 10 > call child > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > % 0 child1.stkdirty > % 1 child1.stkidx > % 2 child1.return @@ -83,12 +80,12 @@ stat child > store-into fp[8] > sp-sub 2 > push fp[8] -> store-into fp[-4] +> store-into fp[-3] > ret > pending: > sp-sub 3 > push 101 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/readback_fiber.co b/co_lc/test/readback_fiber.co index 0140426..d97a8db 100644 --- a/co_lc/test/readback_fiber.co +++ b/co_lc/test/readback_fiber.co @@ -13,5 +13,5 @@ let f2 = spawn (child2 (x + y)) in {f1, f2} > +eval -print -> {Fiber {int; int} (`Done {30, 35}), +> {Fiber {int; int} (`Done {10, 20}), > Fiber {int; int} `Pending} \ No newline at end of file diff --git a/co_lc/test/recursive_call_factorial.co b/co_lc/test/recursive_call_factorial.co index ac857db..df68941 100644 --- a/co_lc/test/recursive_call_factorial.co +++ b/co_lc/test/recursive_call_factorial.co @@ -10,45 +10,43 @@ fact 10 > +ir -print > fact: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > fact: > push 1 -> push fp[-4] +> push fp[-3] > < > jmpz else > then: > push 1 -> store-into fp[-5] +> store-into fp[-4] > ret > else: > sp-add 1 > push 1 -> push fp[-4] +> push fp[-3] > sub > call fact > sp-sub 1 -> push fp[-4] +> push fp[-3] > mul -> store-into fp[-5] +> store-into fp[-4] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > sp-add 1 > push 10 > call fact > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/recursive_call_fibonacci.co b/co_lc/test/recursive_call_fibonacci.co index 66675e3..4786298 100644 --- a/co_lc/test/recursive_call_fibonacci.co +++ b/co_lc/test/recursive_call_fibonacci.co @@ -10,50 +10,48 @@ fib 28 > +ir -print > fib: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > fib: > push 2 -> push fp[-4] +> push fp[-3] > < > jmpz else > then: -> push fp[-4] -> store-into fp[-5] +> push fp[-3] +> store-into fp[-4] > ret > else: > sp-add 1 > push 2 -> push fp[-4] +> push fp[-3] > sub > call fib > sp-sub 1 > sp-add 1 > push 1 -> push fp[-4] +> push fp[-3] > sub > call fib > sp-sub 1 > add -> store-into fp[-5] +> store-into fp[-4] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > sp-add 1 > push 28 > call fib > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/recursive_closure.co b/co_lc/test/recursive_closure.co index b4a5b33..ec84cb8 100644 --- a/co_lc/test/recursive_closure.co +++ b/co_lc/test/recursive_closure.co @@ -22,42 +22,40 @@ incTo 7 > +ir -print > incTo: { > % Stack relative to frame pointer: -> % -6 #return -> % -5 n -> % -4 inc -> % -4 incTo.captures.0 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -5 #return +> % -4 n +> % -3 inc +> % -3 incTo.captures.0 +> % -2 @old_pc +> % -1 @old_fp > incTo: > push 0 -> push fp[-5] +> push fp[-4] > = > jmpz else > then: > push 0 -> store-into fp[-6] +> store-into fp[-5] > ret > else: > sp-add 1 > push 1 -> push fp[-5] -> sub > push fp[-4] +> sub +> push fp[-3] > call incTo > sp-sub 2 -> push fp[-4] +> push fp[-3] > add -> store-into fp[-6] +> store-into fp[-5] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > % 0 inc > % 1 incTo.captures.0 > @main: @@ -72,7 +70,7 @@ incTo 7 > push fp[1] > call incTo > sp-sub 2 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/resume_repeated.co b/co_lc/test/resume_repeated.co index 404dc20..67e045a 100644 --- a/co_lc/test/resume_repeated.co +++ b/co_lc/test/resume_repeated.co @@ -23,51 +23,49 @@ exec child > +ir -print > exec: { > % Stack relative to frame pointer: -> % -8 #return -> % -7 fiber.stkdirty -> % -6 fiber.stkidx -> % -5 fiber.return -> % -4 fiber.bit -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -7 #return +> % -6 fiber.stkdirty +> % -5 fiber.stkidx +> % -4 fiber.return +> % -3 fiber.bit +> % -2 @old_pc +> % -1 @old_fp > % 0 n5 > exec: > sp-add 1 > start2: -> push fp[-7] > push fp[-6] > push fp[-5] > push fp[-4] +> push fp[-3] > jmpz pending > done: > store-into fp[0] > sp-sub 2 > push fp[0] -> store-into fp[-8] +> store-into fp[-7] > ret > pending: > sp-sub 3 -> push fp[-7] > push fp[-6] > push fp[-5] > push fp[-4] +> push fp[-3] > resume 1 +> store-into fp[-3] > store-into fp[-4] > store-into fp[-5] > store-into fp[-6] -> store-into fp[-7] > sp-restore-fp > jmp exec > } > > child: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > % 0 n1 > % 1 n2 > % 2 n3 @@ -77,7 +75,7 @@ exec child > start1: > yield > push 1 -> push fp[-4] +> push fp[-3] > add > store-into fp[0] > yield @@ -97,31 +95,29 @@ exec child > store-into fp[3] > yield > push fp[3] -> store-into fp[-5] +> store-into fp[-4] > ret > } > > spawn_wrapper: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > spawn_wrapper: > sp-add 1 > push 10 > call child > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > % 0 child1.stkdirty > % 1 child1.stkidx > % 2 child1.return @@ -141,7 +137,7 @@ exec child > push fp[3] > call exec > sp-sub 4 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/spawn_capturing.co b/co_lc/test/spawn_capturing.co index 0ac5a38..754aedc 100644 --- a/co_lc/test/spawn_capturing.co +++ b/co_lc/test/spawn_capturing.co @@ -14,44 +14,41 @@ stat child > +ir -print > child: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > child: > push 5 -> push fp[-4] +> push fp[-3] > add -> store-into fp[-5] +> store-into fp[-4] > ret > } > > spawn_wrapper: { > % Stack relative to frame pointer: -> % -6 #return -> % -5 y -> % -4 x -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -5 #return +> % -4 y +> % -3 x +> % -2 @old_pc +> % -1 @old_fp > spawn_wrapper: > sp-add 1 -> push fp[-5] > push fp[-4] +> push fp[-3] > add > call child > sp-sub 1 -> store-into fp[-6] +> store-into fp[-5] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > % 0 x > % 1 y > % 2 child1.stkdirty @@ -82,14 +79,14 @@ stat child > store-into fp[6] > sp-sub 2 > push fp[6] -> store-into fp[-4] +> store-into fp[-3] > ret > pending: > sp-sub 3 > push 101 -> store-into fp[-4] +> store-into fp[-3] > ret > } > +eval -print -> 35 \ No newline at end of file +> 10 \ No newline at end of file diff --git a/co_lc/test/sub.co b/co_lc/test/sub.co index a36329b..833ea45 100644 --- a/co_lc/test/sub.co +++ b/co_lc/test/sub.co @@ -5,13 +5,12 @@ > +ir -print > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > push 8 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/tco.co b/co_lc/test/tco.co index 8c963f5..852a1c2 100644 --- a/co_lc/test/tco.co +++ b/co_lc/test/tco.co @@ -11,63 +11,60 @@ in fact 10 > +ir -print > inner: { > % Stack relative to frame pointer: -> % -6 #return -> % -5 t.1 -> % -4 t.0 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -5 #return +> % -4 t.1 +> % -3 t.0 +> % -2 @old_pc +> % -1 @old_fp > inner: > push 0 -> push fp[-4] +> push fp[-3] > = > jmpz else > then: -> push fp[-5] -> store-into fp[-6] +> push fp[-4] +> store-into fp[-5] > ret > else: +> push fp[-3] > push fp[-4] -> push fp[-5] > mul -> store-into fp[-5] +> store-into fp[-4] > push 1 -> push fp[-4] +> push fp[-3] > sub -> store-into fp[-4] +> store-into fp[-3] > sp-restore-fp > jmp inner > } > > fact: { > % Stack relative to frame pointer: -> % -5 #return -> % -4 n -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -4 #return +> % -3 n +> % -2 @old_pc +> % -1 @old_fp > fact: > sp-add 1 > push 1 -> push fp[-4] +> push fp[-3] > call inner > sp-sub 2 -> store-into fp[-5] +> store-into fp[-4] > ret > } > > @main: { > % Stack relative to frame pointer: -> % -4 #return -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -3 #return +> % -2 @old_pc +> % -1 @old_fp > @main: > sp-add 1 > push 10 > call fact > sp-sub 1 -> store-into fp[-4] +> store-into fp[-3] > ret > } diff --git a/co_lc/test/tuple.co b/co_lc/test/tuple.co index eb1facd..ce5a5cb 100644 --- a/co_lc/test/tuple.co +++ b/co_lc/test/tuple.co @@ -6,17 +6,16 @@ let t = {1, {2, 3, {4, 5}, 6}, 7, 8} in > +ir -print > @main: { > % Stack relative to frame pointer: -> % -11 #return.7 -> % -10 #return.6 -> % -9 #return.5 -> % -8 #return.4 -> % -7 #return.3 -> % -6 #return.2 -> % -5 #return.1 -> % -4 #return.0 -> % -3 @old_pc -> % -2 @old_fp -> % -1 @old_sp +> % -10 #return.7 +> % -9 #return.6 +> % -8 #return.5 +> % -7 #return.4 +> % -6 #return.3 +> % -5 #return.2 +> % -4 #return.1 +> % -3 #return.0 +> % -2 @old_pc +> % -1 @old_fp > % 0 t.3 > % 1 t.2 > % 2 t.1.3 @@ -45,21 +44,21 @@ let t = {1, {2, 3, {4, 5}, 6}, 7, 8} in > push 1 > store-into fp[7] > push fp[0] -> store-into fp[-11] -> push fp[1] > store-into fp[-10] -> push fp[2] +> push fp[1] > store-into fp[-9] -> push fp[3] +> push fp[2] > store-into fp[-8] -> push fp[4] +> push fp[3] > store-into fp[-7] -> push fp[5] +> push fp[4] > store-into fp[-6] -> push fp[6] +> push fp[5] > store-into fp[-5] -> push fp[7] +> push fp[6] > store-into fp[-4] +> push fp[7] +> store-into fp[-3] > ret > } diff --git a/co_lc/vm_conv.ml b/co_lc/vm_conv.ml index a1e135f..302e08c 100644 --- a/co_lc/vm_conv.ml +++ b/co_lc/vm_conv.ml @@ -19,7 +19,6 @@ --- < stack top on call old_pc old_fp - old_sp --- < new frame pointer = new stack pointer on enter *) @@ -194,14 +193,13 @@ module Ctx = struct --- old_pc old_fp - old_sp --- < new frame pointer = new stack pointer - so, the arg starts at at fp[-3 - closure_stksize - argstksize] + so, the arg starts at at fp[-2 - closure_stksize - argstksize] *) let depth = current_depth c in let arg_stksize = stack_size arg_ty in - let captures_offset = -3 - closure_stksize in + let captures_offset = -2 - closure_stksize in let _off = List.fold_left @@ -212,7 +210,7 @@ module Ctx = struct @@ List.rev captures in - let arg_offset = -3 - closure_stksize - arg_stksize in + let arg_offset = -2 - closure_stksize - arg_stksize in c.names <- (arg_name, (depth, arg_ty, `FpOffset arg_offset)) :: c.names; (* add a local for the return value *) diff --git a/co_lc/vm_debug.ml b/co_lc/vm_debug.ml index c4d06e8..e79801e 100644 --- a/co_lc/vm_debug.ml +++ b/co_lc/vm_debug.ml @@ -62,9 +62,8 @@ let fill_out (offset, (x, ty)) = let pp_debug_frame symbols f { locals } = let locals = - (`Sym "@old_pc", (T.int, `FpOffset (-3))) - :: (`Sym "@old_fp", (T.int, `FpOffset (-2))) - :: (`Sym "@old_sp", (T.int, `FpOffset (-1))) + (`Sym "@old_pc", (T.int, `FpOffset (-2))) + :: (`Sym "@old_fp", (T.int, `FpOffset (-1))) :: locals in let by_offset = diff --git a/co_lc/vm_fiber.ml b/co_lc/vm_fiber.ml index ebf18ee..60b2296 100644 --- a/co_lc/vm_fiber.ml +++ b/co_lc/vm_fiber.ml @@ -83,14 +83,12 @@ let make ~ret ~arg = args (block) END_pc END_fp - END_sp --- current frame *) Stack.extend stack (Array.make ret debug_word); let top = Stack.len stack in Stack.extend stack arg; Stack.push stack 0; - Stack.push stack 0; Stack.push stack top; let fp = Stack.len stack in { stack; fp = ref fp; top = ref top } @@ -135,13 +133,10 @@ let setup_new_frame fiber ~pc = ...args (set elsewhere) old_pc old_fp - old_sp --- new frame *) - let old_sp = Stack.len fiber.stack in push_int fiber pc; push_int fiber !(fiber.fp); - push_int fiber old_sp; fiber.fp := Stack.len fiber.stack let reset_to_fp { stack; fp; _ } = Stack.truncate stack !fp @@ -152,15 +147,12 @@ let restore_old_frame fiber = --- wanted result old_pc old_fp - old_sp --- current frame *) - let old_sp = pop_int fiber in let old_fp = pop_int fiber in let old_pc = pop_int fiber in - Stack.truncate fiber.stack old_sp; fiber.fp := old_fp; - if old_sp = !(fiber.top) then + if old_fp = !(fiber.top) then let ret_val = Stack.splice_off fiber.stack !(fiber.top) in `Done ret_val else `Pc old_pc