4263
Implement literal constants before type abbreviations, reducing some unnecessary tangling.
This commit is contained in:
parent
01ce563dfe
commit
92a3d0824b
|
@ -1,5 +1,7 @@
|
|||
//: A few literal constants.
|
||||
|
||||
:(scenarios load) // use 'load' instead of 'run' in all scenarios in this layer
|
||||
|
||||
:(before "End Mu Types Initialization")
|
||||
put(Type_ordinal, "literal-boolean", 0);
|
||||
|
||||
|
@ -9,7 +11,7 @@ put(Type_ordinal, "literal-boolean", 0);
|
|||
def main [
|
||||
1:boolean <- copy true
|
||||
]
|
||||
+mem: storing 1 in location 1
|
||||
+parse: ingredient: {true: "literal-boolean"}
|
||||
|
||||
:(before "End Parsing reagent")
|
||||
if (name == "true") {
|
||||
|
@ -20,8 +22,6 @@ if (name == "true") {
|
|||
type = new type_tree("literal-boolean");
|
||||
set_value(1);
|
||||
}
|
||||
:(before "End Literal types_match Special-cases")
|
||||
if (is_mu_boolean(to)) return from.name == "false" || from.name == "true";
|
||||
|
||||
//: 'false'
|
||||
|
||||
|
@ -29,7 +29,7 @@ if (is_mu_boolean(to)) return from.name == "false" || from.name == "true";
|
|||
def main [
|
||||
1:boolean <- copy false
|
||||
]
|
||||
+mem: storing 0 in location 1
|
||||
+parse: ingredient: {false: "literal-boolean"}
|
||||
|
||||
:(before "End Parsing reagent")
|
||||
if (name == "false") {
|
||||
|
@ -43,20 +43,14 @@ if (name == "false") {
|
|||
|
||||
//: 'null'
|
||||
|
||||
:(before "End Mu Types Initialization")
|
||||
put(Type_ordinal, "literal-address", 0);
|
||||
|
||||
:(scenario null)
|
||||
def main [
|
||||
1:address:number <- copy null
|
||||
]
|
||||
+mem: storing 0 in location 1
|
||||
|
||||
:(scenario null_has_wildcard_type)
|
||||
def main [
|
||||
1:address:boolean <- copy null
|
||||
]
|
||||
+mem: storing 0 in location 1
|
||||
|
||||
:(before "End Mu Types Initialization")
|
||||
put(Type_ordinal, "literal-address", 0);
|
||||
+parse: ingredient: {null: "literal-address"}
|
||||
|
||||
:(before "End Parsing reagent")
|
||||
if (name == "null") {
|
||||
|
@ -67,23 +61,3 @@ if (name == "null") {
|
|||
type = new type_tree("literal-address");
|
||||
set_value(0);
|
||||
}
|
||||
|
||||
:(before "End Literal->Address types_match(from) Special-cases")
|
||||
// allow writing null to any address
|
||||
if (from.name == "null") return true;
|
||||
|
||||
//: scenarios for type abbreviations that we couldn't write until now
|
||||
|
||||
:(scenario type_abbreviation_for_compound)
|
||||
type foo = address:number
|
||||
def main [
|
||||
1:foo <- copy null
|
||||
]
|
||||
+transform: product type after expanding abbreviations: ("address" "number")
|
||||
|
||||
:(scenario use_type_abbreviations_when_declaring_type_abbreviations)
|
||||
type foo = &:num
|
||||
def main [
|
||||
1:foo <- copy null
|
||||
]
|
||||
+transform: product type after expanding abbreviations: ("address" "number")
|
|
@ -90,6 +90,13 @@ type foo = bar
|
|||
type foo = baz
|
||||
+error: 'type' conflict: 'foo' defined as both 'bar' and 'baz'
|
||||
|
||||
:(scenario type_abbreviation_for_compound)
|
||||
type foo = address:number
|
||||
def main [
|
||||
1:foo <- copy null
|
||||
]
|
||||
+transform: product type after expanding abbreviations: ("address" "number")
|
||||
|
||||
//: cleaning up type abbreviations between tests and before exiting
|
||||
|
||||
:(before "End save_snapshots")
|
||||
|
@ -122,6 +129,13 @@ put(Type_abbreviations, "num", new_type_tree("number"));
|
|||
put(Type_abbreviations, "bool", new_type_tree("boolean"));
|
||||
put(Type_abbreviations, "char", new_type_tree("character"));
|
||||
|
||||
:(scenario use_type_abbreviations_when_declaring_type_abbreviations)
|
||||
type foo = &:num
|
||||
def main [
|
||||
1:foo <- copy null
|
||||
]
|
||||
+transform: product type after expanding abbreviations: ("address" "number")
|
||||
|
||||
//:: Expand type aliases before running.
|
||||
//: We'll do this in a transform so that we don't need to define abbreviations
|
||||
//: before we use them.
|
|
@ -103,18 +103,12 @@ bool types_match(const reagent& to, const reagent& from) {
|
|||
if (is_mu_array(to)) return false;
|
||||
// End Matching Types For Literal(to)
|
||||
if (!to.type) return false;
|
||||
if (is_mu_address(to)) return types_match_literal_to_address(from);
|
||||
// End Literal types_match Special-cases
|
||||
if (is_mu_address(to)) return from.name == "null";
|
||||
return size_of(to) == 1; // literals are always scalars
|
||||
}
|
||||
return types_strictly_match(to, from);
|
||||
}
|
||||
|
||||
bool types_match_literal_to_address(const reagent& from) {
|
||||
// End Literal->Address types_match(from) Special-cases
|
||||
return false;
|
||||
}
|
||||
|
||||
//: copy arguments for later layers
|
||||
bool types_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from) {
|
||||
// End Preprocess types_strictly_match(reagent to, reagent from)
|
||||
|
|
Loading…
Reference in New Issue