about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-08-21 19:55:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-08-21 19:55:16 -0700
commitbaf61345bfa68d6457a9300e0d3e3aefe5196c30 (patch)
tree3da7f2b00b9419517cb6059df9d757d03400a312
parent689a480e1e0f7aca0f406bfad90a52dcef01d878 (diff)
downloadmu-baf61345bfa68d6457a9300e0d3e3aefe5196c30.tar.gz
62
-rw-r--r--mu.arc34
1 files changed, 20 insertions, 14 deletions
diff --git a/mu.arc b/mu.arc
index e88c4825..4d39ab33 100644
--- a/mu.arc
+++ b/mu.arc
@@ -45,10 +45,13 @@
 (def ty (operand)
   operand.1)  ; assume type is always first bit of metadata, and it's always present
 
+(def typeinfo (operand)
+  (types* ty.operand))
+
 (def sz (operand)
 ;?   (prn "sz " operand)
   ; todo: override this for vectors
-  ((types* ty.operand) 'size))
+  typeinfo.operand!size)
 (defextend sz (typename) (isa typename 'sym)
   types*.typename!size)
 
@@ -82,6 +85,11 @@
                                (rep val@))
          (= (memory* dest@) src@)))))
 
+(def array-ref (operand idx)
+  (withs (elem  typeinfo.operand!elem
+          offset  (+ 1 (* idx sz.elem)))
+    (m `(,(+ v.operand offset) ,elem))))
+
 (def run (instrs (o fn-args) (o fn-oargs))
   (ret result nil
     (with (ninstrs 0  fn-arg-idx 0)
@@ -153,19 +161,17 @@
                 copy
                   (m arg.0)
                 get
-                  (if ((types* (ty arg.0)) 'vector)
-                    (if (is 0 (v arg.1))
-                      (m `(,(v arg.0) integer))
-                      (withs (elem  ((types* (ty arg.0)) 'elem)
-                              offset  (+ (* (- (v arg.1) 1)
-                                            sz.elem)
-                                         1))
-                        (m `(,(+ (v arg.0) offset) ,elem))))
-                    (withs (idx  (v arg.1)
-                            fields  ((types* (ty arg.0)) 'elems)
-                            offset  (apply +
-                                           (map sz (firstn idx fields))))
-                      (memory* (+ (v arg.0) offset))))
+                  (with (base arg.0  ; integer (non-symbol) memory location including metadata
+                         idx (v arg.1))  ; literal integer
+                    (if typeinfo.base!vector
+                      ; vector is an integer 'sz' followed by sz elems
+                      (if (is 0 idx)
+                        (m `(,v.base integer))
+                        (array-ref base (- idx 1)))
+                      ; field index
+                      (memory* (+ v.base
+                                  (apply + (map sz
+                                                (firstn idx typeinfo.base!elems)))))))
                 reply
                   (do (= result arg)
                       (break))