diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-23 06:06:04 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-23 06:11:38 -0800 |
commit | 019444d597088bfbfe64a3346303d824216829d9 (patch) | |
tree | b66b0177c4ce2190a6f69e5d0ca1e2db995a836d | |
parent | 1ced22ded92c30794a47c208f281f2849ae28a59 (diff) | |
download | mu-019444d597088bfbfe64a3346303d824216829d9.tar.gz |
300 - missed a spot
Also uncovered a bug in convert-braces, which helps see a simpler close-offset. Instead of all that crap with first incrementing then waiting for counter to return to 0, just wait for counter to go to -1.
-rw-r--r-- | mu.arc | 13 | ||||
-rw-r--r-- | mu.arc.t | 54 |
2 files changed, 61 insertions, 6 deletions
diff --git a/mu.arc b/mu.arc index 545102fc..b874bee1 100644 --- a/mu.arc +++ b/mu.arc @@ -701,6 +701,7 @@ (point continue (when (atom instr) ; label (yield instr) + (++ pc) (continue)) (let delim (or (pos '<- instr) -1) (with (oarg (if (>= delim 0) @@ -749,20 +750,22 @@ (++ pc)))))))) (def close-offset (pc locs) +;? (tr "close " pc " " locs) (let close 0 (with (stacksize 0 done nil) (each (state loc) locs - (if (< loc pc) +;? (tr stacksize "/" done " " state " " loc) + (if (<= loc pc) nil ; do nothing (no done) (do - ; first time - (when (and (is 0 stacksize) (~is loc pc)) - (++ stacksize)) +;? (tr "process " stacksize loc) (if (is 'open state) (++ stacksize) (-- stacksize)) ; last time - (when (is 0 stacksize) +;? (tr "process2 " stacksize loc) + (when (is -1 stacksize) +;? (tr "close now " loc) (= close loc) (set done)))))) (- close pc 1))) diff --git a/mu.arc.t b/mu.arc.t index 975afe7d..d010e415 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -1146,6 +1146,7 @@ (reset) (new-trace "convert-braces") +;? (= dump-trace* (obj whitelist '("c{0" "c{1"))) (if (~iso (convert-braces '(((1 integer) <- copy (4 literal)) ((2 integer) <- copy (2 literal)) @@ -1164,9 +1165,11 @@ ((5 integer) <- copy (34 literal)) (reply))) (prn "F - convert-braces replaces break-if with a jump-if to after the next close-curly")) +;? (quit) (reset) (new-trace "convert-braces-empty-block") +;? (= dump-trace* (obj whitelist '("c{0" "c{1"))) (if (~iso (convert-braces '(((1 integer) <- copy (4 literal)) ((2 integer) <- copy (2 literal)) @@ -1181,6 +1184,7 @@ (jump (0 offset)) (reply))) (prn "F - convert-braces works for degenerate blocks")) +;? (quit) (reset) (new-trace "convert-braces-nested-break") @@ -1206,6 +1210,29 @@ (prn "F - convert-braces balances curlies when converting break")) (reset) +(new-trace "convert-braces-repeated-jump") +;? (= dump-trace* (obj whitelist '("c{0" "c{1"))) +(if (~iso (convert-braces + '(((1 integer) <- copy (4 literal)) + { begin + (break) + ((2 integer) <- copy (5 literal)) + } + { begin + (break) + ((3 integer) <- copy (6 literal)) + } + ((4 integer) <- copy (7 literal)))) + '(((1 integer) <- copy (4 literal)) + (jump (1 offset)) + ((2 integer) <- copy (5 literal)) + (jump (1 offset)) + ((3 integer) <- copy (6 literal)) + ((4 integer) <- copy (7 literal)))) + (prn "F - convert-braces handles jumps on jumps")) +;? (quit) + +(reset) (new-trace "convert-braces-nested-continue") (if (~iso (convert-braces '(((1 integer) <- copy (4 literal)) @@ -1253,7 +1280,32 @@ (jump (1 offset)) foo ((2 integer) <- copy (2 literal)))) - (prn "F - convert-braces skips past labels")) + (prn "F - convert-braces treats labels as instructions")) +;? (quit) + +(reset) +(new-trace "convert-braces-label-increments-offset2") +;? (= dump-trace* (obj whitelist '("c{0" "c{1"))) +(if (~iso (convert-braces + '(((1 integer) <- copy (4 literal)) + { begin + (break) + foo + } + ((2 integer) <- copy (5 literal)) + { begin + (break) + ((3 integer) <- copy (6 literal)) + } + ((4 integer) <- copy (7 literal)))) + '(((1 integer) <- copy (4 literal)) + (jump (1 offset)) + foo + ((2 integer) <- copy (5 literal)) + (jump (1 offset)) + ((3 integer) <- copy (6 literal)) + ((4 integer) <- copy (7 literal)))) + (prn "F - convert-braces treats labels as instructions - 2")) ;? (quit) (reset) |