about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/break_unless34
-rw-r--r--cpp/.traces/loop_unless34
-rw-r--r--cpp/024brace56
3 files changed, 124 insertions, 0 deletions
diff --git a/cpp/.traces/break_unless b/cpp/.traces/break_unless
new file mode 100644
index 00000000..b227e1ab
--- /dev/null
+++ b/cpp/.traces/break_unless
@@ -0,0 +1,34 @@
+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: 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: 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: }
+brace/0: 24: push (open, 2)
+brace/0: push (close, 5)
+after-brace/0: recipe main
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: jump-unless 2, 1:offset
+after-brace/0: copy ...
+run/0: instruction main/0
+run/0: ingredient 0 is 0
+mem/0: storing in location 1
+run/0: instruction main/1
+run/0: ingredient 0 is 0
+mem/0: storing in location 2
+run/0: instruction main/3
+mem/0: location 2 is 0
+run/0: ingredient 0 is 0
+run/0: ingredient 1 is 
+run/0: jumping to instruction 4
+run/0: instruction main/4
+run/0: ingredient 0 is 0
+mem/0: storing in location 3
diff --git a/cpp/.traces/loop_unless b/cpp/.traces/loop_unless
new file mode 100644
index 00000000..35a3cc8a
--- /dev/null
+++ b/cpp/.traces/loop_unless
@@ -0,0 +1,34 @@
+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: 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: 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: }
+brace/0: 24: push (open, 2)
+brace/0: push (close, 5)
+after-brace/0: recipe main
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: jump-unless 2, -1:offset
+after-brace/0: copy ...
+run/0: instruction main/0
+run/0: ingredient 0 is 0
+mem/0: storing in location 1
+run/0: instruction main/1
+run/0: ingredient 0 is 0
+mem/0: storing in location 2
+run/0: instruction main/3
+mem/0: location 2 is 0
+run/0: ingredient 0 is 0
+run/0: ingredient 1 is 
+run/0: jumping to instruction 4
+run/0: instruction main/4
+run/0: ingredient 0 is 0
+mem/0: storing in location 3
diff --git a/cpp/024brace b/cpp/024brace
index 0a13ddda..f5fbbb87 100644
--- a/cpp/024brace
+++ b/cpp/024brace
@@ -109,6 +109,32 @@ void transform_braces(const recipe_number r) {
         trace("after-brace") << "jump-if " << inst.ingredients[0].name << ", " << ing.value << ":offset";
       }
     }
+    else if (inst.operation == Recipe_number["loop-unless"]) {
+      inst.operation = Recipe_number["jump-unless"];
+      if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) {
+        // explicit target; a later phase will handle it
+        trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset";
+      }
+      else {
+        reagent ing(0);  // literal
+        ing.value = open_braces.top()-index;
+        inst.ingredients.push_back(ing);
+        trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset";
+      }
+    }
+    else if (inst.operation == Recipe_number["break-unless"]) {
+      inst.operation = Recipe_number["jump-unless"];
+      if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) {
+        // explicit target; a later phase will handle it
+        trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset";
+      }
+      else {
+        reagent ing(0);  // literal
+        ing.value = matching_brace(open_braces.top(), braces) - index - 1;
+        inst.ingredients.push_back(ing);
+        trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset";
+      }
+    }
     else {
       trace("after-brace") << inst.name << " ...";
     }
@@ -252,3 +278,33 @@ recipe main [
   }
 ]
 +after-brace: jump +foo:offset
+
+:(scenario "break_unless")
+recipe main [
+  1:integer <- copy 0:literal
+  2:integer <- copy 0:literal
+  {
+    break-unless 2:integer
+    3:integer <- copy 0:literal
+  }
+]
++after-brace: recipe main
++after-brace: copy ...
++after-brace: copy ...
++after-brace: jump-unless 2, 1:offset
++after-brace: copy ...
+
+:(scenario "loop_unless")
+recipe main [
+  1:integer <- copy 0:literal
+  2:integer <- copy 0:literal
+  {
+    loop-unless 2:integer
+    3:integer <- copy 0:literal
+  }
+]
++after-brace: recipe main
++after-brace: copy ...
++after-brace: copy ...
++after-brace: jump-unless 2, -1:offset
++after-brace: copy ...