about summary refs log tree commit diff stats
path: root/052tangle.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 /052tangle.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 '052tangle.cc')
-rw-r--r--052tangle.cc596
1 files changed, 328 insertions, 268 deletions
diff --git a/052tangle.cc b/052tangle.cc
index d7d1ccc3..a5332e1b 100644
--- a/052tangle.cc
+++ b/052tangle.cc
@@ -14,20 +14,25 @@ bool is_waypoint(string label) {
   return *label.begin() == '<' && *label.rbegin() == '>';
 }
 
-:(scenario tangle_before)
-def main [
-  1:num <- copy 0
-  <label1>
-  3:num <- copy 0
-]
-before <label1> [
-  2:num <- copy 0
-]
-+mem: storing 0 in location 1
-+mem: storing 0 in location 2
-+mem: storing 0 in location 3
-# nothing else
-$mem: 3
+void test_tangle_before() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  <label1>\n"
+      "  3:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+      "mem: storing 0 in location 2\n"
+      "mem: storing 0 in location 3\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 3);
+}
 
 //: while loading recipes, load before/after fragments
 
@@ -175,273 +180,328 @@ void check_insert_fragments() {
   }
 }
 
-:(scenario tangle_before_and_after)
-def main [
-  1:num <- copy 0
-  <label1>
-  4:num <- copy 0
-]
-before <label1> [
-  2:num <- copy 0
-]
-after <label1> [
-  3:num <- copy 0
-]
-+mem: storing 0 in location 1
-+mem: storing 0 in location 2
-# label1
-+mem: storing 0 in location 3
-+mem: storing 0 in location 4
-# nothing else
-$mem: 4
+void test_tangle_before_and_after() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  <label1>\n"
+      "  4:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+      "mem: storing 0 in location 2\n"
+      // label1
+      "mem: storing 0 in location 3\n"
+      "mem: storing 0 in location 4\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 4);
+}
 
-:(scenario tangle_ignores_jump_target)
-% Hide_errors = true;
-def main [
-  1:num <- copy 0
-  +label1
-  4:num <- copy 0
-]
-before +label1 [
-  2:num <- copy 0
-]
-+error: can't tangle before non-waypoint +label1
+void test_tangle_ignores_jump_target() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  +label1\n"
+      "  4:num <- copy 0\n"
+      "]\n"
+      "before +label1 [\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: can't tangle before non-waypoint +label1\n"
+  );
+}
 
-:(scenario tangle_keeps_labels_separate)
-def main [
-  1:num <- copy 0
-  <label1>
-  <label2>
-  6:num <- copy 0
-]
-before <label1> [
-  2:num <- copy 0
-]
-after <label1> [
-  3:num <- copy 0
-]
-before <label2> [
-  4:num <- copy 0
-]
-after <label2> [
-  5:num <- copy 0
-]
-+mem: storing 0 in location 1
-+mem: storing 0 in location 2
-# label1
-+mem: storing 0 in location 3
-# 'after' fragments for earlier label always go before 'before' fragments for later label
-+mem: storing 0 in location 4
-# label2
-+mem: storing 0 in location 5
-+mem: storing 0 in location 6
-# nothing else
-$mem: 6
+void test_tangle_keeps_labels_separate() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  <label1>\n"
+      "  <label2>\n"
+      "  6:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 0\n"
+      "]\n"
+      "before <label2> [\n"
+      "  4:num <- copy 0\n"
+      "]\n"
+      "after <label2> [\n"
+      "  5:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+      "mem: storing 0 in location 2\n"
+      // label1
+      "mem: storing 0 in location 3\n"
+      // 'after' fragments for earlier label always go before 'before'
+      // fragments for later label
+      "mem: storing 0 in location 4\n"
+      // label2
+      "mem: storing 0 in location 5\n"
+      "mem: storing 0 in location 6\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 6);
+}
 
