about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/.traces/array_length2
-rw-r--r--cpp/.traces/brace_conversion2
-rw-r--r--cpp/.traces/break_cascading4
-rw-r--r--cpp/.traces/break_cascading24
-rw-r--r--cpp/.traces/break_empty_block2
-rw-r--r--cpp/.traces/break_if4
-rw-r--r--cpp/.traces/break_label2
-rw-r--r--cpp/.traces/break_nested2
-rw-r--r--cpp/.traces/break_nested_degenerate2
-rw-r--r--cpp/.traces/break_nested_degenerate22
-rw-r--r--cpp/.traces/break_unless2
-rw-r--r--cpp/.traces/factorial4
-rw-r--r--cpp/.traces/loop2
-rw-r--r--cpp/.traces/loop_nested2
-rw-r--r--cpp/.traces/loop_unless2
-rw-r--r--cpp/.traces/new4
-rw-r--r--cpp/.traces/new_array4
-rw-r--r--cpp/.traces/new_string2
-rw-r--r--cpp/.traces/string_literal2
-rw-r--r--cpp/.traces/string_literal_nested2
-rw-r--r--cpp/011load11
-rw-r--r--cpp/012transform1
-rw-r--r--cpp/024brace40
-rw-r--r--cpp/026new2
-rw-r--r--cpp/030length2
25 files changed, 76 insertions, 32 deletions
diff --git a/cpp/.traces/array_length b/cpp/.traces/array_length
index c9f0863f..50c80830 100644
--- a/cpp/.traces/array_length
+++ b/cpp/.traces/array_length
@@ -10,7 +10,7 @@ parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "16", value: 0, type: 0, properties: ["16": "literal"]}
 parse/0:   product: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}
-parse/0: instruction: 25
+parse/0: instruction: 31
 parse/0:   ingredient: {name: "1", value: 0, type: 5-1, properties: ["1": "array":"integer"]}
 parse/0:   product: {name: "5", value: 0, type: 1, properties: ["5": "integer"]}
 after-brace/0: recipe main
diff --git a/cpp/.traces/brace_conversion b/cpp/.traces/brace_conversion
index 2db6bee0..455b7cd2 100644
--- a/cpp/.traces/brace_conversion
+++ b/cpp/.traces/brace_conversion
@@ -1,5 +1,5 @@
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
diff --git a/cpp/.traces/break_cascading b/cpp/.traces/break_cascading
index 340589e8..ee835faa 100644
--- a/cpp/.traces/break_cascading
+++ b/cpp/.traces/break_cascading
@@ -2,10 +2,10 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: }
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: }
 brace/0: 100: push (open, 1)
 brace/0: push (close, 3)
diff --git a/cpp/.traces/break_cascading2 b/cpp/.traces/break_cascading2
index 995bda66..c72e2cf6 100644
--- a/cpp/.traces/break_cascading2
+++ b/cpp/.traces/break_cascading2
@@ -5,13 +5,13 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
 parse/0: label: }
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: }
 brace/0: 100: push (open, 2)
 brace/0: push (close, 5)
diff --git a/cpp/.traces/break_empty_block b/cpp/.traces/break_empty_block
index b43601ac..ba91f9b1 100644
--- a/cpp/.traces/break_empty_block
+++ b/cpp/.traces/break_empty_block
@@ -2,7 +2,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: }
 brace/0: 100: push (open, 1)
 brace/0: push (close, 3)
diff --git a/cpp/.traces/break_if b/cpp/.traces/break_if
index 6f8907e7..0b02ca42 100644
--- a/cpp/.traces/break_if
+++ b/cpp/.traces/break_if
@@ -5,14 +5,14 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 25
 parse/0:   ingredient: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
 parse/0: label: }
 parse/0: label: {
-parse/0: instruction: 102
+parse/0: instruction: 24
 parse/0: label: }
 brace/0: 100: push (open, 2)
 brace/0: push (close, 5)
diff --git a/cpp/.traces/break_label b/cpp/.traces/break_label
index c0c939ea..e948e7e7 100644
--- a/cpp/.traces/break_label
+++ b/cpp/.traces/break_label
@@ -2,7 +2,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0:   ingredient: {name: "+foo", value: 0, type: 0, properties: ["+foo": "offset"]}
 parse/0: label: }
 brace/0: 100: push (open, 1)
