about summary refs log tree commit diff stats
path: root/022constant.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-17 00:05:38 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-17 00:29:22 -0700
commitdd66068298b0a11f2a1f195376cba98e0c8570b5 (patch)
tree06696728fd65cdf38a2ac571943e130e9d60c333 /022constant.cc
parentb89b822439f47a490a1b764e14a1ed1b73059cba (diff)
downloadmu-dd66068298b0a11f2a1f195376cba98e0c8570b5.tar.gz
4261 - start using literals for 'true' and 'false'
They uncovered one bug: in edit/003-shortcuts.mu
  <scroll-down> was returning 0 for an address in one place where I
  thought it was returning 0 for a boolean.

Now we've eliminated this bad interaction between tangling and punning
literals.
Diffstat (limited to '022constant.cc')
-rw-r--r--022constant.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/022constant.cc b/022constant.cc
new file mode 100644
index 00000000..800e1b2b
--- /dev/null
+++ b/022constant.cc
@@ -0,0 +1,38 @@
+//: A few literal constants.
+
+:(before "End Mu Types Initialization")
+put(Type_ordinal, "literal-boolean", 0);
+
+:(scenario true)
+def main [
+  1:boolean <- copy true
+]
++mem: storing 1 in location 1
+
+:(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);
+}
+:(before "End Literal types_match Special-cases")
+if (is_mu_boolean(to)) return from.name == "false" || from.name == "true";
+
+:(scenario false)
+def main [
+  1:boolean <- copy false
+]
++mem: storing 0 in location 1
+
+:(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);
+}