about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-07 11:50:41 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-07 11:50:41 -0800
commit0ecba1bcb1440d27d1c9335491d77981d611e600 (patch)
tree9e595f3e6c74b448e3c8bf30b6cb36d66a822ba1
parent55cf3fb58acb70494664c5d0bc5d63bf993b0b7b (diff)
downloadmu-0ecba1bcb1440d27d1c9335491d77981d611e600.tar.gz
250 - experimental support for _ oarg
This radically overhauls our assumption that args must always be lists,
so we're probably missing things. Where we do, more tests are required.

Only important trace change: .traces/dummy-oarg
-rw-r--r--mu.arc33
-rw-r--r--mu.arc.t11
2 files changed, 33 insertions, 11 deletions
diff --git a/mu.arc b/mu.arc
index 57bcfe7b..e8e6a048 100644
--- a/mu.arc
+++ b/mu.arc
@@ -542,8 +542,9 @@
                         (let (caller-oargs _ _)  (parse-instr (body.routine* pc.routine*))
                           (trace "reply" arg " " caller-oargs)
                           (each (dest val)  (zip caller-oargs results)
-                            (trace "reply" val " => " dest)
-                            (setm dest val)))
+                            (unless (is dest '_)
+                              (trace "reply" val " => " dest)
+                              (setm dest val))))
                         (++ pc.routine*)
                         (while (>= pc.routine* (len body.routine*))
                           (pop-stack routine*)
@@ -565,7 +566,8 @@
 ;?               (prn "store: " tmp " " oarg)
               (if (acons tmp)
                 (for i 0 (< i (min len.tmp len.oarg)) ++.i
-                  (setm oarg.i tmp.i))
+                  (unless (is oarg.i '_)
+                    (setm oarg.i tmp.i)))
                 (when oarg  ; must be a list
                   (trace "run" "writing to oarg " tmp " => " oarg.0)
                   (setm oarg.0 tmp)))
@@ -701,17 +703,21 @@
          isa-field  (table))
     (let idx 1
       (each instr instrs
+        (trace "cn0" instr " " canon.offset " " canon.isa-field)
         (let (oargs op args)  (parse-instr instr)
           (if (in op 'get 'get-address)
             (with (basetype  (typeinfo args.0)
                    field  (v args.1))
+              (trace "cn0" "field-access " field)
               ; todo: need to rename args.0 as well?
               (when (pos 'deref (metadata args.0))
+                (trace "cn0" "field-access deref")
                 (assert basetype!address "@args.0 requests deref, but it's not an address of a record")
                 (= basetype (types* basetype!elem)))
               (when (isa field 'sym)
                 (assert (or (~offset field) isa-field.field) "field @args.1 is also a variable")
                 (when (~offset field)
+                  (trace "cn0" "new field; computing offset")
                   (assert basetype!fields "no field names available for @instr")
                   (iflet idx (pos field basetype!fields)
                     (do (set isa-field.field)
@@ -720,24 +726,29 @@
             (each arg args
               (assert (~isa-field v.arg) "arg @arg is also a field name")
               (when (maybe-add arg offset idx)
-                (err "use before set: @arg")
-                (++ idx (sizeof ty.arg)))))
+                (err "use before set: @arg"))))
           (each arg oargs
-            (assert (~isa-field v.arg) "oarg @arg is also a field name")
-            (when (maybe-add arg offset idx)
-              (++ idx (sizeof ty.arg)))))))
+            (trace "cn0" "checking " arg)
+            (unless (is arg '_)
+              (assert (~isa-field v.arg) "oarg @arg is also a field name")
+              (when (maybe-add arg offset idx)
+                (trace "cn0" "location for arg " arg ": " idx)
+                (++ idx (sizeof ty.arg))))))))
+    (trace "cn1" "update names " canon.offset " " canon.isa-field)
     (each instr instrs
       (let (oargs op args)  (parse-instr instr)
         (each arg args
-          (when (offset v.arg)
+          (when (and acons.arg (offset v.arg))
             (zap offset v.arg)))
         (each arg oargs
-          (when (offset v.arg)
+          (when (and acons.arg (offset v.arg))
             (zap offset v.arg)))))
     instrs))
 
 (def maybe-add (arg offset idx)
-  (when (and (~in ty.arg 'literal 'offset 'fn)
+  (trace "maybe-add" arg)
+  (when (and (~is arg '_)
+             (~in ty.arg 'literal 'offset 'fn)
              (~offset v.arg)
              (isa v.arg 'sym)
              (~in v.arg 'nil 'default-scope)
diff --git a/mu.arc.t b/mu.arc.t
index 1da8ac6d..70a38f4d 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -216,6 +216,17 @@
 (if (~iso memory* (obj 1 3  2 5))
   (prn "F - 'idiv' performs integer division, returning quotient and remainder"))
 
+(reset)
+(new-trace "dummy-oarg")
+;? (set dump-trace*)
+(add-fns
+  '((main
+      (_ (2 integer) <- idiv (23 literal) (6 literal)))))
+(run 'main)
+(if (~iso memory* (obj 2 5))
+  (prn "F - '_' oarg can ignore some results"))
+;? (quit)
+
 ; Basic boolean operations: and, or, not
 ; There are easy ways to encode booleans in binary, but we'll skip past those
 ; details for now.
2019-06-12 19:55:28 -0400 committer Ben Morrison <ben@gbmor.dev> 2019-06-12 19:55:28 -0400 updated makefile' href='/gbmor/getwtxt/commit/Makefile?h=v0.4.9&id=96fbc6ec48e0613b0d377fc06376a5a767db4b9c'>96fbc6e ^
69217dd ^
96fbc6e ^


ee0d421 ^
96fbc6e ^

69217dd ^






96fbc6e ^


69217dd ^
96fbc6e ^
be76daa ^

69217dd ^
96fbc6e ^
69217dd ^
96fbc6e ^











f532f49 ^



69217dd ^
96fbc6e ^



be76daa ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83