about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-14 21:51:27 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-14 22:10:47 -0800
commit20379e78835203f0b5c79ac3edf1749216da82c8 (patch)
treeaf03251fa299951e7c6ff322dbb3e4163413b6c5
parent7d91aa77ffe74f136340c729bf9df9e24184dd7d (diff)
downloadmu-20379e78835203f0b5c79ac3edf1749216da82c8.tar.gz
569 - ah, the right way to do generic functions
Each clause creates its own default-space for local variables.

Now we can justify prepending bodies on every 'function' form.

Later we can optimize away the duplicate default-spaces.

Another cost: we can't mindlessly use 'next-input' anymore. Pity.
-rw-r--r--generic.mu5
-rw-r--r--mu.arc5
-rw-r--r--mu.arc.t2
3 files changed, 9 insertions, 3 deletions
diff --git a/generic.mu b/generic.mu
index 4486e8bc..1392394a 100644
--- a/generic.mu
+++ b/generic.mu
@@ -5,7 +5,6 @@
 (function factorial [
   (default-space:space-address <- new space:literal 30:literal)
   (n:integer <- input 0:literal)
-  more-clauses
   (x:integer <- subtract n:integer 1:literal)
   (subresult:integer <- factorial x:integer)
   (result:integer <- multiply subresult:integer n:integer)
@@ -13,7 +12,9 @@
 ])
 
 ; factorial 0 = 1
-(after factorial/more-clauses [
+(function factorial [
+  (default-space:space-address <- new space:literal 30:literal)
+  (n:integer <- input 0:literal)
   { begin
     (zero?:boolean <- equal n:integer 0:literal)
     (break-unless zero?:boolean)
diff --git a/mu.arc b/mu.arc
index 4ba2a193..59a16e70 100644
--- a/mu.arc
+++ b/mu.arc
@@ -815,11 +815,14 @@
                       (map memory* (addrs addr n)))))))
 
 (def setm (loc val)  ; set memory, respecting metadata
+;?   (tr 111)
   (point return
+;?   (tr 112)
     (when (is v.loc 'default-space)
       (assert (is 1 sizeof.loc) "can't store compounds in default-space @loc")
       (= rep.routine*!call-stack.0!default-space val)
       (return))
+;?   (tr 120)
     (assert (isa v.loc 'int) "can't store to non-numeric address (problem in convert-names?)")
     (trace "setm" loc " <= " val)
     (with (n  (if (isa val 'record) (len rep.val) 1)
@@ -904,7 +907,7 @@
 (def absolutize (operand)
   (if (no routine*)
         operand
-      (is '_ v.operand)
+      (in v.operand '_ 'default-space)
         operand
       (pos '(raw) metadata.operand)
         operand
diff --git a/mu.arc.t b/mu.arc.t
index 5e376ed4..1b378c5a 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -4116,6 +4116,8 @@
   (prn "F - 'absolutize' checks against default-space bounds"))
 (when (~iso '((_ integer)) (absolutize '((_ integer))))
   (prn "F - 'absolutize' passes dummy args right through"))
+(when (~iso '((default-space integer)) (absolutize '((default-space integer))))
+  (prn "F - 'absolutize' passes 'default-space' right through"))
 
 (= memory*.20 5)  ; pretend array
 (= rep.routine*!globals 20)  ; provide it to routine global