diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-10-05 11:32:25 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-10-05 11:32:25 -0700 |
commit | 3b0b336e87f33d41c5a699531ad25e2da4172a78 (patch) | |
tree | 81bf9347e7ac8245823bd14a91eab44203c8fca5 | |
parent | 5812830d53032aa7a8d97a6912fb254f2a8d856e (diff) | |
download | mu-3b0b336e87f33d41c5a699531ad25e2da4172a78.tar.gz |
102 - fold 'aref' into 'get'
Also separate op for length of an array.
-rw-r--r-- | mu.arc | 12 | ||||
-rw-r--r-- | mu.arc.t | 30 |
2 files changed, 32 insertions, 10 deletions
diff --git a/mu.arc b/mu.arc index 3a18b62e..3dc6e6f3 100644 --- a/mu.arc +++ b/mu.arc @@ -281,8 +281,7 @@ idx (v arg.1)) ; literal integer (if typeinfo.base!array - (do (assert (is 0 idx)) ; 'get' can only lookup array length - (array-len base)) + (array-ref base idx) typeinfo.base!record ; field index (do (assert (< -1 idx (len typeinfo.base!elems))) @@ -292,13 +291,18 @@ ,typeinfo.base!elems.idx))) :else (assert nil "get on invalid type @base"))) - aref - (array-ref arg.0 (v arg.1)) new (let type (v arg.0) (if types*.type!array (new-array type (v arg.1)) (new-scalar type))) + sizeof + (sizeof (v arg.0)) + len + (let base arg.0 + (if typeinfo.base!array + array-len.base + -1)) ; multiprocessing run diff --git a/mu.arc.t b/mu.arc.t index f7c9a7a7..829eb8ca 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -416,11 +416,11 @@ ((3 boolean) <- literal nil) ((4 integer) <- literal 24) ((5 boolean) <- literal t) - ((6 integer) <- get (1 integer-boolean-pair-array) (0 offset))))) + ((6 integer-boolean-pair) <- get (1 integer-boolean-pair-array) (1 offset))))) (run 'main) ;? (prn memory*) -(if (~iso memory* (obj 1 2 2 23 3 nil 4 24 5 t 6 2)) - (prn "F - 'get' accesses length of array")) +(if (~iso memory* (obj 1 2 2 23 3 nil 4 24 5 t 6 24 7 t)) + (prn "F - 'get' accesses indices of arrays")) (reset) (add-fns @@ -430,11 +430,29 @@ ((3 boolean) <- literal nil) ((4 integer) <- literal 24) ((5 boolean) <- literal t) - ((6 integer-boolean-pair) <- aref (1 integer-boolean-pair-array) (1 offset))))) + ((6 integer) <- len (1 integer-boolean-pair-array))))) (run 'main) ;? (prn memory*) -(if (~iso memory* (obj 1 2 2 23 3 nil 4 24 5 t 6 24 7 t)) - (prn "F - 'aref' accesses indices of arrays")) +(if (~iso memory* (obj 1 2 2 23 3 nil 4 24 5 t 6 2)) + (prn "F - 'len' accesses length of array")) + +(reset) +(add-fns + '((main + ((1 integer) <- sizeof (integer-boolean-pair type))))) +(run 'main) +;? (prn memory*) +(if (~iso memory* (obj 1 2)) + (prn "F - 'sizeof' returns space required by arg")) + +(reset) +(add-fns + '((main + ((1 integer) <- sizeof (integer-point-pair type))))) +(run 'main) +;? (prn memory*) +(if (~iso memory* (obj 1 3)) + (prn "F - 'sizeof' is different from number of elems")) ; todo: test that out-of-bounds access throws an error |