From ff61dc90eae50cdeb9927392fce692cb113ce751 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 28 Nov 2014 17:43:33 -0800 Subject: 363 --- mu.arc | 15 ++++++++++++++- mu.arc.t | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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) -- cgit 1.4.1-2-gfad0