about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-08-21 20:33:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-08-21 20:35:52 -0700
commit6a2edbe8cad4547921fa6d7307af47b5190a2b48 (patch)
tree8189cfb81f5d48b71082d102265e3c5909d27036
parent6f9bf3a063470d02cfaff0601281e39ee315e6a3 (diff)
downloadmu-6a2edbe8cad4547921fa6d7307af47b5190a2b48.tar.gz
65 - separate op for array indexing
'get' no longer supports that case; that was confusing.
-rw-r--r--mu.arc7
-rw-r--r--mu.arc.t21
2 files changed, 21 insertions, 7 deletions
diff --git a/mu.arc b/mu.arc
index 789b30f3..04a6af69 100644
--- a/mu.arc
+++ b/mu.arc
@@ -167,14 +167,15 @@
                          idx (v arg.1))  ; literal integer
                     (if typeinfo.base!array
                       ; array is an integer 'sz' followed by sz elems
-                      (if (is 0 idx)
-                        (m `(,v.base integer))
-                        (array-ref base (- idx 1)))
+                      ; 'get' can only lookup its index
+                      (m `(,v.base integer))
                       ; field index
                       (m `(,(+ v.base
                                (apply + (map sz
                                              (firstn idx typeinfo.base!elems))))
                            ,typeinfo.base!elems.idx))))
+                aref
+                  (array-ref arg.0 (v arg.1))
                 reply
                   (do (= result arg)
                       (break))
diff --git a/mu.arc.t b/mu.arc.t
index a626bcda..6dfb7824 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -366,12 +366,25 @@
       ((3 boolean) <- literal nil)
       ((4 integer) <- literal 24)
       ((5 boolean) <- literal t)
-      ((6 integer) <- get (1 integer-boolean-pair-array) (0 offset))
-      ((7 integer-boolean-pair) <- get (1 integer-boolean-pair-array) (1 offset)))))
+      ((6 integer) <- get (1 integer-boolean-pair-array) (0 offset)))))
 (run function*!main)
 ;? (prn memory*)
-(if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 2  7 23 8 nil))
-  (prn "F - 'get' accesses fields of arrays, with length at index 0"))
+(if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 2))
+  (prn "F - 'get' accesses length of array"))
+
+(reset)
+(add-fns
+  '((main
+      ((1 integer) <- literal 2)
+      ((2 integer) <- literal 23)
+      ((3 boolean) <- literal nil)
+      ((4 integer) <- literal 24)
+      ((5 boolean) <- literal t)
+      ((6 integer-boolean-pair) <- aref (1 integer-boolean-pair-array) (1 offset)))))
+(run function*!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"))
 
 ; todo: test that out-of-bounds access throws an error