diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/.traces/break_if | 41 | ||||
-rw-r--r-- | cpp/.traces/break_label | 17 | ||||
-rw-r--r-- | cpp/.traces/break_nested | 41 | ||||
-rw-r--r-- | cpp/.traces/break_nested_degenerate | 34 | ||||
-rw-r--r-- | cpp/.traces/break_nested_degenerate2 | 27 | ||||
-rw-r--r-- | cpp/.traces/run_label | 1 | ||||
-rw-r--r-- | cpp/024brace | 99 |
7 files changed, 257 insertions, 3 deletions
diff --git a/cpp/.traces/break_if b/cpp/.traces/break_if new file mode 100644 index 00000000..fdfce24d --- /dev/null +++ b/cpp/.traces/break_if @@ -0,0 +1,41 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "1", value: 1, 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: 2, type: 1, properties: [2: integer]} +parse/0: label: { +parse/0: instruction: 25 +parse/0: ingredient: {name: "2", value: 2, 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: 3, type: 1, properties: [3: integer]} +parse/0: label: } +parse/0: label: { +parse/0: instruction: 26 +parse/0: label: } +brace/0: 24: push (open, 2) +brace/0: push (close, 5) +brace/0: 24: push (open, 6) +brace/0: push (close, 8) +after-brace/0: recipe main +after-brace/0: copy ... +after-brace/0: copy ... +after-brace/0: jump-if 2, 1:offset +after-brace/0: copy ... +after-brace/0: jump 0:offset +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: jump-if fell through +run/0: instruction main/4 +run/0: ingredient 0 is 0 +mem/0: storing in location 3 +run/0: instruction main/7 +run/0: ingredient 0 is diff --git a/cpp/.traces/break_label b/cpp/.traces/break_label new file mode 100644 index 00000000..cefe3e2e --- /dev/null +++ b/cpp/.traces/break_label @@ -0,0 +1,17 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "1", value: 1, type: 1, properties: [1: integer]} +parse/0: label: { +parse/0: instruction: 25 +parse/0: ingredient: {name: "3", value: 3, type: 0, properties: [3: offset]} +parse/0: label: } +brace/0: 24: push (open, 1) +brace/0: push (close, 3) +after-brace/0: recipe main +after-brace/0: copy ... +after-brace/0: jump 3:offset +run/0: instruction main/0 +run/0: ingredient 0 is 0 +mem/0: storing in location 1 +run/0: instruction main/2 +run/0: ingredient 0 is 3 diff --git a/cpp/.traces/break_nested b/cpp/.traces/break_nested new file mode 100644 index 00000000..3212847b --- /dev/null +++ b/cpp/.traces/break_nested @@ -0,0 +1,41 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "1", value: 1, type: 1, properties: [1: integer]} +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: 2, type: 1, properties: [2: integer]} +parse/0: instruction: 25 +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: 3, type: 1, properties: [3: integer]} +parse/0: label: } +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "4", value: 4, type: 1, properties: [4: integer]} +parse/0: label: } +brace/0: 24: push (open, 1) +brace/0: 24: push (open, 4) +brace/0: push (close, 6) +brace/0: push (close, 8) +after-brace/0: recipe main +after-brace/0: copy ... +after-brace/0: copy ... +after-brace/0: jump 4:offset +after-brace/0: copy ... +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/2 +run/0: ingredient 0 is 0 +mem/0: storing in location 2 +run/0: instruction main/3 +run/0: ingredient 0 is +run/0: instruction main/5 +run/0: ingredient 0 is 0 +mem/0: storing in location 3 +run/0: instruction main/7 +run/0: ingredient 0 is 0 +mem/0: storing in location 4 diff --git a/cpp/.traces/break_nested_degenerate b/cpp/.traces/break_nested_degenerate new file mode 100644 index 00000000..90a0d57f --- /dev/null +++ b/cpp/.traces/break_nested_degenerate @@ -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: 1, type: 1, properties: [1: integer]} +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: 2, type: 1, properties: [2: integer]} +parse/0: instruction: 25 +parse/0: label: { +parse/0: label: } +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "4", value: 4, type: 1, properties: [4: integer]} +parse/0: label: } +brace/0: 24: push (open, 1) +brace/0: 24: push (open, 4) +brace/0: push (close, 5) +brace/0: push (close, 7) +after-brace/0: recipe main +after-brace/0: copy ... +after-brace/0: copy ... +after-brace/0: jump 3: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/2 +run/0: ingredient 0 is 0 +mem/0: storing in location 2 +run/0: instruction main/3 +run/0: ingredient 0 is +run/0: instruction main/6 +run/0: ingredient 0 is 0 +mem/0: storing in location 4 diff --git a/cpp/.traces/break_nested_degenerate2 b/cpp/.traces/break_nested_degenerate2 new file mode 100644 index 00000000..6ca10a5c --- /dev/null +++ b/cpp/.traces/break_nested_degenerate2 @@ -0,0 +1,27 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "1", value: 1, type: 1, properties: [1: integer]} +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: 2, type: 1, properties: [2: integer]} +parse/0: instruction: 25 +parse/0: label: { +parse/0: label: } +parse/0: label: } +brace/0: 24: push (open, 1) +brace/0: 24: push (open, 4) +brace/0: push (close, 5) +brace/0: push (close, 6) +after-brace/0: recipe main +after-brace/0: copy ... +after-brace/0: copy ... +after-brace/0: jump 2:offset +run/0: instruction main/0 +run/0: ingredient 0 is 0 +mem/0: storing in location 1 +run/0: instruction main/2 +run/0: ingredient 0 is 0 +mem/0: storing in location 2 +run/0: instruction main/3 +run/0: ingredient 0 is diff --git a/cpp/.traces/run_label b/cpp/.traces/run_label index e1b62185..6d1065b9 100644 --- a/cpp/.traces/run_label +++ b/cpp/.traces/run_label @@ -6,7 +6,6 @@ parse/0: instruction: 1 parse/0: ingredient: {name: "1", value: 1, type: 1, properties: [1: integer]} parse/0: product: {name: "2", value: 2, type: 1, properties: [2: integer]} after-brace/0: recipe main -after-brace/0: jump 0:offset after-brace/0: copy ... after-brace/0: copy ... run/0: instruction main/1 diff --git a/cpp/024brace b/cpp/024brace index 2402923b..0385b3b1 100644 --- a/cpp/024brace +++ b/cpp/024brace @@ -55,11 +55,13 @@ void transform_braces(const recipe_number r) { instruction& inst = Recipe[r].steps[index]; if (inst.label == "{") open_braces.push(index); else if (inst.label == "}") open_braces.pop(); + else if (inst.is_label) + ; // do nothing else if (inst.operation == Recipe_number["loop"]) { inst.operation = Recipe_number["jump"]; if (inst.ingredients.size() > 0 && inst.ingredients[0].types[0] == 0) { // explicit target; a later phase will handle it - ; + trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } else { reagent ing(0); // literal @@ -72,7 +74,7 @@ void transform_braces(const recipe_number r) { inst.operation = Recipe_number["jump"]; if (inst.ingredients.size() > 0 && inst.ingredients[0].types[0] == 0) { // explicit target; a later phase will handle it - ; + trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } else { reagent ing(0); // literal @@ -81,6 +83,32 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << ing.value << ":offset"; } } + else if (inst.operation == Recipe_number["loop-if"]) { + inst.operation = Recipe_number["jump-if"]; + 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-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + } + } + else if (inst.operation == Recipe_number["break-if"]) { + inst.operation = Recipe_number["jump-if"]; + 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-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; + } + } else { trace("after-brace") << inst.name << " ..."; } @@ -157,3 +185,70 @@ recipe main [ +after-brace: jump 1:offset +after-brace: copy ... +after-brace: jump 0:offset + +:(scenario "break_if") +recipe main [ + 1:integer <- copy 0:literal + 2:integer <- copy 0:literal + { + break-if 2:integer + 3:integer <- copy 0:literal + } + { + break + } +] ++after-brace: recipe main ++after-brace: copy ... ++after-brace: copy ... ++after-brace: jump-if 2, 1:offset ++after-brace: copy ... ++after-brace: jump 0:offset + +:(scenario "break_nested") +recipe main [ + 1:integer <- copy 0:literal + { + 2:integer <- copy 0:literal + break + { + 3:integer <- copy 0:literal + } + 4:integer <- copy 0:literal + } +] ++after-brace: jump 4:offset + +:(scenario "break_nested_degenerate") +recipe main [ + 1:integer <- copy 0:literal + { + 2:integer <- copy 0:literal + break + { + } + 4:integer <- copy 0:literal + } +] ++after-brace: jump 3:offset + +:(scenario "break_nested_degenerate2") +recipe main [ + 1:integer <- copy 0:literal + { + 2:integer <- copy 0:literal + break + { + } + } +] ++after-brace: jump 2:offset + +:(scenario "break_label") +recipe main [ + 1:integer <- copy 0:literal + { + break 3:offset + } +] ++after-brace: jump 3:offset |