From 124996992988ecd2c41ce0cbc35470a0b89ed954 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 28 Nov 2014 15:51:17 -0800 Subject: 354 - stepping back, test-driving 'addr' helper again --- mu.arc | 3 ++- mu.arc.t | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mu.arc b/mu.arc index d2486df7..8ff33f5c 100644 --- a/mu.arc +++ b/mu.arc @@ -312,7 +312,8 @@ (trace "addr" loc) (ret result v.loc (trace "addr" "initial result: " result) - (unless (pos 'global metadata.loc) + (unless (or (pos 'global metadata.loc) + (no routine*)) ;? (tr "aa " routine*) (whenlet base rep.routine*!call-stack.0!default-scope (if (< result memory*.base) diff --git a/mu.arc.t b/mu.arc.t index 32cd2f26..564dd1f8 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -705,6 +705,33 @@ (prn "F - 'sizeof' is different from number of elems")) ; Regardless of a type's length, you can move it around just like a primitive. +; Various primitives need to support this. + +; unit tests for 'addr' helper +(reset) +(= routine* nil) +(if (~is 4 (addr '(4 integer))) + (prn "F - directly addressed operands are their own address")) +(if (~is 4 (addr '(4 integer-address))) + (prn "F - directly addressed operands are their own address - 2")) +(if (~is 4 (addr '(4 literal))) + (prn "F - 'addr' doesn't understand literals")) +(= memory*.4 23) +(if (~is 23 (addr '(4 integer-address deref))) + (prn "F - 'addr' works with indirectly-addressed 'deref'")) + +(= routine* make-routine!foo) +(= rep.routine*!call-stack.0!default-scope 10) +(= memory*.10 5) ; bounds check for default-scope +(if (~is 14 (addr '(4 integer))) + (prn "F - directly addressed operands in routines add default-scope")) +(if (~is 14 (addr '(4 integer-address))) + (prn "F - directly addressed operands in routines add default-scope - 2")) +(if (~is 14 (addr '(4 literal))) + (prn "F - 'addr' doesn't understand literals")) +(= memory*.14 23) +(if (~is 23 (addr '(4 integer-address deref))) + (prn "F - 'addr' adds default-scope before 'deref', not after")) (reset) (new-trace "copy-record") -- cgit 1.4.1-2-gfad0