diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
commit | 2a4088119cf41175457414dfa59bd4064b8f0562 (patch) | |
tree | 64fe184e399f9870ebd481a90eec34d51e5dff68 /archive/1.vm/059to_text.mu | |
parent | 23fd294d85959c6b476bcdc35ed6ad508cc99b8f (diff) | |
download | mu-2a4088119cf41175457414dfa59bd4064b8f0562.tar.gz |
5852
Diffstat (limited to 'archive/1.vm/059to_text.mu')
-rw-r--r-- | archive/1.vm/059to_text.mu | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/archive/1.vm/059to_text.mu b/archive/1.vm/059to_text.mu new file mode 100644 index 00000000..d45afb0a --- /dev/null +++ b/archive/1.vm/059to_text.mu @@ -0,0 +1,48 @@ +# A couple of variants of 'to-text' that we'll use implicitly in stashes (see +# later layers). +# +# Mu code might specialize them to be smarter, but I don't anticipate any need +# beyond specializing 'to-text' itself. + +# 'shorter' variant of to-text, when you want to enable some sort of trimming +# define it to be identical to 'to-text' by default +def to-text-line x:_elem -> y:text [ + local-scope + load-inputs + y <- to-text x +] + +# variant for arrays (since we can't pass them around otherwise) +def array-to-text-line x:&:@:_elem -> y:text [ + local-scope + load-inputs + y <- to-text *x +] + +scenario to-text-line-early-warning-for-static-dispatch [ + x:text <- to-text-line 34 + # just ensure there were no errors +] + +scenario array-to-text-line-early-warning-for-static-dispatch [ + n:&:@:num <- new number:type, 3 + x:text <- array-to-text-line n + # just ensure there were no errors +] + +# finally, a specialization for single characters +def to-text c:char -> y:text [ + local-scope + load-inputs + y <- new character:type, 1/capacity + *y <- put-index *y, 0, c +] + +scenario character-to-text [ + 1:char <- copy 111/o + 2:text <- to-text 1:char + 3:@:char <- copy *2:text + memory-should-contain [ + 3:array:character <- [o] + ] +] |