about summary refs log tree commit diff stats
path: root/041jump_target.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-03-12 18:56:55 -0700
committerKartik Agaram <vc@akkartik.com>2019-03-12 19:14:12 -0700
commit4a943d4ed313eff001504c2b5c472266e86a38af (patch)
treea5757233a8c81b303a808f251180c7344071ed51 /041jump_target.cc
parent43711b0e9f18e0225ce14687fb6ea0902aa6fc61 (diff)
downloadmu-4a943d4ed313eff001504c2b5c472266e86a38af.tar.gz
5001 - drop the :(scenario) DSL
I've been saying for a while[1][2][3] that adding extra abstractions makes
things harder for newcomers, and adding new notations doubly so. And then
I notice this DSL in my own backyard. Makes me feel like a hypocrite.

[1] https://news.ycombinator.com/item?id=13565743#13570092
[2] https://lobste.rs/s/to8wpr/configuration_files_are_canary_warning
[3] https://lobste.rs/s/mdmcdi/little_languages_by_jon_bentley_1986#c_3miuf2

The implementation of the DSL was also highly hacky:

a) It was happening in the tangle/ tool, but was utterly unrelated to tangling
layers.

b) There were several persnickety constraints on the different kinds of
lines and the specific order they were expected in. I kept finding bugs
where the translator would silently do the wrong thing. Or the error messages
sucked, and readers may be stuck looking at the generated code to figure
out what happened. Fixing error messages would require a lot more code,
which is one of my arguments against DSLs in the first place: they may
be easy to implement, but they're hard to design to go with the grain of
the underlying platform. They require lots of iteration. Is that effort
worth prioritizing in this project?

On the other hand, the DSL did make at least some readers' life easier,
the ones who weren't immediately put off by having to learn a strange syntax.
There were fewer quotes to parse, fewer backslash escapes.

Anyway, since there are also people who dislike having to put up with strange
syntaxes, we'll call that consideration a wash and tear this DSL out.

---

This commit was sheer drudgery. Hopefully it won't need to be redone with
a new DSL because I grow sick of backslashes.
Diffstat (limited to '041jump_target.cc')
-rw-r--r--041jump_target.cc211
1 files changed, 124 insertions, 87 deletions
diff --git a/041jump_target.cc b/041jump_target.cc
index d8eaf68a..ec7adede 100644
--- a/041jump_target.cc
+++ b/041jump_target.cc
@@ -14,13 +14,16 @@ bool is_jump_target(const string& label) {
   return is_label_word(label);
 }
 
-:(scenario jump_to_label)
-def main [
-  jump +target:label
-  1:num <- copy 0
-  +target
-]
--mem: storing 0 in location 1
+void test_jump_to_label() {
+  run(
+      "def main [\n"
+      "  jump +target:label\n"
+      "  1:num <- copy 0\n"
+      "  +target\n"
+      "]\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 0 in location 1");
+}
 
 :(before "End Mu Types Initialization")
 put(Type_ordinal, "label", 0);
@@ -94,90 +97,124 @@ void replace_offset(reagent& x, /*const*/ map<string, int>& offset, const int cu
   x.set_value(get(offset, x.name) - current_offset);
 }
 
-:(scenario break_to_label)
-def main [
-  {
-    {
-      break +target:label
-      1:num <- copy 0
-    }
-  }
-  +target
-]
--mem: storing 0 in location 1
+void test_break_to_label() {
+  run(
+      "def main [\n"
+      "  {\n"
+      "    {\n"
+      "      break +target:label\n"
+      "      1:num <- copy 0\n"
+      "    }\n"
+      "  }\n"
+      "  +target\n"
+      "]\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 0 in location 1");
+}
 
-:(scenario jump_if_to_label)
-def main [
-  {
-    {
-      jump-if 1, +target:label
-      1:num <- copy 0
-    }
-  }
-  +target
-]
--mem: storing 0 in location 1
+void test_jump_if_to_label() {
+  run(
+      "def main [\n"
+      "  {\n"
+      "    {\n"
+      "      jump-if 1, +target:label\n"
+      "      1:num <- copy 0\n"
+      "    }\n"
+      "  }\n"
+      "  +target\n"
+      "]\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 0 in location 1");
+}
 
-:(scenario loop_unless_to_label)
-def main [
-  {
-    {
-      loop-unless 0, +target:label  # loop/break with a label don't care about braces
-      1:num <- copy 0
-    }
-  }
-  +target
-]
--mem: storing 0 in location 1
+void test_loop_unless_to_label() {
+  run(
+      "def main [\n"
+      "  {\n"
+      "    {\n"
+      "      loop-unless 0, +target:label\n"  // loop/break with a label don't care about braces
+      "      1:num <- copy 0\n"
+      "    }\n"
+      "  }\n"
+      "  +target\n"
+      "]\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 0 in location 1");
+}
 
-:(scenario jump_runs_code_after_label)
-def main [
-  # first a few lines of padding to exercise the offset computation
-  1:num <- copy 0
-  2:num <- copy 0
-  3:num <- copy 0
-  jump +target:label
-  4:num <- copy 0
-  +target
-  5:num <- copy 0
-]
-+mem: storing 0 in location 5
--mem: storing 0 in location 4
+void test_jump_runs_code_after_label() {
+  run(
+      "def main [\n"
+      // first a few lines of padding to exercise the offset computation
+      "  1:num <- copy 0\n"
+      "  2:num <- copy 0\n"
+      "  3:num <- copy 0\n"
+      "  jump +target:label\n"
+      "  4:num <- copy 0\n"
+      "  +target\n"
+      "  5:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 5\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 0 in location 4");
+}
 
-:(scenario jump_fails_without_target)
-% Hide_errors = true;
-def main [
-  jump
-]
-+error: main: 'jump' expects an ingredient but got 0
+void test_jump_fails_without_target() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      "  jump\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: main: 'jump' expects an ingredient but got 0\n"
+  );
+}
 
-:(scenario jump_fails_without_target_2)
-% Hide_errors = true;
-def main [
-  jump-if true
-]
-+error: main: 'jump-if true' expects 2 ingredients but got 1
+void test_jump_fails_without_target_2() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      "  jump-if true\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: main: 'jump-if true' expects 2 ingredients but got 1\n"
+  );
+}
 
-:(scenario recipe_fails_on_duplicate_jump_target)
-% Hide_errors = true;
-def main [
-  +label
-  1:num <- copy 0
-  +label
-  2:num <- copy 0
-]
-+error: main: duplicate label '+label'
+void test_recipe_fails_on_duplicate_jump_target() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      "  +label\n"
+      "  1:num <- copy 0\n"
+      "  +label\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: main: duplicate label '+label'\n"
+  );
+}
 
-:(scenario jump_ignores_nontarget_label)
-% Hide_errors = true;
-def main [
-  # first a few lines of padding to exercise the offset computation
-  1:num <- copy 0
-  2:num <- copy 0
-  3:num <- copy 0
-  jump $target:label
-  4:num <- copy 0
-  $target
-  5:num <- copy 0
-]
-+error: main: can't jump to label '$target'
+void test_jump_ignores_nontarget_label() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      // first a few lines of padding to exercise the offset computation
+      "  1:num <- copy 0\n"
+      "  2:num <- copy 0\n"
+      "  3:num <- copy 0\n"
+      "  jump $target:label\n"
+      "  4:num <- copy 0\n"
+      "  $target\n"
+      "  5:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: main: can't jump to label '$target'\n"
+  );
+}