about summary refs log tree commit diff stats
path: root/mu.arc.t
diff options
context:
space:
mode:
Diffstat (limited to 'mu.arc.t')
-rw-r--r--mu.arc.t128
1 files changed, 61 insertions, 67 deletions
diff --git a/mu.arc.t b/mu.arc.t
index 4be95dcc..f7b77b28 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1137,111 +1137,105 @@
 (if (~iso memory* (obj 1 4  2 4  3 nil  4 34))
   (prn "F - continue might never trigger"))
 
-; 'type' and 'otype' let us create generic functions that run different code
-; based on what args the caller provides, or what oargs the caller expects.
-;
-; These operations are almost certainly bad ideas; they violate our constraint
-; of easily assembling down to native code. We'll eventually switch to dynamic
-; typing with tagged-values.
+; using tagged-values you can define generic functions that run different code
+; based on the types of their args.
 
 (reset)
-(new-trace "dispatch-otype")
+(new-trace "dispatch-clause")
+;? (set dump-trace*)
 (add-fns
   '((test1
-      ((4 type) <- otype 0)
+      ((4 tagged-value-address) <- arg)
       { begin
-        ((5 boolean) <- eq (4 type) (integer literal))
-        (break-unless (5 boolean))
-        ((6 integer) <- arg)
-        ((7 integer) <- arg)
-        ((8 integer) <- add (6 integer) (7 integer))
+        ((5 integer) (6 boolean) <- maybe-coerce (4 tagged-value-address deref) (integer literal))
+        (break-unless (6 boolean))
+        ((7 tagged-value-address) <- arg)
+        ((8 integer) (9 boolean) <- maybe-coerce (7 tagged-value-address deref) (integer literal))
+        ((9 integer) <- add (5 integer) (8 integer))
+        (reply (9 integer))
       }
-      (reply (8 integer)))
+      (reply (nil literal)))
     (main
-      ((1 integer) <- test1 (1 literal) (3 literal)))))
+      ((1 tagged-value-address) <- new-tagged-value (integer literal) (34 literal))
+      ((2 tagged-value-address) <- new-tagged-value (integer literal) (3 literal))
+      ((3 integer) <- test1 (1 tagged-value-address) (2 tagged-value-address)))))
 (run 'main)
 ;? (prn memory*)
-(if (~iso memory* (obj 1 4
-                         ; add-fn's temporaries
-                         4 'integer  5 t  6 1  7 3  8 4))
+(if (~is memory*.3 37)
   (prn "F - an example function that checks that its oarg is an integer"))
 ;? (quit)
 
 ; todo - test that reply increments pc for caller frame after popping current frame
 
 (reset)
-(new-trace "dispatch-otype-multiple-clauses")
+(new-trace "dispatch-multiple-clauses")
 ;? (set dump-trace*)
 (add-fns
-  '((test-fn
-      ((4 type) <- otype 0)
+  '((test1
+      ((4 tagged-value-address) <- arg)
       { begin
-        ; integer needed? add args
-        ((5 boolean) <- eq (4 type) (integer literal))
-        (break-unless (5 boolean))
-        ((6 integer) <- arg)
-        ((7 integer) <- arg)
-        ((8 integer) <- add (6 integer) (7 integer))
-        (reply (8 integer))
+        ((5 integer) (6 boolean) <- maybe-coerce (4 tagged-value-address deref) (integer literal))
+        (break-unless (6 boolean))
+        ((7 tagged-value-address) <- arg)
+        ((8 integer) (9 boolean) <- maybe-coerce (7 tagged-value-address deref) (integer literal))
+        ((9 integer) <- add (5 integer) (8 integer))
+        (reply (9 integer))
       }
       { begin
-        ; boolean needed? 'or' args
-        ((5 boolean) <- eq (4 type) (boolean literal))
-        (break-unless (5 boolean) (4 offset))
-        ((6 boolean) <- arg)
-        ((7 boolean) <- arg)
-        ((8 boolean) <- or (6 boolean) (7 boolean))
-        (reply (8 boolean))
-      })
+        ((5 boolean) (6 boolean) <- maybe-coerce (4 tagged-value-address deref) (boolean literal))
+        (break-unless (6 boolean))
+        ((7 tagged-value-address) <- arg)
+        ((8 boolean) (9 boolean) <- maybe-coerce (7 tagged-value-address deref) (boolean literal))
+        ((9 boolean) <- or (5 boolean) (8 boolean))
+        (reply (9 boolean))
+      }
+      (reply (nil literal)))
     (main
-      ((1 boolean) <- test-fn (t literal) (t literal)))))
+      ((1 tagged-value-address) <- new-tagged-value (boolean literal) (t literal))
+      ((2 tagged-value-address) <- new-tagged-value (boolean literal) (nil literal))
+      ((3 boolean) <- test1 (1 tagged-value-address) (2 tagged-value-address)))))
 ;? (each stmt function*!test-fn
 ;?   (prn "  " stmt))
 (run 'main)
 ;? (wipe dump-trace*)
 ;? (prn memory*)
-(if (~is memory*.1 t)
+(if (~is memory*.3 t)
   (prn "F - an example function that can do different things (dispatch) based on the type of its args or oargs"))
-(if (~iso memory* (obj 1 t
-                       ; add-fn's temporaries
-                       4 'boolean  5 t  6 t  7 t  8 t))
-  (prn "F - an example function that can do different things (dispatch) based on the type of its args or oargs (internals)"))
 ;? (quit)
 
 (reset)
-(new-trace "dispatch-otype-multiple-calls")
+(new-trace "dispatch-multiple-calls")
 (add-fns
-  '((test-fn
-      ((4 type) <- otype 0)
+  '((test1
+      ((4 tagged-value-address) <- arg)
       { begin
-        ((5 boolean) <- eq (4 type) (integer literal))
-        (break-unless (5 boolean))
-        ((6 integer) <- arg)
-        ((7 integer) <- arg)
-        ((8 integer) <- add (6 integer) (7 integer))
-        (reply (8 integer))
+        ((5 integer) (6 boolean) <- maybe-coerce (4 tagged-value-address deref) (integer literal))
+        (break-unless (6 boolean))
+        ((7 tagged-value-address) <- arg)
+        ((8 integer) (9 boolean) <- maybe-coerce (7 tagged-value-address deref) (integer literal))
+        ((9 integer) <- add (5 integer) (8 integer))
+        (reply (9 integer))
       }
       { begin
-        ((5 boolean) <- eq (4 type) (boolean literal))
-        (break-unless (5 boolean))
-        ((6 boolean) <- arg)
-        ((7 boolean) <- arg)
-        ((8 boolean) <- or (6 boolean) (7 boolean))
-        (reply (8 boolean))
-      })
+        ((5 boolean) (6 boolean) <- maybe-coerce (4 tagged-value-address deref) (boolean literal))
+        (break-unless (6 boolean))
+        ((7 tagged-value-address) <- arg)
+        ((8 boolean) (9 boolean) <- maybe-coerce (7 tagged-value-address deref) (boolean literal))
+        ((9 boolean) <- or (5 boolean) (8 boolean))
+        (reply (9 boolean))
+      }
+      (reply (nil literal)))
     (main
-      ((1 boolean) <- test-fn (t literal) (t literal))
-      ((2 integer) <- test-fn (3 literal) (4 literal)))))
+      ((1 tagged-value-address) <- new-tagged-value (boolean literal) (t literal))
+      ((2 tagged-value-address) <- new-tagged-value (boolean literal) (nil literal))
+      ((3 boolean) <- test1 (1 tagged-value-address) (2 tagged-value-address))
+      ((10 tagged-value-address) <- new-tagged-value (integer literal) (34 literal))
+      ((11 tagged-value-address) <- new-tagged-value (integer literal) (3 literal))
+      ((12 integer) <- test1 (10 tagged-value-address) (11 tagged-value-address)))))
 (run 'main)
 ;? (prn memory*)
-(if (~and (is memory*.1 t) (is memory*.2 7))
+(if (~and (is memory*.3 t) (is memory*.12 37))
   (prn "F - different calls can exercise different clauses of the same function"))
-(if (~iso memory* (obj ; results of first and second calls to test-fn
-                       1 t  2 7
-                       ; temporaries for most recent call to test-fn
-                       4 'integer  5 t  6 3  7 4  8 7))
-  (prn "F - different calls can exercise different clauses of the same function (internals)"))
-
 
 ; A rudimentary memory allocator. Eventually we want to write this in mu.