44 - now 'deref' is a bit of metadata on any operand rather than a special op

Still only works in read, and only in a single instruction. But these are details.
This commit is contained in:
Kartik K. Agaram 2014-07-31 02:27:41 -07:00
parent 52c3822e08
commit b20165a890
3 changed files with 12 additions and 7 deletions

13
mu.arc
View File

@ -20,12 +20,20 @@
(mac v (operand) ; for value
`(,operand 0))
(mac metadata (operand)
`(cdr ,operand))
(mac ty (operand)
`(,operand 1)) ; assume type is always first bit of metadata, and it's always present
(mac m (loc) ; for memory
`(memory* (v ,loc)))
(mac m2 (loc) ; for memory
`(if (pos 'deref (metadata ,loc))
(memory* (memory* (v ,loc)))
(memory* (v ,loc))))
(def run (instrs (o fn-args) (o fn-oargs))
(ret result nil
(let fn-arg-idx 0
@ -109,10 +117,7 @@
;? (prn "jumping to " pc)
(continue))
copy
(= (m oarg.0) (m arg.0))
deref
(= (m oarg.0)
(memory* (m arg.0)))
(= (m oarg.0) (m2 arg.0))
reply
(do (= result arg)
(break))

View File

@ -310,11 +310,11 @@
'((main
((1 integer-address) <- literal 2)
((2 integer) <- literal 34)
((3 integer) <- deref (1 integer-address)))))
((3 integer) <- copy (1 integer-address deref)))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 2 2 34 3 34))
(prn "F - 'deref' performs indirect addressing"))
(prn "F - 'copy' performs indirect addressing"))
(clear)
(add-fns

2
new.mu
View File

@ -2,7 +2,7 @@
(main
((1 integer) <- literal 1000) ; location 1 contains the high-water mark for the memory allocator
((4 integer-address) <- new)
((5 integer) <- deref (4 integer-address))
((5 integer) <- copy (4 integer-address deref))
)
(new