about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-28 17:43:33 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-28 17:43:33 -0800
commitff61dc90eae50cdeb9927392fce692cb113ce751 (patch)
tree71b97a56481ec31d79361717626375a97d75c7b5
parent307dd5b8e7cbb5c20f831b9d948f68bc77acc83a (diff)
downloadmu-ff61dc90eae50cdeb9927392fce692cb113ce751.tar.gz
363
-rw-r--r--mu.arc15
-rw-r--r--mu.arc.t15
2 files changed, 29 insertions, 1 deletions
diff --git a/mu.arc b/mu.arc
index 21e03a0e..a5a34c14 100644
--- a/mu.arc
+++ b/mu.arc
@@ -274,7 +274,8 @@
   (= rep.routine*!error msg)
   (= rep.routine*!stack-trace rep.routine*!call-stack)
   (wipe rep.routine*!call-stack)
-  ((abort-routine*)))
+  (iflet abort-continuation (abort-routine*)
+    (abort-continuation)))
 
 ;; running a single routine
 (def nondummy (operand)  ; precondition for helpers below
@@ -708,6 +709,18 @@
         :else
           (err "sizeof can't handle @type (arrays require a specific variable)")))))
 
+(def absolutize (operand)
+  (if (no routine*)
+        operand
+      (pos 'global metadata.operand)
+        operand
+      :else
+        (iflet base rep.routine*!call-stack.0!default-scope
+          (if (< v.operand memory*.base)
+            `(,(+ v.operand base) ,@metadata.operand global)
+            (die "no room for var @operand in routine of size @memory*.base"))
+          operand)))
+
 (def deref (operand)
   (assert (pos 'deref metadata.operand))
   (assert typeinfo.operand!address)
diff --git a/mu.arc.t b/mu.arc.t
index bb08c583..070d68bb 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -754,6 +754,21 @@
 (if (~iso '(5 integer) (deref:deref '(3 integer-address-address deref deref)))
   (prn "F - 'deref' can be chained"))
 
+; unit tests for 'absolutize' helper
+(reset)
+(if (~iso '(4 integer) (absolutize '(4 integer)))
+  (prn "F - 'absolutize' works without routine"))
+(= routine* make-routine!foo)
+(if (~iso '(4 integer) (absolutize '(4 integer)))
+  (prn "F - 'absolutize' works without default-scope"))
+(= rep.routine*!call-stack.0!default-scope 10)
+(= memory*.10 5)  ; bounds check for default-scope
+(if (~iso '(14 integer global) (absolutize '(4 integer)))
+  (prn "F - 'absolutize' works with default-scope"))
+(absolutize '(5 integer))
+(if (~posmatch "no room" rep.routine*!error)
+  (prn "F - 'absolutize' checks against default-scope bounds"))
+
 ; unit tests for 'sizeof' helper
 (reset)
 (if (~is 1 sizeof!integer)