Skip to content

Commit

Permalink
4263
Browse files Browse the repository at this point in the history
Implement literal constants before type abbreviations, reducing some
unnecessary tangling.
  • Loading branch information
akkartik committed Jun 17, 2018
1 parent 01ce563 commit 92a3d08
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
42 changes: 8 additions & 34 deletions 022constant.cc → 018constant.cc
@@ -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);

Expand All @@ -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") {
Expand All @@ -20,16 +22,14 @@ 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'

:(scenario false)
def main [
1:boolean <- copy false
]
+mem: storing 0 in location 1
+parse: ingredient: {false: "literal-boolean"}

:(before "End Parsing reagent")
if (name == "false") {
Expand All @@ -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") {
Expand All @@ -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")
14 changes: 14 additions & 0 deletions 018type_abbreviations.cc → 019type_abbreviations.cc
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions 021check_instruction.cc
Expand Up @@ -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)
Expand Down

0 comments on commit 92a3d08

Please sign in to comment.