about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-28 16:13:28 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-28 16:13:28 -0800
commit73cff60f2547f006c64bbf75ec359d392c1de866 (patch)
tree6064b44732857a3d349a41327dab65801daa99f8
parentb41babf83f81a10ef82516b9e98c49832a482624 (diff)
downloadmu-73cff60f2547f006c64bbf75ec359d392c1de866.tar.gz
356 - high time 'sizeof' supported operands
-rw-r--r--mu.arc26
-rw-r--r--mu.arc.t9
2 files changed, 23 insertions, 12 deletions
diff --git a/mu.arc b/mu.arc
index 8ff33f5c..5138b6a0 100644
--- a/mu.arc
+++ b/mu.arc
@@ -679,18 +679,20 @@
       (= memory*.Memory-in-use-until c)
       (++ Memory-in-use-until))))
 
-(def sizeof (type)
-  (trace "sizeof" type)
-  (assert types*.type "sizeof: no such type @type")
-  (if (~or types*.type!record types*.type!array)
-        types*.type!size
-      types*.type!record
-        (sum idfn
-          (accum yield
-            (each elem types*.type!elems
-              (yield sizeof.elem))))
-      :else
-        (err "sizeof can't handle @type (arrays require a specific variable)")))
+(def sizeof (x)
+  (trace "sizeof" x)
+  (point return
+  (let type (if acons.x ty.x x)
+    (assert types*.type "sizeof: no such type @type")
+    (if (~or types*.type!record types*.type!array)
+          types*.type!size
+        types*.type!record
+          (sum idfn
+            (accum yield
+              (each elem types*.type!elems
+                (yield sizeof.elem))))
+        :else
+          (err "sizeof can't handle @type (arrays require a specific variable)")))))
 
 ;; desugar structured assembly based on blocks
 
diff --git a/mu.arc.t b/mu.arc.t
index b5133572..c7c4a6c1 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -744,6 +744,15 @@
 (if (~is 3 sizeof!integer-point-pair)
   (prn "F - 'sizeof' works on records with record fields"))
 
+(if (~is 1 (sizeof '(34 integer)))
+  (prn "F - 'sizeof' works on primitive operands"))
+(if (~is 1 (sizeof '(34 integer-address)))
+  (prn "F - 'sizeof' works on address operands"))
+(if (~is 2 (sizeof '(34 integer-boolean-pair)))
+  (prn "F - 'sizeof' works on record operands"))
+(if (~is 3 (sizeof '(34 integer-point-pair)))
+  (prn "F - 'sizeof' works on record operands with record fields"))
+
 (reset)
 (new-trace "copy-record")
 (add-code