-:(scenario tangle_stacks_multiple_fragments)
-def main [
-  1:num <- copy 0
-  <label1>
-  6:num <- copy 0
-]
-before <label1> [
-  2:num <- copy 0
-]
-after <label1> [
-  3:num <- copy 0
-]
-before <label1> [
-  4:num <- copy 0
-]
-after <label1> [
-  5:num <- copy 0
-]
-+mem: storing 0 in location 1
-# 'before' fragments stack in order
-+mem: storing 0 in location 2
-+mem: storing 0 in location 4
-# label1
-# 'after' fragments stack in reverse order
-+mem: storing 0 in location 5
-+mem: storing 0 in location 3
-+mem: storing 0 in location 6
-# nothing else
-$mem: 6
+void test_tangle_stacks_multiple_fragments() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  <label1>\n"
+      "  6:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 0\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  4:num <- copy 0\n"
+      "]\n"
+      "after <label1> [\n"
+      "  5:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+      // 'before' fragments stack in order
+      "mem: storing 0 in location 2\n"
+      "mem: storing 0 in location 4\n"
+      // label1
+      // 'after' fragments stack in reverse order
+      "mem: storing 0 in location 5\n"
+      "mem: storing 0 in location 3\n"
+      "mem: storing 0 in location 6\n"
+  );
+  // nothing
+  CHECK_TRACE_COUNT("mem", 6);
+}
 
-:(scenario tangle_supports_fragments_with_multiple_instructions)
-def main [
-  1:num <- copy 0
-  <label1>
-  6:num <- copy 0
-]
-before <label1> [
-  2:num <- copy 0
-  3:num <- copy 0
-]
-after <label1> [
-  4:num <- copy 0
-  5:num <- copy 0
-]
-+mem: storing 0 in location 1
-+mem: storing 0 in location 2
-+mem: storing 0 in location 3
-# label1
-+mem: storing 0 in location 4
-+mem: storing 0 in location 5
-+mem: storing 0 in location 6
-# nothing else
-$mem: 6
+void test_tangle_supports_fragments_with_multiple_instructions() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 0\n"
+      "  <label1>\n"
+      "  6:num <- copy 0\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 0\n"
+      "  3:num <- copy 0\n"
+      "]\n"
+      "after <label1> [\n"
+      "  4:num <- copy 0\n"
+      "  5:num <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+      "mem: storing 0 in location 2\n"
+      "mem: storing 0 in location 3\n"
+      // label1
+      "mem: storing 0 in location 4\n"
+      "mem: storing 0 in location 5\n"
+      "mem: storing 0 in location 6\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 6);
+}
 
-:(scenario tangle_tangles_into_all_labels_with_same_name)
-def main [
-  1:num <- copy 10
-  <label1>
-  4:num <- copy 10
-  recipe2
-]
-def recipe2 [
-  1:num <- copy 11
-  <label1>
-  4:num <- copy 11
-]
-before <label1> [
-  2:num <- copy 12
-]
-after <label1> [
-  3:num <- copy 12
-]
-+mem: storing 10 in location 1
-+mem: storing 12 in location 2
-# label1
-+mem: storing 12 in location 3
-+mem: storing 10 in location 4
-# recipe2
-+mem: storing 11 in location 1
-+mem: storing 12 in location 2
-# label1
-+mem: storing 12 in location 3
-+mem: storing 11 in location 4
-# nothing else
-$mem: 8
+void test_tangle_tangles_into_all_labels_with_same_name() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  4:num <- copy 10\n"
+      "  recipe2\n"
+      "]\n"
+      "def recipe2 [\n"
+      "  1:num <- copy 11\n"
+      "  <label1>\n"
+      "  4:num <- copy 11\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 12\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      "mem: storing 12 in location 2\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 10 in location 4\n"
+      // recipe2
+      "mem: storing 11 in location 1\n"
+      "mem: storing 12 in location 2\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 11 in location 4\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 8);
+}
 
-:(scenario tangle_tangles_into_all_labels_with_same_name_2)
-def main [
-  1:num <- copy 10
-  <label1>
-  <label1>
-  4:num <- copy 10
-]
-before <label1> [
-  2:num <- copy 12
-]
-after <label1> [
-  3:num <- copy 12
-]
-+mem: storing 10 in location 1
-+mem: storing 12 in location 2
-# label1
-+mem: storing 12 in location 3
-+mem: storing 12 in location 2
-# label1
-+mem: storing 12 in location 3
-+mem: storing 10 in location 4
-# nothing else
-$mem: 6
+void test_tangle_tangles_into_all_labels_with_same_name_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  <label1>\n"
+      "  4:num <- copy 10\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 12\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      "mem: storing 12 in location 2\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 12 in location 2\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 10 in location 4\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 6);
+}
 
