From f9dd51f6727f4a0344663b6edf470663e6dca174 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 19 Aug 2014 21:33:48 -0700 Subject: 56 - 'get' for record access --- mu.arc | 23 +++++++++++++++++------ 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 @@ -331,6 +331,18 @@ (if (~iso memory* (obj 1 2 2 36 3 2)) (prn "F - instructions can performs indirect addressing on output arg")) +(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 -- cgit 1.4.1-2-gfad0 f3fc8f8f77f833c4730b6de1b7d'>tree)
1
2
3
4
5
6
7
8
9
10
11