diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-17 16:10:00 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-17 16:10:00 -0700 |
commit | 92a3d0824b37e564f3d5bb7e042f97f991f25416 (patch) | |
tree | b4a8f79805307ed1a1d9428a184fd4a633f15054 /018constant.cc | |
parent | 01ce563dfe3e6cf58337708b9dbb60a8a99fa0f2 (diff) | |
download | mu-92a3d0824b37e564f3d5bb7e042f97f991f25416.tar.gz |
4263
Implement literal constants before type abbreviations, reducing some unnecessary tangling.
Diffstat (limited to '018constant.cc')
-rw-r--r-- | 018constant.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/018constant.cc b/018constant.cc new file mode 100644 index 00000000..97239bbe --- /dev/null +++ b/018constant.cc @@ -0,0 +1,63 @@ +//: 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); + +//: 'true' + +:(scenario true) +def main [ + 1:boolean <- copy true +] ++parse: ingredient: {true: "literal-boolean"} + +:(before "End Parsing reagent") +if (name == "true") { + if (type != NULL) { + raise << "'true' is a literal and can't take a type\n" << end(); + return; + } + type = new type_tree("literal-boolean"); + set_value(1); +} + +//: 'false' + +:(scenario false) +def main [ + 1:boolean <- copy false +] ++parse: ingredient: {false: "literal-boolean"} + +:(before "End Parsing reagent") +if (name == "false") { + if (type != NULL) { + raise << "'false' is a literal and can't take a type\n" << end(); + return; + } + type = new type_tree("literal-boolean"); + set_value(0); +} + +//: 'null' + +:(before "End Mu Types Initialization") +put(Type_ordinal, "literal-address", 0); + +:(scenario null) +def main [ + 1:address:number <- copy null +] ++parse: ingredient: {null: "literal-address"} + +:(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); +} |