about summary refs log tree commit diff stats
path: root/mu.arc.t
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-24 11:38:02 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-24 11:38:02 -0700
commitb046ed735b48cef1c41656ba6307abbb9ec33e70 (patch)
treedda5f015d5740c9053594a2ab2a4fb8364bf2600 /mu.arc.t
parent4a0751d80b8b4ab9832a7b35ea796ceca8a0358b (diff)
downloadmu-b046ed735b48cef1c41656ba6307abbb9ec33e70.tar.gz
156 - new primitive for lifting into tagged-types: 'save-type'
Diffstat (limited to 'mu.arc.t')
-rw-r--r--mu.arc.t16
1 files changed, 15 insertions, 1 deletions
diff --git a/mu.arc.t b/mu.arc.t
index c17f248d..ccd325de 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -638,7 +638,11 @@
 ; A special kind of record is the 'tagged type'. It lets us represent
 ; dynamically typed values, which save type information in memory rather than
 ; in the code to use them. This will let us do things like create heterogenous
-; lists containing both integers and strings.
+; lists containing both integers and strings. Tagged values admit two
+; operations:
+;
+;   'save-type' - turns a regular value into a tagged-value of the appropriate type
+;   'maybe-coerce' - turns a tagged value into a regular value if the type matches
 
 (reset)
 (new-trace "tagged-value")
@@ -667,6 +671,16 @@
   (prn "F - 'maybe-coerce' doesn't copy value when type tag doesn't match"))
 
 (reset)
+(new-trace "save-type")
+(add-fns
+  '((main
+      ((1 tagged-value) <- save-type (34 integer-address)))))  ; pointer to nowhere
+(run 'main)
+;? (prn memory*)
+(if (~iso memory* (obj  1 'integer-address  2 34))
+  (prn "F - 'save-type' saves the type of a value at runtime, turning it into a tagged-value"))
+
+(reset)
 (new-trace "new-tagged-value")
 ;? (set dump-trace*)
 (add-fns
a89c9bb0154137a0d40731c035d'>^
ddf828fb ^



ddf828fb ^
ddf828fb ^
98bca305 ^
b5393406 ^
ddf828fb ^

86594dde ^


ddf828fb ^
86594dde ^



4e01caf1 ^
86594dde ^

ddf828fb ^
86594dde ^
98bca305 ^
d3eff0a9 ^
86594dde ^






ddf828fb ^
86594dde ^
98bca305 ^
ddf828fb ^
86594dde ^

ddf828fb ^
86594dde ^
91f4dcab ^







86594dde ^



98bca305 ^
ddf828fb ^
86594dde ^
ea87d005 ^
33cb688a ^



ddf828fb ^
b5393406 ^
586f0006 ^


e8bab380 ^

ea87d005 ^
d6e2900a ^
586f0006 ^


d6e2900a ^
586f0006 ^
ddf828fb ^
417c594f ^
41df56be ^
ea87d005 ^
ddf828fb ^

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
84
85
86
87
88
89
90
91
92
93