diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-17 11:20:53 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-17 15:57:37 -0700 |
commit | 01ce563dfe3e6cf58337708b9dbb60a8a99fa0f2 (patch) | |
tree | 696fce7bb207e77952d10b7358f4ce00faed3874 /022constant.cc | |
parent | dd66068298b0a11f2a1f195376cba98e0c8570b5 (diff) | |
download | mu-01ce563dfe3e6cf58337708b9dbb60a8a99fa0f2.tar.gz |
4262 - literal 'null'
Diffstat (limited to '022constant.cc')
-rw-r--r-- | 022constant.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/022constant.cc b/022constant.cc index 800e1b2b..6fc9a019 100644 --- a/022constant.cc +++ b/022constant.cc @@ -3,6 +3,8 @@ :(before "End Mu Types Initialization") put(Type_ordinal, "literal-boolean", 0); +//: 'true' + :(scenario true) def main [ 1:boolean <- copy true @@ -21,6 +23,8 @@ if (name == "true") { :(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 @@ -36,3 +40,50 @@ if (name == "false") { type = new type_tree("literal-boolean"); set_value(0); } + +//: 'null' + +:(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); + +:(before "End Parsing reagent") +if (name == "null") { + if (type != NULL) { + raise << "'null' is a literal and can't take a type\n" << end(); + return; + } + 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") |