2017-09-01 08:50:10 +00:00
|
|
|
# A couple of variants of 'to-text' that we'll use implicitly in stashes (see
|
2016-09-13 04:02:38 +00:00
|
|
|
# later layers).
|
|
|
|
#
|
|
|
|
# Mu code might specialize them to be smarter, but I don't anticipate any need
|
2017-09-01 08:50:10 +00:00
|
|
|
# beyond specializing 'to-text' itself.
|
2016-09-13 04:02:38 +00:00
|
|
|
|
|
|
|
# 'shorter' variant of to-text, when you want to enable some sort of trimming
|
|
|
|
# define it to be identical to 'to-text' by default
|
2016-09-13 07:07:38 +00:00
|
|
|
def to-text-line x:_elem -> y:text [
|
2016-09-13 04:02:38 +00:00
|
|
|
local-scope
|
2017-12-04 07:25:40 +00:00
|
|
|
load-inputs
|
2016-09-13 04:02:38 +00:00
|
|
|
y <- to-text x
|
|
|
|
]
|
|
|
|
|
|
|
|
# variant for arrays (since we can't pass them around otherwise)
|
2016-09-17 20:00:39 +00:00
|
|
|
def array-to-text-line x:&:@:_elem -> y:text [
|
2016-09-13 04:02:38 +00:00
|
|
|
local-scope
|
2017-12-04 07:25:40 +00:00
|
|
|
load-inputs
|
2016-09-13 04:02:38 +00:00
|
|
|
y <- to-text *x
|
|
|
|
]
|
|
|
|
|
|
|
|
scenario to-text-line-early-warning-for-static-dispatch [
|
2016-09-13 07:07:38 +00:00
|
|
|
x:text <- to-text-line 34
|
2016-09-13 04:02:38 +00:00
|
|
|
# just ensure there were no errors
|
|
|
|
]
|
|
|
|
|
|
|
|
scenario array-to-text-line-early-warning-for-static-dispatch [
|
2016-09-17 20:00:39 +00:00
|
|
|
n:&:@:num <- new number:type, 3
|
2016-09-13 07:07:38 +00:00
|
|
|
x:text <- array-to-text-line n
|
2016-09-13 04:02:38 +00:00
|
|
|
# just ensure there were no errors
|
|
|
|
]
|
2016-09-15 20:46:13 +00:00
|
|
|
|
|
|
|
# finally, a specialization for single characters
|
2016-09-17 07:31:55 +00:00
|
|
|
def to-text c:char -> y:text [
|
2016-09-15 20:46:13 +00:00
|
|
|
local-scope
|
2017-12-04 07:25:40 +00:00
|
|
|
load-inputs
|
2016-09-15 20:46:13 +00:00
|
|
|
y <- new character:type, 1/capacity
|
|
|
|
*y <- put-index *y, 0, c
|
|
|
|
]
|
|
|
|
|
|
|
|
scenario character-to-text [
|
2016-09-17 07:31:55 +00:00
|
|
|
1:char <- copy 111/o
|
|
|
|
2:text <- to-text 1:char
|
2016-09-17 20:00:39 +00:00
|
|
|
3:@:char <- copy *2:text
|
2016-09-15 20:46:13 +00:00
|
|
|
memory-should-contain [
|
|
|
|
3:array:character <- [o]
|
|
|
|
]
|
|
|
|
]
|