3343
Reorganize layers a bit so I can add a couple of scenarios testing static dispatch *before* I add `stash` into the mix.
This commit is contained in:
parent
e309b9e82d
commit
db01afa844
|
@ -0,0 +1,23 @@
|
|||
//: Primitive to convert any type to text (array of characters).
|
||||
//: Later layers will allow us to override this to do something smarter for
|
||||
//: specific types.
|
||||
|
||||
:(before "End Primitive Recipe Declarations")
|
||||
TO_TEXT,
|
||||
:(before "End Primitive Recipe Numbers")
|
||||
put(Recipe_ordinal, "to-text", TO_TEXT);
|
||||
:(before "End Primitive Recipe Checks")
|
||||
case TO_TEXT: {
|
||||
if (SIZE(inst.ingredients) != 1) {
|
||||
raise << maybe(get(Recipe, r).name) << "'to-text' requires a single ingredient, but got '" << inst.original_string << "'\n" << end();
|
||||
break;
|
||||
}
|
||||
// can handle any type
|
||||
break;
|
||||
}
|
||||
:(before "End Primitive Recipe Implementations")
|
||||
case TO_TEXT: {
|
||||
products.resize(1);
|
||||
products.at(0).push_back(new_mu_string(print_mu(current_instruction().ingredients.at(0), ingredients.at(0))));
|
||||
break;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
# 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:address:array:character [
|
||||
local-scope
|
||||
load-ingredients
|
||||
y <- to-text x
|
||||
]
|
||||
|
||||
# variant for arrays (since we can't pass them around otherwise)
|
||||
def array-to-text-line x:address:array:_elem -> y:address:array:character [
|
||||
local-scope
|
||||
load-ingredients
|
||||
y <- to-text *x
|
||||
]
|
||||
|
||||
scenario to-text-line-early-warning-for-static-dispatch [
|
||||
x:address:array:character <- to-text-line 34
|
||||
# just ensure there were no errors
|
||||
]
|
||||
|
||||
scenario array-to-text-line-early-warning-for-static-dispatch [
|
||||
n:address:array:number <- new number:type, 3
|
||||
x:address:array:character <- array-to-text-line n
|
||||
# just ensure there were no errors
|
||||
]
|
15
061text.mu
15
061text.mu
|
@ -1,21 +1,6 @@
|
|||
# Some useful helpers for dealing with text (arrays of characters)
|
||||
type text = address:array:character
|
||||
|
||||
# to-text-line gets called implicitly in various places
|
||||
# define it to be identical to 'to-text' by default
|
||||
def to-text-line x:_elem -> y:address:array:character [
|
||||
local-scope
|
||||
load-ingredients
|
||||
y <- to-text x
|
||||
]
|
||||
|
||||
# variant for arrays (since we can't pass them around otherwise)
|
||||
def array-to-text-line x:address:array:_elem -> y:address:array:character [
|
||||
local-scope
|
||||
load-ingredients
|
||||
y <- to-text *x
|
||||
]
|
||||
|
||||
def equal a:text, b:text -> result:boolean [
|
||||
local-scope
|
||||
load-ingredients
|
||||
|
|
|
@ -144,23 +144,3 @@ recipe main [
|
|||
stash x
|
||||
]
|
||||
+app: 34 35
|
||||
|
||||
:(before "End Primitive Recipe Declarations")
|
||||
TO_TEXT,
|
||||
:(before "End Primitive Recipe Numbers")
|
||||
put(Recipe_ordinal, "to-text", TO_TEXT);
|
||||
:(before "End Primitive Recipe Checks")
|
||||
case TO_TEXT: {
|
||||
if (SIZE(inst.ingredients) != 1) {
|
||||
raise << maybe(get(Recipe, r).name) << "'to-text' requires a single ingredient, but got '" << inst.original_string << "'\n" << end();
|
||||
break;
|
||||
}
|
||||
// can handle any type
|
||||
break;
|
||||
}
|
||||
:(before "End Primitive Recipe Implementations")
|
||||
case TO_TEXT: {
|
||||
products.resize(1);
|
||||
products.at(0).push_back(new_mu_string(print_mu(current_instruction().ingredients.at(0), ingredients.at(0))));
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue