about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-28 16:17:11 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-28 16:19:54 -0800
commitbfc5fe9e0df6aeba7dc12e9138305a2be5dc8c91 (patch)
tree9e30532dacf7f99cbac1fe56eb2115a648827b54
parentd9dfd8a31a97150d8974933ad22671b8591fc4bc (diff)
downloadmu-bfc5fe9e0df6aeba7dc12e9138305a2be5dc8c91.tar.gz
358 - start of 'sizeof' support for arrays
-rw-r--r--mu.arc4
-rw-r--r--mu.arc.t12
2 files changed, 16 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index 5138b6a0..6e59ed1a 100644
--- a/mu.arc
+++ b/mu.arc
@@ -682,6 +682,10 @@
 (def sizeof (x)
   (trace "sizeof" x)
   (point return
+  (when (and (acons x)
+             typeinfo.x!array)
+    (return (+ 1 (* (m `(,v.x integer))
+                    (sizeof typeinfo.x!elem)))))
   (let type (if acons.x ty.x x)
     (assert types*.type "sizeof: no such type @type")
     (if (~or types*.type!record types*.type!array)
diff --git a/mu.arc.t b/mu.arc.t
index c677413d..01e130f1 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -763,6 +763,18 @@
 (if (~is 3 (sizeof '(34 integer-point-pair)))
   (prn "F - 'sizeof' works on record operands with record fields"))
 
+(= memory*.4 23)
+(if (~is 24 (sizeof '(4 integer-array)))
+  (prn "F - 'sizeof' reads array lengths from memory"))
+(= memory*.14 34)
+(= routine* make-routine!foo)
+(if (~is 24 (sizeof '(4 integer-array)))
+  (prn "F - 'sizeof' reads array lengths from memory inside routines"))
+(= rep.routine*!call-stack.0!default-scope 10)
+(= memory*.10 5)  ; bounds check for default-scope
+(if (~is 35 (sizeof '(4 integer-array)))
+  (prn "F - 'sizeof' reads array lengths from memory using default-scope"))
+
 (reset)
 (new-trace "copy-record")
 (add-code