-:(scenario tangle_tangles_into_all_labels_with_same_name_3)
-def main [
-  1:num <- copy 10
-  <label1>
-  <foo>
-  4:num <- copy 10
-]
-before <label1> [
-  2:num <- copy 12
-]
-after <label1> [
-  3:num <- copy 12
-]
-after <foo> [
-  <label1>
-]
-+mem: storing 10 in location 1
-+mem: storing 12 in location 2
-# label1
-+mem: storing 12 in location 3
-+mem: storing 12 in location 2
-# foo/label1
-+mem: storing 12 in location 3
-+mem: storing 10 in location 4
-# nothing else
-$mem: 6
+void test_tangle_tangles_into_all_labels_with_same_name_3() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  <foo>\n"
+      "  4:num <- copy 10\n"
+      "]\n"
+      "before <label1> [\n"
+      "  2:num <- copy 12\n"
+      "]\n"
+      "after <label1> [\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+      "after <foo> [\n"
+      "  <label1>\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      "mem: storing 12 in location 2\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 12 in location 2\n"
+      // foo/label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 10 in location 4\n"
+  );
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 6);
+}
 
-:(scenario tangle_handles_jump_target_inside_fragment)
-def main [
-  1:num <- copy 10
-  <label1>
-  4:num <- copy 10
-]
-before <label1> [
-  jump +label2:label
-  2:num <- copy 12
-  +label2
-  3:num <- copy 12
-]
-+mem: storing 10 in location 1
-# label1
-+mem: storing 12 in location 3
-+mem: storing 10 in location 4
-# ignored by jump
--mem: storing 12 in label 2
-# nothing else
-$mem: 3
+void test_tangle_handles_jump_target_inside_fragment() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  4:num <- copy 10\n"
+      "]\n"
+      "before <label1> [\n"
+      "  jump +label2:label\n"
+      "  2:num <- copy 12\n"
+      "  +label2\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 10 in location 4\n"
+  );
+  // ignored by jump
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 12 in label 2");
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 3);
+}
 
-:(scenario tangle_renames_jump_target)
-def main [
-  1:num <- copy 10
-  <label1>
-  +label2
-  4:num <- copy 10
-]
-before <label1> [
-  jump +label2:label
-  2:num <- copy 12
-  +label2  # renamed
-  3:num <- copy 12
-]
-+mem: storing 10 in location 1
-# label1
-+mem: storing 12 in location 3
-+mem: storing 10 in location 4
-# ignored by jump
--mem: storing 12 in label 2
-# nothing else
-$mem: 3
+void test_tangle_renames_jump_target() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  +label2\n"
+      "  4:num <- copy 10\n"
+      "]\n"
+      "before <label1> [\n"
+      "  jump +label2:label\n"
+      "  2:num <- copy 12\n"
+      "  +label2  # renamed\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      // label1
+      "mem: storing 12 in location 3\n"
+      "mem: storing 10 in location 4\n"
+  );
+  // ignored by jump
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 12 in label 2");
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 3);
+}
 
-:(scenario tangle_jump_to_base_recipe)
-def main [
-  1:num <- copy 10
-  <label1>
-  +label2
-  4:num <- copy 10
-]
-before <label1> [
-  jump +label2:label
-  2:num <- copy 12
-  3:num <- copy 12
-]
-+mem: storing 10 in location 1
-# label1
-+mem: storing 10 in location 4
-# ignored by jump
--mem: storing 12 in label 2
--mem: storing 12 in location 3
-# nothing else
-$mem: 2
+void test_tangle_jump_to_base_recipe() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 10\n"
+      "  <label1>\n"
+      "  +label2\n"
+      "  4:num <- copy 10\n"
+      "]\n"
+      "before <label1> [\n"
+      "  jump +label2:label\n"
+      "  2:num <- copy 12\n"
+      "  3:num <- copy 12\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 10 in location 1\n"
+      // label1
+      "mem: storing 10 in location 4\n"
+  );
+  // ignored by jump
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 12 in label 2");
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 12 in location 3");
+  // nothing else
+  CHECK_TRACE_COUNT("mem", 2);
+}
 
 //: ensure that there are no new fragments created for a label after it's already been inserted to
 
-:(code)
 void test_new_fragment_after_tangle() {
   // define a recipe
   load("def foo [\n"