107 - 'get' can now take an address

This commit is contained in:
Kartik K. Agaram 2014-10-05 15:02:28 -07:00
parent ecbd043693
commit bf6a25faa9
2 changed files with 32 additions and 0 deletions

19
mu.arc
View File

@ -93,6 +93,20 @@
(def typeinfo (operand)
(types* ty.operand))
;? (def is-array (operand)
;? (if (pos 'deref metadata.operand)
;? (if typeinfo.operand!address
;? ((types* typeinfo.operand!elem) 'array)
;? (err "can't deref non-address @operand"))
;? typeinfo.operand!array))
;?
;? (def is-record (operand)
;? (if (pos 'deref metadata.operand)
;? (if typeinfo.operand!address
;? ((types* typeinfo.operand!elem) 'record)
;? (err "can't deref non-address @operand"))
;? typeinfo.operand!record))
(def sz (operand)
;? (prn "sz " operand)
; todo: override this for arrays
@ -287,6 +301,11 @@
get
(with (base arg.0 ; integer (non-symbol) memory location including metadata
idx (v arg.1)) ; literal integer
;? (prn base ": " (memory* v.base))
(when typeinfo.base!address
(assert (pos 'deref metadata.base))
(= base (list (memory* v.base) typeinfo.base!elem)))
;? (prn "after: " base)
(if
typeinfo.base!array
(array-ref base idx)

View File

@ -396,6 +396,19 @@
(if (~iso memory* (obj 1 34 2 nil 3 nil 4 34))
(prn "F - 'get' accesses fields of records"))
(reset)
(add-fns
'((main
((1 integer) <- literal 34)
((2 boolean) <- literal nil)
((3 integer-boolean-pair-address) <- literal 1)
((4 boolean) <- get (3 integer-boolean-pair-address deref) (1 offset))
((5 integer) <- get (3 integer-boolean-pair-address deref) (0 offset)))))
(run 'main)
;? (prn memory*)
(if (~iso memory* (obj 1 34 2 nil 3 1 4 nil 5 34))
(prn "F - 'get' accesses fields of record address"))
(reset)
(add-fns
'((main