about summary refs log tree commit diff stats
path: root/025compare.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 /025compare.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 '025compare.cc')
-rw-r--r--025compare.cc439
1 files changed, 282 insertions, 157 deletions
diff --git a/025compare.cc b/025compare.cc
index e12fa1dc..bade3c9c 100644
--- a/025compare.cc
+++ b/025compare.cc
@@ -46,37 +46,58 @@ case EQUAL: {
   break;
 }
 
-:(scenario equal)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- equal 1:num, 2:num
-]
-+mem: location 1 is 34
-+mem: location 2 is 33
-+mem: storing 0 in location 3
+:(code)
+void test_equal() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: location 1 is 34\n"
+      "mem: location 2 is 33\n"
+      "mem: storing 0 in location 3\n"
+  );
+}
 
-:(scenario equal_2)
-def main [
-  1:num <- copy 34
-  2:num <- copy 34
-  3:bool <- equal 1:num, 2:num
-]
-+mem: location 1 is 34
-+mem: location 2 is 34
-+mem: storing 1 in location 3
+void test_equal_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 34\n"
+      "  3:bool <- equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: location 1 is 34\n"
+      "mem: location 2 is 34\n"
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario equal_multiple)
-def main [
-  1:bool <- equal 34, 34, 34
-]
-+mem: storing 1 in location 1
+void test_equal_multiple() {
+  run(
+      "def main [\n"
+      "  1:bool <- equal 34, 34, 34\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 1\n"
+  );
+}
 
-:(scenario equal_multiple_2)
-def main [
-  1:bool <- equal 34, 34, 35
-]
-+mem: storing 0 in location 1
+void test_equal_multiple_2() {
+  run(
+      "def main [\n"
+      "  1:bool <- equal 34, 34, 35\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+  );
+}
 
 :(before "End Primitive Recipe Declarations")
 NOT_EQUAL,
@@ -116,25 +137,36 @@ case NOT_EQUAL: {
   break;
 }
 
-:(scenario not_equal)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- not-equal 1:num, 2:num
-]
-+mem: location 1 is 34
-+mem: location 2 is 33
-+mem: storing 1 in location 3
+:(code)
+void test_not_equal() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- not-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: location 1 is 34\n"
+      "mem: location 2 is 33\n"
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario not_equal_2)
-def main [
-  1:num <- copy 34
-  2:num <- copy 34
-  3:bool <- not-equal 1:num, 2:num
-]
-+mem: location 1 is 34
-+mem: location 2 is 34
-+mem: storing 0 in location 3
+void test_not_equal_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 34\n"
+      "  3:bool <- not-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: location 1 is 34\n"
+      "mem: location 2 is 34\n"
+      "mem: storing 0 in location 3\n"
+  );
+}
 
 :(before "End Primitive Recipe Declarations")
 GREATER_THAN,
@@ -175,33 +207,54 @@ case GREATER_THAN: {
   break;
 }
 
-:(scenario greater_than)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- greater-than 1:num, 2:num
-]
-+mem: storing 1 in location 3
+:(code)
+void test_greater_than() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- greater-than 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario greater_than_2)
-def main [
-  1:num <- copy 34
-  2:num <- copy 34
-  3:bool <- greater-than 1:num, 2:num
-]
-+mem: storing 0 in location 3
+void test_greater_than_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 34\n"
+      "  3:bool <- greater-than 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 3\n"
+  );
+}
 
-:(scenario greater_than_multiple)
-def main [
-  1:bool <- greater-than 36, 35, 34
-]
-+mem: storing 1 in location 1
+void test_greater_than_multiple() {
+  run(
+      "def main [\n"
+      "  1:bool <- greater-than 36, 35, 34\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 1\n"
+  );
+}
 
-:(scenario greater_than_multiple_2)
-def main [
-  1:bool <- greater-than 36, 35, 35
-]
-+mem: storing 0 in location 1
+void test_greater_than_multiple_2() {
+  run(
+      "def main [\n"
+      "  1:bool <- greater-than 36, 35, 35\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+  );
+}
 
 :(before "End Primitive Recipe Declarations")
 LESSER_THAN,
@@ -242,34 +295,54 @@ case LESSER_THAN: {
   break;
 }
 
-:(scenario lesser_than)
-def main [
-  1:num <- copy 32
-  2:num <- copy 33
-  3:bool <- lesser-than 1:num, 2:num
-]
-+mem: storing 1 in location 3
-
-:(scenario lesser_than_2)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- lesser-than 1:num, 2:num
-]
-+mem: storing 0 in location 3
+:(code)
+void test_lesser_than() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 32\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- lesser-than 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario lesser_than_multiple)
-def main [
-  1:bool <- lesser-than 34, 35, 36
-]
-+mem: storing 1 in location 1
+void test_lesser_than_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- lesser-than 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 3\n"
+  );
+}
 