diff --git a/cpp/.traces/break_nested b/cpp/.traces/break_nested
index 261d39d1..8a2ac302 100644
--- a/cpp/.traces/break_nested
+++ b/cpp/.traces/break_nested
@@ -5,7 +5,7 @@ parse/0: label: {
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: {
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
diff --git a/cpp/.traces/break_nested_degenerate b/cpp/.traces/break_nested_degenerate
index 1838fa75..e68442d3 100644
--- a/cpp/.traces/break_nested_degenerate
+++ b/cpp/.traces/break_nested_degenerate
@@ -5,7 +5,7 @@ parse/0: label: {
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: {
 parse/0: label: }
 parse/0: instruction: 1
diff --git a/cpp/.traces/break_nested_degenerate2 b/cpp/.traces/break_nested_degenerate2
index 17339d4f..2a871e43 100644
--- a/cpp/.traces/break_nested_degenerate2
+++ b/cpp/.traces/break_nested_degenerate2
@@ -5,7 +5,7 @@ parse/0: label: {
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
-parse/0: instruction: 101
+parse/0: instruction: 24
 parse/0: label: {
 parse/0: label: }
 parse/0: label: }
diff --git a/cpp/.traces/break_unless b/cpp/.traces/break_unless
index 605ff6fd..fdff7f87 100644
--- a/cpp/.traces/break_unless
+++ b/cpp/.traces/break_unless
@@ -5,7 +5,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 26
 parse/0:   ingredient: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
diff --git a/cpp/.traces/factorial b/cpp/.traces/factorial
index 050b8bbe..04c1e0ba 100644
--- a/cpp/.traces/factorial
+++ b/cpp/.traces/factorial
@@ -9,7 +9,7 @@ parse/0: instruction: 13
 parse/0:   ingredient: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
 parse/0:   ingredient: {name: "1", value: 0, type: 0, properties: ["1": "literal"]}
 parse/0:   product: {name: "3", value: 0, type: 3, properties: ["3": "boolean"]}
-parse/0: instruction: 101
+parse/0: instruction: 25
 parse/0:   ingredient: {name: "3", value: 0, type: 3, properties: ["3": "boolean"]}
 parse/0: instruction: 4
 parse/0:   ingredient: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
@@ -19,7 +19,7 @@ parse/0: instruction: 3
 parse/0:   ingredient: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
 parse/0:   ingredient: {name: "1", value: 0, type: 0, properties: ["1": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
-parse/0: instruction: 102
+parse/0: instruction: 27
 parse/0: label: }
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
diff --git a/cpp/.traces/loop b/cpp/.traces/loop
index 11685d5d..e37e3dac 100644
--- a/cpp/.traces/loop
+++ b/cpp/.traces/loop
@@ -8,7 +8,7 @@ parse/0: label: {
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
-parse/0: instruction: 101
+parse/0: instruction: 27
 parse/0: label: }
 brace/0: 100: push (open, 2)
 brace/0: push (close, 5)
diff --git a/cpp/.traces/loop_nested b/cpp/.traces/loop_nested
index 1eba2a21..44f69eef 100644
--- a/cpp/.traces/loop_nested
+++ b/cpp/.traces/loop_nested
@@ -10,7 +10,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
 parse/0: label: }
-parse/0: instruction: 101
+parse/0: instruction: 28
 parse/0:   ingredient: {name: "4", value: 0, type: 3, properties: ["4": "boolean"]}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
diff --git a/cpp/.traces/loop_unless b/cpp/.traces/loop_unless
index 2de78b4a..5394cba5 100644
--- a/cpp/.traces/loop_unless
+++ b/cpp/.traces/loop_unless
@@ -5,7 +5,7 @@ parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
 parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: label: {
-parse/0: instruction: 101
+parse/0: instruction: 29
 parse/0:   ingredient: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
 parse/0: instruction: 1
 parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: ["0": "literal"]}
diff --git a/cpp/.traces/new b/cpp/.traces/new
index d2e291d7..e9be5862 100644
--- a/cpp/.traces/new
+++ b/cpp/.traces/new
@@ -1,7 +1,7 @@
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "integer", value: 0, type: 0, properties: ["integer": "type"]}
 parse/0:   product: {name: "1", value: 0, type: 2-1, properties: ["1": "address":"integer", "raw": ]}
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "integer", value: 0, type: 0, properties: ["integer": "type"]}
 parse/0:   product: {name: "2", value: 0, type: 2-1, properties: ["2": "address":"integer", "raw": ]}
 parse/0: instruction: 13
diff --git a/cpp/.traces/new_array b/cpp/.traces/new_array
index d7cd46fc..8a44bcf8 100644
--- a/cpp/.traces/new_array
+++ b/cpp/.traces/new_array
@@ -1,8 +1,8 @@
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "integer", value: 0, type: 0, properties: ["integer": "type"]}
 parse/0:   ingredient: {name: "5", value: 0, type: 0, properties: ["5": "literal"]}
 parse/0:   product: {name: "1", value: 0, type: 2-5-1, properties: ["1": "address":"array":"integer", "raw": ]}
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "integer", value: 0, type: 0, properties: ["integer": "type"]}
 parse/0:   product: {name: "2", value: 0, type: 2-1, properties: ["2": "address":"integer", "raw": ]}
 parse/0: instruction: 3
