about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-28 19:52:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-28 19:52:50 -0800
commitdc97016a7fd9c2c5fe4d4dd014cc018f8b69b00b (patch)
treeaab5b104b69718f5dd47d3abacce2feb47607719
parent29754636a6fd7406be0380c491fc155ca91c1b49 (diff)
downloadmu-dc97016a7fd9c2c5fe4d4dd014cc018f8b69b00b.tar.gz
376 - similarly simplify record helpers
-rw-r--r--mu.arc15
-rw-r--r--mu.arc.t18
2 files changed, 25 insertions, 8 deletions
diff --git a/mu.arc b/mu.arc
index b632b479..42e4ccfe 100644
--- a/mu.arc
+++ b/mu.arc
@@ -614,17 +614,16 @@
 (def record-info (operand field-offset)
   (trace "record-info" operand " " field-offset)
   (assert (is 'offset (ty field-offset)) "record index @field-offset must have type 'offset'")
-  (with (base  addr.operand
+  (zap absolutize operand)
+  (while (pos 'deref metadata.operand)
+    (zap deref operand))
+  (assert typeinfo.operand!record "get on non-record @operand")
+  (with (base  v.operand
          basetype  typeinfo.operand
          idx  (v field-offset))
     (trace "record-info" "initial base " base " type " canon.basetype)
-    (when (pos 'deref metadata.operand)
-      (assert basetype!address "@operand requests deref, but it's not an address of a record")
-      (= basetype (types* basetype!elem))
-      (trace "record-info" operand " requests deref => " canon.basetype))
-    (assert basetype!record "get on non-record @operand")
     (assert (< -1 idx (len basetype!elems)) "@idx is out of bounds of record @operand")
-    (list (+ base (apply + (map sizeof (firstn idx basetype!elems))))
+    (list (apply + base (map sizeof (firstn idx basetype!elems)))
           basetype!elems.idx)))
 
 ; (operand idx) -> (base-addr elem-type)
@@ -637,7 +636,7 @@
   (unless (< -1 idx array-len.operand)
     (die "@idx is out of bounds of array @operand"))
   (let elemtype typeinfo.operand!elem
-    (list (+ addr.operand
+    (list (+ v.operand
              1  ; for array siz
              (* idx sizeof.elemtype))
           elemtype)))
diff --git a/mu.arc.t b/mu.arc.t
index 1661ca71..ce879c32 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -511,6 +511,24 @@
   (prn "F - 'get' accesses fields of record address"))
 
 (reset)
+(new-trace "get-indirect-repeated")
+(add-code
+  '((def main [
+      ((1 integer) <- copy (34 literal))
+      ((2 integer) <- copy (35 literal))
+      ((3 integer) <- copy (36 literal))
+      ((4 integer-point-pair-address) <- copy (1 literal))  ; unsafe
+      ((5 integer-point-pair-address-address) <- copy (4 literal))  ; unsafe
+      ((6 integer-integer-pair) <- get (5 integer-point-pair-address-address deref deref) (1 offset))
+      ((8 integer) <- get (5 integer-point-pair-address-address deref deref) (0 offset))
+     ])))
+(run 'main)
+(if (or (~is memory*.6 35)
+        (~is memory*.7 36)
+        (~is memory*.8 34))
+  (prn "F - 'get' can deref multiple times"))
+
+(reset)
 (new-trace "get-compound-field")
 (add-code
   '((def main [