about summary refs log tree commit diff stats
path: root/020run.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 /020run.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 '020run.cc')
-rw-r--r--020run.cc199
1 files changed, 125 insertions, 74 deletions
diff --git a/020run.cc b/020run.cc
index 5d466bbc..aa4513e4 100644
--- a/020run.cc
+++ b/020run.cc
@@ -12,28 +12,43 @@
 //: does nothing, and COPY, which can copy numbers from one memory location to
 //: another. Later layers will add more primitives.
 
-:(scenario copy_literal)
-def main [
-  1:num <- copy 23
-]
-+run: {1: "number"} <- copy {23: "literal"}
-+mem: storing 23 in location 1
-
-:(scenario copy)
-def main [
-  1:num <- copy 23
-  2:num <- copy 1:num
-]
-+run: {2: "number"} <- copy {1: "number"}
-+mem: location 1 is 23
-+mem: storing 23 in location 2
-
-:(scenario copy_multiple)
-def main [
-  1:num, 2:num <- copy 23, 24
-]
-+mem: storing 23 in location 1
-+mem: storing 24 in location 2
+void test_copy_literal() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 23\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "run: {1: \"number\"} <- copy {23: \"literal\"}\n"
+      "mem: storing 23 in location 1\n"
+  );
+}
+
+void test_copy() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 23\n"
+      "  2:num <- copy 1:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "run: {2: \"number\"} <- copy {1: \"number\"}\n"
+      "mem: location 1 is 23\n"
+      "mem: storing 23 in location 2\n"
+  );
+}
+
+void test_copy_multiple() {
+  run(
+      "def main [\n"
+      "  1:num, 2:num <- copy 23, 24\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 23 in location 1\n"
+      "mem: storing 24 in location 2\n"
+  );
+}
 
 :(before "End Types")
 // Book-keeping while running a recipe.
@@ -258,13 +273,13 @@ if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, g
   assert(Num_calls_to_transform_all == 1);
   run_main(argc, argv);
 }
+
 :(code)
 void run_main(int argc, char* argv[]) {
   recipe_ordinal r = get(Recipe_ordinal, "main");
   if (r) run(r);
 }
 
-:(code)
 void load_file_or_directory(string filename) {
   if (is_directory(filename)) {
     load_all(filename);
@@ -272,7 +287,7 @@ void load_file_or_directory(string filename) {
   }
   ifstream fin(filename.c_str());
   if (!fin) {
-    cerr << "no such file '" << filename << "'\n" << end();  // don't raise, just warn. just in case it's just a name for a scenario to run.
+    cerr << "no such file '" << filename << "'\n" << end();  // don't raise, just warn. just in case it's just a name for a test to run.
     return;
   }
   trace(2, "load") << "=== " << filename << end();
@@ -421,60 +436,96 @@ void run(const string& form) {
     run(tmp.front());
 }
 
-:(scenario run_label)
-def main [
-  +foo
-  1:num <- copy 23
-  2:num <- copy 1:num
-]
-+run: {1: "number"} <- copy {23: "literal"}
-+run: {2: "number"} <- copy {1: "number"}
--run: +foo
-
-:(scenario run_dummy)
-def main [
-  _ <- copy 0
-]
-+run: _ <- copy {0: "literal"}
-
-:(scenario run_null)
-def main [
-  1:&:num <- copy null
-]
-
-:(scenario write_to_0_disallowed)
-% Hide_errors = true;
-def main [
-  0:num <- copy 34
-]
--mem: storing 34 in location 0
+void test_run_label() {
+  run(
+      "def main [\n"
+      "  +foo\n"
+      "  1:num <- copy 23\n"
+      "  2:num <- copy 1:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "run: {1: \"number\"} <- copy {23: \"literal\"}\n"
+      "run: {2: \"number\"} <- copy {1: \"number\"}\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("run: +foo");
+}
+
+void test_run_dummy() {
+  run(
+      "def main [\n"
+      "  _ <- copy 0\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "run: _ <- copy {0: \"literal\"}\n"
+  );
+}
+
+void test_run_null() {
+  run(
+      "def main [\n"
+      "  1:&:num <- copy null\n"
+      "]\n"
+  );
+}
+
+void test_write_to_0_disallowed() {
+  Hide_errors = true;
+  run(
+      "def main [\n"
+      "  0:num <- copy 34\n"
+      "]\n"
+  );
+  CHECK_TRACE_DOESNT_CONTAIN("mem: storing 34 in location 0");
+}
 
 //: Mu is robust to various combinations of commas and spaces. You just have
 //: to put spaces around the '<-'.
 
-:(scenario comma_without_space)
-def main [
-  1:num, 2:num <- copy 2,2
-]
-+mem: storing 2 in location 1
-
-:(scenario space_without_comma)
-def main [
-  1:num, 2:num <- copy 2 2
-]
-+mem: storing 2 in location 1
-
-:(scenario comma_before_space)
-def main [
-  1:num, 2:num <- copy 2, 2
-]
-+mem: storing 2 in location 1
-
-:(scenario comma_after_space)
-def main [
-  1:num, 2:num <- copy 2 ,2
-]
-+mem: storing 2 in location 1
+void test_comma_without_space() {
+  run(
+      "def main [\n"
+      "  1:num, 2:num <- copy 2,2\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 2 in location 1\n"
+  );
+}
+
+void test_space_without_comma() {
+  run(
+      "def main [\n"
+      "  1:num, 2:num <- copy 2 2\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 2 in location 1\n"
+  );
+}
+
+void test_comma_before_space() {
+  run(
+      "def main [\n"
+      "  1:num, 2:num <- copy 2, 2\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 2 in location 1\n"
+  );
+}
+
+void test_comma_after_space() {
+  run(
+      "def main [\n"
+      "  1:num, 2:num <- copy 2 ,2\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 2 in location 1\n"
+  );
+}
 
 //:: Counters for trying to understand where Mu programs are spending their
 //:: time.