diff --git a/cpp/.traces/new_string b/cpp/.traces/new_string
index 56b9ae0f..96077d14 100644
--- a/cpp/.traces/new_string
+++ b/cpp/.traces/new_string
@@ -1,4 +1,4 @@
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "abc def", value: 0, type: 0, properties: ["abc def": "literal-string"]}
 parse/0:   product: {name: "1", value: 0, type: 2-5-8, properties: ["1": "address":"array":"character"]}
 parse/0: instruction: 20
diff --git a/cpp/.traces/string_literal b/cpp/.traces/string_literal
index 39e204e3..80393a55 100644
--- a/cpp/.traces/string_literal
+++ b/cpp/.traces/string_literal
@@ -1,4 +1,4 @@
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "abc def", value: 0, type: 0, properties: ["abc def": "literal-string"]}
 parse/0:   product: {name: "1", value: 0, type: 2-5-8, properties: ["1": "address":"array":"character"]}
 new/0: abc def -> 0
diff --git a/cpp/.traces/string_literal_nested b/cpp/.traces/string_literal_nested
index 5fd3fbff..923cd140 100644
--- a/cpp/.traces/string_literal_nested
+++ b/cpp/.traces/string_literal_nested
@@ -1,4 +1,4 @@
-parse/0: instruction: 24
+parse/0: instruction: 30
 parse/0:   ingredient: {name: "abc [def]", value: 0, type: 0, properties: ["abc [def]": "literal-string"]}
 parse/0:   product: {name: "1", value: 0, type: 2-5-8, properties: ["1": "address":"array":"character"]}
 new/0: abc [def] -> 0
