about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc16
-rw-r--r--mu.arc.t17
-rw-r--r--tangle.mu33
3 files changed, 35 insertions, 31 deletions
diff --git a/mu.arc b/mu.arc
index 38c5318a..aaab580a 100644
--- a/mu.arc
+++ b/mu.arc
@@ -203,6 +203,7 @@
               ,@body)))))
 
 (def run fn-names
+  (freeze-functions)
   (each it fn-names
     (enq make-routine.it running-routines*))
   (while (~empty running-routines*)
@@ -1054,10 +1055,6 @@
   ((result boolean) <- eq (full integer) (curr integer))
   (reply (result boolean)))
 
-; drop all traces while processing above functions
-(on-init
-  (= traces* (queue)))
-
 (def canon (table)
   (sort (compare < [tostring (prn:car _)]) (as cons table)))
 
@@ -1073,9 +1070,8 @@
       def
         (let (name (_make-br-fn body))  rest
           (assert (is 'make-br-fn _make-br-fn))
-;?           (prn keys.before* " -- " keys.after*)
-;?           (= function*.name (convert-names:convert-braces:prn:insert-code body)))
-          (= function*.name (convert-names:convert-braces:insert-code body)))
+          ; don't apply our lightweight tools just yet
+          (= function*.name body))
 
       ; syntax: before <label> [ <instructions> ]
       ;
@@ -1096,6 +1092,12 @@
           (assert (is 'make-br-fn _make-br-fn))
           (push fragment after*.label)))))
 
+(def freeze-functions ()
+  (each (name body)  canon.function*
+;?     (prn keys.before* " -- " keys.after*)
+;?     (= function*.name (convert-names:convert-braces:prn:insert-code body)))
+    (= function*.name (convert-names:convert-braces:insert-code body))))
+
 ;; load all provided files and start at 'main'
 (reset)
 (awhen cdr.argv
diff --git a/mu.arc.t b/mu.arc.t
index a1f0c90e..542dbfc8 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -2785,9 +2785,26 @@
                 label1
               }
              ])))
+(freeze-functions)
 (if (~iso function*!f1
           '(label1
             ((1 integer) <- copy (0 literal))))
   (prn "F - before/after works inside blocks"))
 
+(reset)
+;? (new-trace "before-after-any-order")
+(add-code '((def f1 [
+              { begin
+                label1
+              }
+             ])
+            (after label1 [
+               ((1 integer) <- copy (0 literal))
+             ])))
+(freeze-functions)
+(if (~iso function*!f1
+          '(label1
+            ((1 integer) <- copy (0 literal))))
+  (prn "F - before/after can come after the function they need to modify"))
+
 (reset)  ; end file with this to persist the trace for the final test
diff --git a/tangle.mu b/tangle.mu
index fae99791..46ddd6fc 100644
--- a/tangle.mu
+++ b/tangle.mu
@@ -3,6 +3,15 @@
 ; This isn't a very realistic example, just a simple demonstration of
 ; possibilities.
 
+(def factorial [
+  ((default-scope scope-address) <- new (scope literal) (30 literal))
+  ((n integer) <- arg)
+  { begin
+    base-case
+  }
+  recursive-case
+])
+
 (after base-case [
   ; if n=0 return 1
   ((zero? boolean) <- eq (n integer) (0 literal))
@@ -18,33 +27,9 @@
   (reply (result integer))
 ])
 
-(def factorial [
-  ((default-scope scope-address) <- new (scope literal) (30 literal))
-  ((n integer) <- arg)
-  { begin
-    base-case
-  }
-  recursive-case
-])
-
 (def main [
   ((1 integer) <- factorial (5 literal))
   (print-primitive ("result: " literal))
   (print-primitive (1 integer))
   (print-primitive ("\n" literal))
 ])
-
-;? (((default-scope scope-address) <- new (scope literal) (30 literal))
-;?  ((n integer) <- arg)
-;?  { begin
-;?    base-case
-;?  }
-;?  recursive-case
-;?  ((x integer) <- sub (n integer) (1 literal))
-;?  ((subresult integer) <- factorial (x integer))
-;?  ((result integer) <- mul (subresult integer) (n integer))
-;?  (reply (result integer)))
-;? 
-;? (((1 integer) <- factorial (5 literal)) (print-primitive (result:  literal)) (print-primitive (1 integer)) (print-primitive (
-;?  literal)))
-;?