about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-05 20:03:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-05 20:03:03 -0700
commit62fc8a7b99f6dc5a9bc06cd682025e465c21ca02 (patch)
tree53c004d2cd92a7894b986d812b848ad91fb50ae4
parentdaff44a21eb533b3774b965912a9df695a25e172 (diff)
downloadmu-62fc8a7b99f6dc5a9bc06cd682025e465c21ca02.tar.gz
111 - no, can't mix array and record access
records need literal offsets; arrays need variables.
-rw-r--r--mu.arc50
-rw-r--r--mu.arc.t28
2 files changed, 52 insertions, 26 deletions
diff --git a/mu.arc b/mu.arc
index 0704d252..9f6440ec 100644
--- a/mu.arc
+++ b/mu.arc
@@ -293,33 +293,43 @@
                       (assert (pos 'deref metadata.base))
                       (= base (list (memory* v.base) typeinfo.base!elem)))
 ;?                     (prn "after: " base)
-                    (if
-                      typeinfo.base!array
-                        (array-ref base idx)
-                      typeinfo.base!record
-                        ; field index
-                        (do (assert (< -1 idx (len typeinfo.base!elems)))
-                            (m `(,(+ v.base
-                                     (apply + (map sz
-                                                   (firstn idx typeinfo.base!elems))))
-                                 ,typeinfo.base!elems.idx)))
-                      :else
-                        (assert nil "get on invalid type @base")))
+                    (if typeinfo.base!record
+                      (do (assert (< -1 idx (len typeinfo.base!elems)))
+                          (m `(,(+ v.base
+                                   (apply + (map sz
+                                                 (firstn idx typeinfo.base!elems))))
+                               ,typeinfo.base!elems.idx)))
+                      (assert nil "get on invalid type @base")))
                 get-address
                   (with (base arg.0
                          idx (v arg.1))
                     (when typeinfo.base!address
                       (assert (pos 'deref metadata.base))
                       (= base (list (memory* v.base) typeinfo.base!elem)))
+                    (if typeinfo.base!record
+                      (do (assert (< -1 idx (len typeinfo.base!elems)))
+                          (+ v.base
+                             (apply + (map sz
+                                           (firstn idx typeinfo.base!elems)))))
+                      (assert nil "get-address on invalid type @base")))
+                index
+                  (with (base arg.0  ; integer (non-symbol) memory location including metadata
+                         idx (m arg.1))
+                    (when typeinfo.base!address
+                      (assert (pos 'deref metadata.base))
+                      (= base (list (memory* v.base) typeinfo.base!elem)))
+                    (if typeinfo.base!array
+                      (array-ref base idx)
+                      (assert nil "get on invalid type @arg.0 => @base")))
+                index-address
+                  (with (base arg.0
+                         idx (m arg.1))
+                    (when typeinfo.base!address
+                      (assert (pos 'deref metadata.base))
+                      (= base (list (memory* v.base) typeinfo.base!elem)))
                     (if typeinfo.base!array
-                          (array-ref-addr base idx)
-                        typeinfo.base!record
-                          (do (assert (< -1 idx (len typeinfo.base!elems)))
-                              (+ v.base
-                                 (apply + (map sz
-                                               (firstn idx typeinfo.base!elems)))))
-                        :else
-                          (assert nil "get-address on invalid type @base")))
+                      (array-ref-addr base idx)
+                      (assert nil "get-address on invalid type @arg.0 => @base")))
 
                 new
                   (let type (v arg.0)
diff --git a/mu.arc.t b/mu.arc.t
index 15de917a..868de132 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -442,7 +442,7 @@
 (run 'main)
 ;? (prn memory*)
 (if (~iso memory* (obj 1 34  2 t  3 1  4 2))
-  (prn "F - 'get-address' returns address of fields of records"))
+  (prn "F - 'get-address' accesses fields of record address"))
 
 (reset)
 (add-fns
@@ -452,11 +452,26 @@
       ((3 boolean) <- literal nil)
       ((4 integer) <- literal 24)
       ((5 boolean) <- literal t)
-      ((6 integer-boolean-pair) <- get (1 integer-boolean-pair-array) (1 offset)))))
+      ((6 integer-boolean-pair) <- index (1 integer-boolean-pair-array) (1 literal)))))
 (run 'main)
 ;? (prn memory*)
 (if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 24 7 t))
-  (prn "F - 'get' accesses indices of arrays"))
+  (prn "F - 'index' accesses indices of arrays"))
+
+(reset)
+(add-fns
+  '((main
+      ((1 integer) <- literal 2)
+      ((2 integer) <- literal 23)
+      ((3 boolean) <- literal nil)
+      ((4 integer) <- literal 24)
+      ((5 boolean) <- literal t)
+      ((6 integer) <- literal 1)
+      ((7 integer-boolean-pair) <- index (1 integer-boolean-pair-array) (6 integer)))))
+(run 'main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 1  7 24 8 t))
+  (prn "F - 'index' accesses indices of arrays"))
 
 (reset)
 (add-fns
@@ -466,11 +481,12 @@
       ((3 boolean) <- literal nil)
       ((4 integer) <- literal 24)
       ((5 boolean) <- literal t)
-      ((6 integer-boolean-pair-address) <- get-address (1 integer-boolean-pair-array) (1 offset)))))
+      ((6 integer) <- literal 1)
+      ((7 integer-boolean-pair-address) <- index-address (1 integer-boolean-pair-array) (6 integer)))))
 (run 'main)
 ;? (prn memory*)
-(if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 4))
-  (prn "F - 'get-address' returns addresses of indices of arrays"))
+(if (~iso memory* (obj 1 2  2 23 3 nil  4 24 5 t  6 1  7 4))
+  (prn "F - 'index-address' returns addresses of indices of arrays"))
 
 (reset)
 (add-fns