about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-29 10:33:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-29 10:33:43 -0700
commitc34f5e26c8f799b242dffbc0703109052428842d (patch)
treedaf40da749e7bb32382db23049c2b12c65cd54ed
parent4ed7fd4b94a154df6ed65e15e64e3265b569116a (diff)
downloadmu-c34f5e26c8f799b242dffbc0703109052428842d.tar.gz
170 - stack frame support
When the current context has a 'default-scope', directly-addressed
memory offsets off of it.
-rw-r--r--mu.arc40
-rw-r--r--mu.arc.t14
2 files changed, 39 insertions, 15 deletions
diff --git a/mu.arc b/mu.arc
index 612a210b..137d4486 100644
--- a/mu.arc
+++ b/mu.arc
@@ -36,6 +36,9 @@
               character (obj size 1)  ; int32 like a Go rune
               character-address (obj size 1  address t  elem 'character)
               string (obj size 1)  ; temporary hack
+              ; isolating function calls
+              scope  (obj array t  elem 'location)  ; by convention index 0 points to outer scope
+              scope-address  (obj size 1  address t  elem 'scope)
               ; arrays consist of an integer length followed by the right number of elems
               integer-array (obj array t  elem 'integer)
               integer-address (obj size 1  address t  elem 'integer)  ; pointer to int
@@ -146,9 +149,11 @@
       (err "type @typename doesn't have a size: " (tostring:pr types*.typename))))
 
 (def addr (loc)
-  (if (pos 'deref metadata.loc)
-    (memory* v.loc)
-    v.loc))
+  (ret addr v.loc
+    (aif rep.context*!default-scope
+      (++ addr it))
+    (if (pos 'deref metadata.loc)
+      (zap memory* addr))))
 
 (def addrs (n sz)
   (accum yield
@@ -169,18 +174,23 @@
                     (map memory* (addrs addr.loc sz.loc))))))
 
 (def setm (loc val)  ; set memory, respecting metadata
-  (assert (isa v.loc 'int))
-  (trace "setm" loc " <= " val)
-  (let n sz.loc
-    (trace "setm" "size of " loc " is " n)
-    (assert n)
-    (if (is 1 n)
-      (do (assert (~isa val 'record))
-          (= (memory* addr.loc) val))
-      (do (assert (isa val 'record))
-          (each (dest src) (zip (addrs addr.loc n)
-                                (rep val))
-            (= (memory* dest) src))))))
+  (point return
+    (when (is v.loc 'default-scope)
+      (assert (is 1 sz.loc))
+      (= rep.context*!default-scope val)
+      (return))
+    (assert (isa v.loc 'int))
+    (trace "setm" loc " <= " val)
+    (let n sz.loc
+      (trace "setm" "size of " loc " is " n)
+      (assert n)
+      (if (is 1 n)
+        (do (assert (~isa val 'record))
+            (= (memory* addr.loc) val))
+        (do (assert (isa val 'record))
+            (each (dest src) (zip (addrs addr.loc n)
+                                  (rep val))
+              (= (memory* dest) src)))))))
 
 (def array-len (operand)
 ;?   (prn operand)
diff --git a/mu.arc.t b/mu.arc.t
index f3df4ea8..ee3a96f1 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1366,4 +1366,18 @@
             ((3 integer) <- copy (6 literal))))
   (prn "F - convert-quotes can handle 'defer'"))
 
+(reset)
+(new-trace "set-default-scope")
+(add-fns
+  '((main
+      ((default-scope scope-address) <- new (scope type) (1 literal))
+      ((1 integer) <- copy (23 literal)))))
+(let before Memory-in-use-until
+;?   (set dump-trace*)
+  (run 'main)
+;?   (prn memory*)
+  (if (~and (~is 23 memory*.1)
+            (is 23 (memory* (+ before 1))))
+    (prn "F - default-scope implicitly modifies variable locations")))
+
 (reset)  ; end file with this to persist the trace for the final test