-:(scenario lesser_than_multiple_2)
-def main [
-  1:bool <- lesser-than 34, 35, 35
-]
-+mem: storing 0 in location 1
+void test_lesser_than_multiple() {
+  run(
+      "def main [\n"
+      "  1:bool <- lesser-than 34, 35, 36\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 1\n"
+  );
+}
 
+void test_lesser_than_multiple_2() {
+  run(
+      "def main [\n"
+      "  1:bool <- lesser-than 34, 35, 35\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+  );
+}
 :(before "End Primitive Recipe Declarations")
 GREATER_OR_EQUAL,
 :(before "End Primitive Recipe Numbers")
@@ -309,41 +382,67 @@ case GREATER_OR_EQUAL: {
   break;
 }
 
-:(scenario greater_or_equal)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- greater-or-equal 1:num, 2:num
-]
-+mem: storing 1 in location 3
+:(code)
+void test_greater_or_equal() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- greater-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario greater_or_equal_2)
-def main [
-  1:num <- copy 34
-  2:num <- copy 34
-  3:bool <- greater-or-equal 1:num, 2:num
-]
-+mem: storing 1 in location 3
+void test_greater_or_equal_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 34\n"
+      "  3:bool <- greater-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario greater_or_equal_3)
-def main [
-  1:num <- copy 34
-  2:num <- copy 35
-  3:bool <- greater-or-equal 1:num, 2:num
-]
-+mem: storing 0 in location 3
+void test_greater_or_equal_3() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 35\n"
+      "  3:bool <- greater-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 3\n"
+  );
+}
 
-:(scenario greater_or_equal_multiple)
-def main [
-  1:bool <- greater-or-equal 36, 35, 35
-]
-+mem: storing 1 in location 1
+void test_greater_or_equal_multiple() {
+  run(
+      "def main [\n"
+      "  1:bool <- greater-or-equal 36, 35, 35\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 1\n"
+  );
+}
 
-:(scenario greater_or_equal_multiple_2)
-def main [
-  1:bool <- greater-or-equal 36, 35, 36
-]
-+mem: storing 0 in location 1
+void test_greater_or_equal_multiple_2() {
+  run(
+      "def main [\n"
+      "  1:bool <- greater-or-equal 36, 35, 36\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+  );
+}
 
 :(before "End Primitive Recipe Declarations")
 LESSER_OR_EQUAL,
@@ -384,41 +483,67 @@ case LESSER_OR_EQUAL: {
   break;
 }
 
-:(scenario lesser_or_equal)
-def main [
-  1:num <- copy 32
-  2:num <- copy 33
-  3:bool <- lesser-or-equal 1:num, 2:num
-]
-+mem: storing 1 in location 3
+:(code)
+void test_lesser_or_equal() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 32\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- lesser-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario lesser_or_equal_2)
-def main [
-  1:num <- copy 33
-  2:num <- copy 33
-  3:bool <- lesser-or-equal 1:num, 2:num
-]
-+mem: storing 1 in location 3
+void test_lesser_or_equal_2() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 33\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- lesser-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 3\n"
+  );
+}
 
-:(scenario lesser_or_equal_3)
-def main [
-  1:num <- copy 34
-  2:num <- copy 33
-  3:bool <- lesser-or-equal 1:num, 2:num
-]
-+mem: storing 0 in location 3
+void test_lesser_or_equal_3() {
+  run(
+      "def main [\n"
+      "  1:num <- copy 34\n"
+      "  2:num <- copy 33\n"
+      "  3:bool <- lesser-or-equal 1:num, 2:num\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 3\n"
+  );
+}
 
-:(scenario lesser_or_equal_multiple)
-def main [
-  1:bool <- lesser-or-equal 34, 35, 35
-]
-+mem: storing 1 in location 1
+void test_lesser_or_equal_multiple() {
+  run(
+      "def main [\n"
+      "  1:bool <- lesser-or-equal 34, 35, 35\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 1 in location 1\n"
+  );
+}
 
-:(scenario lesser_or_equal_multiple_2)
-def main [
-  1:bool <- lesser-or-equal 34, 35, 34
-]
-+mem: storing 0 in location 1
+void test_lesser_or_equal_multiple_2() {
+  run(
+      "def main [\n"
+      "  1:bool <- lesser-or-equal 34, 35, 34\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "mem: storing 0 in location 1\n"
+  );
+}
 
 :(before "End Primitive Recipe Declarations")
 MAX,