diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-10-24 11:38:02 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-10-24 11:38:02 -0700 |
commit | b046ed735b48cef1c41656ba6307abbb9ec33e70 (patch) | |
tree | dda5f015d5740c9053594a2ab2a4fb8364bf2600 /mu.arc.t | |
parent | 4a0751d80b8b4ab9832a7b35ea796ceca8a0358b (diff) | |
download | mu-b046ed735b48cef1c41656ba6307abbb9ec33e70.tar.gz |
156 - new primitive for lifting into tagged-types: 'save-type'
Diffstat (limited to 'mu.arc.t')
-rw-r--r-- | mu.arc.t | 16 |
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 |