57 - multi-word or multi-field ops

This commit is contained in:
Kartik K. Agaram 2014-08-19 23:37:50 -07:00
parent f9dd51f672
commit b9fef0471d
2 changed files with 37 additions and 7 deletions

32
mu.arc
View File

@ -44,17 +44,35 @@
(mac ty (operand)
`(,operand 1)) ; assume type is always first bit of metadata, and it's always present
(mac m (loc) ; for memory
(mac addr (loc)
`(let loc@ ,loc
(if (pos 'deref (metadata loc@))
(memory* (memory* (v loc@)))
(memory* (v loc@)))))
(memory* (v loc@))
(v loc@))))
(def addrs (n sz)
(accum yield
(repeat sz
(yield n)
(++ n))))
(mac m (loc) ; for memory
`(withs (loc@ ,loc
sz@ ((types* (ty loc@)) 'size))
;? (prn "m " loc@ sz@)
(if (is 1 sz@)
(memory* (addr loc@))
(annotate 'record
(map memory* (addrs (addr loc@) sz@))))))
(mac setm (loc val) ; set memory, respecting addressing-mode tags
`(let loc@ ,loc
(if (pos 'deref (metadata loc@))
(= (memory* (memory* (v loc@))) ,val)
(= (memory* (v loc@)) ,val))))
`(withs (loc@ ,loc
sz@ ((types* (ty loc@)) 'size))
(if (is 1 sz@)
(= (memory* (addr loc@)) ,val)
(each (dest@ src@) (zip (addrs (addr loc@) sz@)
(rep ,val))
(= (memory* dest@) src@)))))
(def run (instrs (o fn-args) (o fn-oargs))
(ret result nil

View File

@ -343,6 +343,18 @@
(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)
((4 boolean) <- literal t)
((3 integer-boolean-pair) <- copy (1 integer-boolean-pair)))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 34 2 nil 3 34 4 nil))
(prn "F - ops can operate on multi-field records"))
(reset)
(add-fns
'((test1