diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-07-27 16:01:55 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-07-27 17:47:59 -0700 |
commit | 6e1eeeebfb453fa7c871869c19375ce60fbd7413 (patch) | |
tree | 539c4a3fdf1756ae79770d5c4aaf6366f1d1525e /archive/2.vm/018constant.cc | |
parent | 8846a7f85cc04b77b2fe8a67b6d317723437b00c (diff) | |
download | mu-6e1eeeebfb453fa7c871869c19375ce60fbd7413.tar.gz |
5485 - promote SubX to top-level
Diffstat (limited to 'archive/2.vm/018constant.cc')
-rw-r--r-- | archive/2.vm/018constant.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/archive/2.vm/018constant.cc b/archive/2.vm/018constant.cc new file mode 100644 index 00000000..bbf3a412 --- /dev/null +++ b/archive/2.vm/018constant.cc @@ -0,0 +1,79 @@ +//: A few literal constants. + +:(before "End Mu Types Initialization") +put(Type_ordinal, "literal-boolean", 0); + +//: 'true' + +:(code) +void test_true() { + load( + "def main [\n" + " 1:boolean <- copy true\n" + "]\n" + ); + CHECK_TRACE_CONTENTS( + "parse: ingredient: {true: \"literal-boolean\"}\n" + ); +} + +:(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' + +:(code) +void test_false() { + load( + "def main [\n" + " 1:boolean <- copy false\n" + "]\n" + ); + CHECK_TRACE_CONTENTS( + "parse: ingredient: {false: \"literal-boolean\"}\n" + ); +} + +:(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); + +:(code) +void test_null() { + load( + "def main [\n" + " 1:address:number <- copy null\n" + "]\n" + ); + CHECK_TRACE_CONTENTS( + "parse: ingredient: {null: \"literal-address\"}\n" + ); +} + +:(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); +} |