about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc51
-rw-r--r--mu.arc.t44
2 files changed, 69 insertions, 26 deletions
diff --git a/mu.arc b/mu.arc
index 988c711f..545102fc 100644
--- a/mu.arc
+++ b/mu.arc
@@ -442,6 +442,9 @@
       (trace "run" "-- " int-canon.memory*)
       (trace "run" curr-cycle* " " top.routine*!fn-name " " pc.routine* ": " (body.routine* pc.routine*))
 ;?       (trace "run" routine*)
+      (when (atom (body.routine* pc.routine*))  ; label
+        (++ pc.routine*)
+        (continue))
       (let (oarg op arg)  (parse-instr (body.routine* pc.routine*))
         (let results
               (case op
@@ -676,18 +679,19 @@
     (let pc 0
       (loop (instrs instrs)
         (each instr instrs
-          (if (~is 'begin instr.0)
-            (do
-              (trace "c{0" pc " " instr " -- " locs)
-              (++ pc))
-            ; hack: racket replaces curlies with parens, so we need the
-            ; keyword begin to delimit blocks.
-            ; ultimately there'll be no nesting and curlies will just be in a
-            ; line by themselves.
-            (do
-              (push `(open ,pc) locs)
-              (recur cdr.instr)
-              (push `(close ,pc) locs))))))
+          (if (or atom.instr (~is 'begin instr.0))  ; label or regular instruction
+                (do
+                  (trace "c{0" pc " " instr " -- " locs)
+                  (++ pc))
+                ; hack: racket replaces curlies with parens, so we need the
+                ; keyword begin to delimit blocks.
+                ; ultimately there'll be no nesting and curlies will just be in a
+                ; line by themselves.
+              :else  ; brace
+                (do
+                  (push `(open ,pc) locs)
+                  (recur cdr.instr)
+                  (push `(close ,pc) locs))))))
     (zap rev locs)
     (with (pc  0
            stack  ())  ; elems are pcs
@@ -695,6 +699,9 @@
         (loop (instrs instrs)
           (each instr instrs
             (point continue
+            (when (atom instr)  ; label
+              (yield instr)
+              (continue))
             (let delim (or (pos '<- instr) -1)
               (with (oarg  (if (>= delim 0)
                              (cut instr 0 delim))
@@ -767,6 +774,9 @@
          isa-field  (table))
     (let idx 1
       (each instr instrs
+        (point continue
+        (when atom.instr
+          (continue))
         (trace "cn0" instr " " canon.location " " canon.isa-field)
         (let (oargs op args)  (parse-instr instr)
           (if (in op 'get 'get-address)
@@ -799,16 +809,17 @@
               (assert (~isa-field v.arg) "oarg @arg is also a field name")
               (when (maybe-add arg location idx)
                 (trace "cn0" "location for arg " arg ": " idx)
-                (++ idx (sizeof ty.arg))))))))
+                (++ idx (sizeof ty.arg)))))))))
     (trace "cn1" "update names " canon.location " " canon.isa-field)
     (each instr instrs
-      (let (oargs op args)  (parse-instr instr)
-        (each arg args
-          (when (and nondummy.arg (location v.arg))
-            (zap location v.arg)))
-        (each arg oargs
-          (when (and nondummy.arg (location v.arg))
-            (zap location v.arg)))))
+      (when (acons instr)
+        (let (oargs op args)  (parse-instr instr)
+          (each arg args
+            (when (and nondummy.arg (location v.arg))
+              (zap location v.arg)))
+          (each arg oargs
+            (when (and nondummy.arg (location v.arg))
+              (zap location v.arg))))))
     instrs))
 
 (def maybe-add (arg location idx)
diff --git a/mu.arc.t b/mu.arc.t
index eb51b4c6..975afe7d 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1229,6 +1229,34 @@
   (prn "F - convert-braces balances curlies when converting continue"))
 
 (reset)
+(new-trace "convert-braces-label")
+(if (~iso (convert-braces
+            '(((1 integer) <- copy (4 literal))
+              foo
+              ((2 integer) <- copy (2 literal))))
+          '(((1 integer) <- copy (4 literal))
+            foo
+            ((2 integer) <- copy (2 literal))))
+  (prn "F - convert-braces skips past labels"))
+;? (quit)
+
+(reset)
+(new-trace "convert-braces-label-increments-offset")
+(if (~iso (convert-braces
+            '(((1 integer) <- copy (4 literal))
+              { begin
+                (break)
+                foo
+              }
+              ((2 integer) <- copy (2 literal))))
+          '(((1 integer) <- copy (4 literal))
+            (jump (1 offset))
+            foo
+            ((2 integer) <- copy (2 literal))))
+  (prn "F - convert-braces skips past labels"))
+;? (quit)
+
+(reset)
 (new-trace "continue")
 ;? (set dump-trace*)
 (add-fns
@@ -1393,6 +1421,16 @@
   (prn "F - convert-names replaces field offsets with multiple mentions"))
 ;? (quit)
 
+(reset)
+(new-trace "convert-names-label")
+(if (~iso (convert-names
+            '(((1 integer) <- copy (4 literal))
+              foo))
+          '(((1 integer) <- copy (4 literal))
+            foo))
+  (prn "F - convert-names skips past labels"))
+;? (quit)
+
 ; A rudimentary memory allocator. Eventually we want to write this in mu.
 ;
 ; No deallocation yet; let's see how much code we can build in mu before we
@@ -2344,12 +2382,6 @@
   (prn "F - channels are meant to be shared between routines"))
 ;? (quit)
 
-;? (reset)
-;? (new-trace "channel-race")
-;? (add-fns
-;?   '((reader
-;?       ((
-
 ;; Separating concerns
 ;
 ; Lightweight tools can also operate on quoted lists of statements surrounded