about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-29 12:33:57 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-29 12:40:29 -0800
commite2a5ae322ce5fec5b798a8c74eb0e72210934de1 (patch)
tree8c68c74c0d89d007db552aaa1aabd79d2cace8c7
parentb96d34f6f613789537e65973f0048dd3ca7681de (diff)
downloadmu-e2a5ae322ce5fec5b798a8c74eb0e72210934de1.tar.gz
676 - allow routines to share *names* for locals
-rw-r--r--mu.arc14
-rw-r--r--mu.arc.t26
2 files changed, 39 insertions, 1 deletions
diff --git a/mu.arc b/mu.arc
index ef1bd936..cc76e2ec 100644
--- a/mu.arc
+++ b/mu.arc
@@ -1076,7 +1076,7 @@
                   (- space 1))))
 
 (def space (operand)
-  (or (alref operand 'space)
+  (or (alref metadata.operand 'space)
       0))
 
 (def deref (operand)
@@ -1263,7 +1263,19 @@
 
 (def assign-names-to-location (instrs name)
 ;?   (tr name)
+;?   (prn name ": " location*) ;? 1
   (ret location (table)
+    ; if default-space in first instruction has a name, begin with its bindings
+    (when (acons instrs.0)  ; not a label
+      (let first-oarg-of-first-instr instrs.0.0  ; hack: assumes the standard default-space boilerplate
+        (when (and (nondummy first-oarg-of-first-instr)
+                   (is 'default-space (v first-oarg-of-first-instr))
+                   (assoc 'names metadata.first-oarg-of-first-instr))
+          (let old-names (location*:alref metadata.first-oarg-of-first-instr 'names)
+            (unless old-names
+              (err "@name requires bindings for @(alref metadata.first-oarg-of-first-instr 'names) which aren't computed yet. Reorder @name to load later."))
+            (= location copy.old-names))))) ; assumption: we've already converted names for 'it'
+;?     (prn location) ;? 1
     (with (isa-field  (table)
            idx  1)  ; 0 always reserved for next space
       (each instr instrs
diff --git a/mu.arc.t b/mu.arc.t
index cbf7c6a2..af4642a4 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -2252,6 +2252,32 @@
   (prn "F - /names to name variables in outer spaces"))
 ;? (quit)
 
+(reset)
+(new-trace "default-space-shared-with-names")
+(add-code
+  '((function f [
+      (default-space:space-address <- new space:literal 30:literal)
+      (x:integer <- copy 3:literal)
+      (y:integer <- copy 4:literal)
+      (reply default-space:space-address)
+     ])
+    (function g [
+      (default-space:space-address/names:f <- next-input)
+      (y:integer <- add y:integer 1:literal)
+      (x:integer <- add x:integer 2:literal)
+      (reply x:integer y:integer)
+     ])
+    (function main [
+      (1:space-address <- f)
+      (2:integer 3:integer <- g 1:space-address)
+     ])))
+(run 'main)
+(each routine completed-routines*
+  (aif rep.routine!error (prn "error - " it)))
+(when (or (~is memory*.2 5)
+          (~is memory*.3 5))
+  (prn "F - override names for the default space"))
+
 )  ; section 20
 
 (section 100