about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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