about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-08-19 23:37:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-08-19 23:37:50 -0700
commitb9fef0471dd11b63353d20fa57358acf477cf534 (patch)
tree473494bb158f136a20c5f05df9765b3f332ed92f
parentf9dd51f6727f4a0344663b6edf470663e6dca174 (diff)
downloadmu-b9fef0471dd11b63353d20fa57358acf477cf534.tar.gz
57 - multi-word or multi-field ops
-rw-r--r--mu.arc32
-rw-r--r--mu.arc.t12
2 files changed, 37 insertions, 7 deletions
diff --git a/mu.arc b/mu.arc
index 3aa0aa3f..fc0d3e78 100644
--- a/mu.arc
+++ b/mu.arc
@@ -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
diff --git a/mu.arc.t b/mu.arc.t
index 8f9edb2f..a7003c6e 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -345,6 +345,18 @@
 
 (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
       ((4 type) <- otype 0)
       ((5 type) <- literal integer)