65 - separate op for array indexing
'get' no longer supports that case; that was confusing.
This commit is contained in:
parent
6f9bf3a063
commit
6a2edbe8ca
7
mu.arc
7
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))
|
||||
|
|
21
mu.arc.t
21
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue