diff options
-rw-r--r-- | generic.mu | 5 | ||||
-rw-r--r-- | mu.arc | 15 | ||||
-rw-r--r-- | mu.arc.t | 18 |
3 files changed, 30 insertions, 8 deletions
diff --git a/generic.mu b/generic.mu index b37b5208..e73612c5 100644 --- a/generic.mu +++ b/generic.mu @@ -5,6 +5,7 @@ (def factorial [ ((default-scope scope-address) <- new (scope literal) (30 literal)) ((n integer) <- arg (0 literal)) + more-clauses ((x integer) <- sub (n integer) (1 literal)) ((subresult integer) <- factorial (x integer)) ((result integer) <- mul (subresult integer) (n integer)) @@ -12,9 +13,7 @@ ]) ; def factorial 0 = 1 -(def factorial [ - ((default-scope scope-address) <- new (scope literal) (30 literal)) - ((n integer) <- arg (0 literal)) +(after factorial/more-clauses [ { begin ((zero? boolean) <- eq (n integer) (0 literal)) (break-unless (zero? boolean)) diff --git a/mu.arc b/mu.arc index 757db53e..9390206c 100644 --- a/mu.arc +++ b/mu.arc @@ -819,7 +819,7 @@ (assert nil "couldn't find field in @instr"))))) (each arg args (assert (~isa-field v.arg) "arg @arg is also a field name") - (when (maybe-add arg location idx) + (when (and (~is 'quasiquote car.arg) (maybe-add arg location idx)) (err "use before set: @arg")))) (each arg oargs (trace "cn0" "checking " arg) @@ -1165,15 +1165,20 @@ rewrite (let (name (_make-br-fn fragment)) rest (assert (is 'make-br-fn _make-br-fn)) - (= rewrite-rules*.name fragment)) + (set rewrite-rules*.name) + (= function*.name (convert-names:convert-braces:insert-code fragment name))) ;else ; must be rewriteable to one of the above - (let new-form (rewrite rewrite-rules*.op rest) + (let new-form (rewrite op rest) (add-code new-form)) ))) -(def rewrite (rewrite-rule params) - rewrite-rule) +(def rewrite (op params) + (prn "a: " params) + (prn "b: " function*.op) + (= routine* (annotate 'routine (obj call-stack (list + (obj fn-name op pc 0 args params caller-arg-idx 0))))) + (run-for-time-slice 10000)) (def freeze-functions () (each (name body) canon.function* diff --git a/mu.arc.t b/mu.arc.t index 77909607..1eac3f79 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -2997,4 +2997,22 @@ ((1 integer) <- copy (0 literal)))) (prn "F - simple rewrite-rule correctly expanded")) +(reset) +(new-trace "rewrite-rule-body") +(= traces* (queue)) +(= function* (table)) +(add-code '((rewrite foo [ + ((default-scope scope-address) <- new (scope literal) (10 literal)) + ((body location) <- arg) + (reply `(def bar ,body)) + ]) + (foo [ + ((1 integer) <- copy (0 literal)) + ]))) +;? (prn function*) +(if (~iso function*!bar + '( + ((1 integer) <- copy (0 literal)))) + (prn "F - rewrite-rule with body correctly expanded")) + (reset) ; end file with this to persist the trace for the final test |