about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc18
-rw-r--r--mu.arc.t13
2 files changed, 31 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index 795a320a..b9c3c3fe 100644
--- a/mu.arc
+++ b/mu.arc
@@ -640,6 +640,24 @@
               (~isa v.arg 'sym))
     (= (offset v.arg) idx)))
 
+;; literate tangling system for reordering code
+
+(def convert-quotes (instrs)
+  (let deferred (queue)
+    (each instr instrs
+      (case instr.0
+        defer
+          (let (q qinstrs)  instr.1
+            (assert (is 'make-br-fn q))
+            (each qinstr qinstrs
+              (enq qinstr deferred)))))
+    (accum yield
+      (each instr instrs
+        (unless (in instr.0 'defer)  ; keep sync'd with case clauses above
+          (yield instr)))
+      (each instr (as cons deferred)
+        (yield instr)))))
+
 ;; system software
 
 (init-fn maybe-coerce
diff --git a/mu.arc.t b/mu.arc.t
index 63445058..5165f77e 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1353,4 +1353,17 @@
             ((3 integer) <- add (1 integer) (2 integer))))
   (prn "F - convert-names renames symbolic names to integer offsets"))
 
+(reset)
+(new-trace "convert-quotes-defer")
+(if (~iso (convert-quotes
+            '(((1 integer) <- copy (4 literal))
+              (defer [
+                       ((3 integer) <- copy (6 literal))
+                     ])
+              ((2 integer) <- copy (5 literal))))
+          '(((1 integer) <- copy (4 literal))
+            ((2 integer) <- copy (5 literal))
+            ((3 integer) <- copy (6 literal))))
+  (prn "F - convert-quotes can handle 'defer'"))
+
 (reset)  ; end file with this to persist the trace for the final test