diff --git a/cpp/011load b/cpp/011load
index 8cbf2e53..5657486b 100644
--- a/cpp/011load
+++ b/cpp/011load
@@ -40,8 +40,10 @@ recipe_number add_recipe(istream& in) {
   if (recipe_name.empty())
     raise << "empty recipe name\n";
 //?     raise << "empty recipe name in " << in.str() << '\n';
-  if (Recipe_number.find(recipe_name) == Recipe_number.end())
+  if (Recipe_number.find(recipe_name) == Recipe_number.end()) {
     Recipe_number[recipe_name] = Next_recipe_number++;
+//?     cout << "AAA: " << recipe_name << " is now " << Recipe_number[recipe_name] << '\n'; //? 1
+  }
   recipe_number r = Recipe_number[recipe_name];
 //?   cout << recipe_name << ": adding recipe " << r << '\n'; //? 3
 
@@ -98,8 +100,13 @@ bool next_instruction(istream& in, instruction* curr) {
   }
 
   curr->name = *p;
-  if (Recipe_number.find(*p) == Recipe_number.end())
+  if (Recipe_number.find(*p) == Recipe_number.end()) {
     Recipe_number[*p] = Next_recipe_number++;
+//?     cout << "AAA: " << *p << " is now " << Recipe_number[*p] << '\n'; //? 1
+  }
+  if (Recipe_number[*p] == 0) {
+    raise << "Recipe " << *p << " has number 0, which is reserved for IDLE.\n" << die();
+  }
   curr->operation = Recipe_number[*p];  ++p;
 
   for (; p != words.end(); ++p) {
diff --git a/cpp/012transform b/cpp/012transform
index e9b74776..7fa979c7 100644
--- a/cpp/012transform
+++ b/cpp/012transform
@@ -16,6 +16,7 @@ vector<transform_fn> Transform;
 
 :(code)
 void transform_all() {
+//?   cout << "AAA transform_all\n"; //? 1
   for (size_t t = 0; t < Transform.size(); ++t) {
     for (unordered_map<recipe_number, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
       recipe& r = p->second;
diff --git a/cpp/024brace b/cpp/024brace
index ec6171f7..47dd5596 100644
--- a/cpp/024brace
+++ b/cpp/024brace
@@ -11,8 +11,8 @@
 //:     }
 //:   }
 //:
-//: Braces are just labels, they require no special parsing. The operations
-//: 'loop' and 'break' jump to just after the enclosing '{' and '}'
+//: Braces are just labels, they require no special parsing. The pseudo
+//: recipes 'loop' and 'break' jump to just after the enclosing '{' and '}'
 //: respectively.
 //:
 //: Conditional and unconditional 'loop' and 'break' should give us 80% of the
@@ -37,6 +37,8 @@ Transform.push_back(transform_braces);
 
 :(code)
 void transform_braces(const recipe_number r) {
+//?   cout << "AAA transform_braces\n"; //? 1
+//?   exit(0); //? 1
   const int OPEN = 0, CLOSE = 1;
   list<pair<int/*OPEN/CLOSE*/, size_t/*step index*/> > braces;
   for (size_t index = 0; index < Recipe[r].steps.size(); ++index) {
@@ -54,6 +56,7 @@ void transform_braces(const recipe_number r) {
   trace("after-brace") << "recipe " << Recipe[r].name;
   for (size_t index = 0; index < Recipe[r].steps.size(); ++index) {
     instruction& inst = Recipe[r].steps[index];
+//?     cout << "AAA " << inst.name << ": " << inst.operation << '\n'; //? 1
     if (inst.label == "{") open_braces.push(index);
     else if (inst.label == "}") open_braces.pop();
     else if (inst.is_label)
@@ -126,6 +129,7 @@ void transform_braces(const recipe_number r) {
       }
     }
     else if (inst.operation == Recipe_number["break-unless"]) {
+//?       cout << "AAA break-unless\n"; //? 1
       inst.operation = Recipe_number["jump-unless"];
       if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) {
         // explicit target; a later phase will handle it
@@ -157,11 +161,43 @@ size_t matching_brace(size_t index, const list<pair<int, size_t> >& braces) {
 
 // temporarily suppress run
 void transform_test(string form) {
+//?   cout << "AAA transform_test {\n"; //? 1
   vector<recipe_number> tmp = add_recipes(form);
+//?   cout << "AAA done adding recipes\n"; //? 1
   recipes_added_by_test.insert(recipes_added_by_test.end(), tmp.begin(), tmp.end());
   transform_all();
+//?   cout << "AAA }\n"; //? 1
 }
 
+//: Make sure these pseudo recipes get consistent numbers, even though they aren't
+//: implemented.
+:(before "End Globals")
+const int BREAK = 24;
+const int BREAK_IF = 25;
+const int BREAK_UNLESS = 26;
+const int LOOP = 27;
+const int LOOP_IF = 28;
+const int LOOP_UNLESS = 29;
+:(before "End Primitive Recipe Numbers")
+Recipe_number["break"] = BREAK;
+assert(Next_recipe_number == BREAK);
+Next_recipe_number++;
+Recipe_number["break-if"] = BREAK_IF;
+assert(Next_recipe_number == BREAK_IF);
+Next_recipe_number++;
+Recipe_number["break-unless"] = BREAK_UNLESS;
+assert(Next_recipe_number == BREAK_UNLESS);
+Next_recipe_number++;
+Recipe_number["loop"] = LOOP;
+assert(Next_recipe_number == LOOP);
+Next_recipe_number++;
+Recipe_number["loop-if"] = LOOP_IF;
+assert(Next_recipe_number == LOOP_IF);
+Next_recipe_number++;
+Recipe_number["loop-unless"] = LOOP_UNLESS;
+assert(Next_recipe_number == LOOP_UNLESS);
+Next_recipe_number++;
+
 :(scenario "loop")
 recipe main [
   1:integer <- copy 0:literal
diff --git a/cpp/026new b/cpp/026new
index e541d923..ee1fd2c5 100644
--- a/cpp/026new
+++ b/cpp/026new
@@ -37,7 +37,7 @@ if (inst.operation == Recipe_number["new"]) {
 
 :(before "End Globals")
 // Operator to look at elements of arrays.
-const int NEW = 24;
+const int NEW = 30;
 :(before "End Primitive Recipe Numbers")
 Recipe_number["new"] = NEW;
 assert(Next_recipe_number == NEW);
diff --git a/cpp/030length b/cpp/030length
index f690d543..7b5c52be 100644
--- a/cpp/030length
+++ b/cpp/030length
@@ -10,7 +10,7 @@ recipe main [
 +mem: storing 3 in location 5
 
 :(before "End Globals")
-const int LENGTH = 25;
+const int LENGTH = 31;
 :(before "End Primitive Recipe Numbers")
 Recipe_number["length"] = LENGTH;
 assert(Next_recipe_number == LENGTH);