about summary refs log tree commit diff stats
path: root/mu.arc
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 /mu.arc
parentdaff44a21eb533b3774b965912a9df695a25e172 (diff)
downloadmu-62fc8a7b99f6dc5a9bc06cd682025e465c21ca02.tar.gz
111 - no, can't mix array and record access
records need literal offsets; arrays need variables.
Diffstat (limited to 'mu.arc')
-rw-r--r--mu.arc50
1 files changed, 30 insertions, 20 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)