diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-08-19 21:33:48 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-08-19 21:33:48 -0700 |
commit | f9dd51f6727f4a0344663b6edf470663e6dca174 (patch) | |
tree | a8849371964591237cf62eac6acc25a9b5776a2a | |
parent | 6b133a720e379c5a891faf5e969361be85bdfcd5 (diff) | |
download | mu-f9dd51f6727f4a0344663b6edf470663e6dca174.tar.gz |
56 - 'get' for record access
-rw-r--r-- | mu.arc | 23 | ||||
-rw-r--r-- | mu.arc.t | 12 |
2 files changed, 29 insertions, 6 deletions
diff --git a/mu.arc b/mu.arc index df63e916..3aa0aa3f 100644 --- a/mu.arc +++ b/mu.arc @@ -7,12 +7,17 @@ (def clear () (= types* (obj - type (obj size 1 record nil array nil address nil) - location (obj size 1 record nil array nil address nil) - integer (obj size 1 record nil array nil address nil) - boolean (obj size 1 record nil array nil address nil) - integer-array (obj array t elem 'integer) ; array of ints, size in front - integer-address (obj size 1 address t elem 'integer) ; pointer to int + ; must be scalar or vector, sum or product or primitive + type (obj size 1) + location (obj size 1) + integer (obj size 1) + boolean (obj size 1) + integer-array (obj vector t elem 'integer) ; vectors provide size at front + integer-address (obj size 1 address t elem 'integer) ; pointer to int + block (obj size 1024 vector t elem 'location) ; last elem points to next block when this one fills up + block-address (obj size 1 address t elem 'block) + integer-boolean-pair (obj size 2 record t elems '(integer boolean)) + integer-boolean-pair-address (obj size 1 address t elem 'integer-boolean-pair) )) (= memory* (table)) (= function* (table))) @@ -121,6 +126,12 @@ (continue)) copy (m arg.0) + get + (withs (idx (v arg.1) + fields ((types* (ty arg.0)) 'elems) + offset (apply + (map [types*._ 'size] + (firstn idx fields)))) + (memory* (+ (v arg.0) offset))) reply (do (= result arg) (break)) diff --git a/mu.arc.t b/mu.arc.t index b9c903e9..8f9edb2f 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -333,6 +333,18 @@ (reset) (add-fns + '((main + ((1 integer) <- literal 34) + ((2 boolean) <- literal nil) + ((3 boolean) <- get (1 integer-boolean-pair) (1 offset)) + ((4 integer) <- get (1 integer-boolean-pair) (0 offset))))) +(run function*!main) +;? (prn memory*) +(if (~iso memory* (obj 1 34 2 nil 3 nil 4 34)) + (prn "F - 'get' accesses fields of records")) + +(reset) +(add-fns '((test1 ((4 type) <- otype 0) ((5 type) <- literal integer) |