about summary refs log tree commit diff stats
path: root/047jump_label.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-10 11:38:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-10 11:40:33 -0700
commit4071055aeed22737366b3cb863b24a59f0625a28 (patch)
tree671bfd7bee9d5d75f5890bc78d1106719568fcde /047jump_label.cc
parent6b16a2ef6b12eedc14f2a7652bf8d977c8192b6e (diff)
downloadmu-4071055aeed22737366b3cb863b24a59f0625a28.tar.gz
1327 - better error handling in chessboard
Also a bugfix in break to label, because I noticed the screen wasn't
being cleaned up on quit.
Diffstat (limited to '047jump_label.cc')
-rw-r--r--047jump_label.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/047jump_label.cc b/047jump_label.cc
index 9bc0c442..c9dcb4f5 100644
--- a/047jump_label.cc
+++ b/047jump_label.cc
@@ -24,25 +24,25 @@ void transform_labels(const recipe_number r) {
     instruction& inst = Recipe[r].steps.at(i);
     if (inst.operation == Recipe_number["jump"]) {
 //?       cerr << inst.to_string() << '\n'; //? 1
-      replace_offset(inst.ingredients.at(0), offset, r);
+      replace_offset(inst.ingredients.at(0), offset, i, r);
     }
     if (inst.operation == Recipe_number["jump-if"] || inst.operation == Recipe_number["jump-unless"]) {
-      replace_offset(inst.ingredients.at(1), offset, r);
+      replace_offset(inst.ingredients.at(1), offset, i, r);
     }
     if ((inst.operation == Recipe_number["loop"] || inst.operation == Recipe_number["break"])
         && inst.ingredients.size() == 1) {
-      replace_offset(inst.ingredients.at(0), offset, r);
+      replace_offset(inst.ingredients.at(0), offset, i, r);
     }
     if ((inst.operation == Recipe_number["loop-if"] || inst.operation == Recipe_number["loop-unless"]
             || inst.operation == Recipe_number["break-if"] || inst.operation == Recipe_number["break-unless"])
         && inst.ingredients.size() == 2) {
-      replace_offset(inst.ingredients.at(1), offset, r);
+      replace_offset(inst.ingredients.at(1), offset, i, r);
     }
   }
 }
 
 :(code)
-void replace_offset(reagent& x, /*const*/ map<string, index_t>& offset, const recipe_number r) {
+void replace_offset(reagent& x, /*const*/ map<string, index_t>& offset, const index_t current_offset, const recipe_number r) {
 //?   cerr << "AAA " << x.to_string() << '\n'; //? 1
   assert(isa_literal(x));
 //?   cerr << "BBB " << x.to_string() << '\n'; //? 1
@@ -52,7 +52,7 @@ void replace_offset(reagent& x, /*const*/ map<string, index_t>& offset, const re
 //?   cerr << "DDD " << x.to_string() << '\n'; //? 1
   if (offset.find(x.name) == offset.end())
     raise << "can't find label " << x.name << " in routine " << Recipe[r].name << '\n';
-  x.set_value(offset[x.name]);
+  x.set_value(offset[x.name]-current_offset);
 }
 
 :(scenario break_to_label)
@@ -91,3 +91,17 @@ recipe main [
   +target
 ]
 -mem: storing 0 in location 1
+
+:(scenario jump_runs_code_after_label)
+recipe main [
+  # first a few lines of padding to exercise the offset computation
+  1:integer <- copy 0:literal
+  2:integer <- copy 0:literal
+  3:integer <- copy 0:literal
+  jump +target:offset
+  4:integer <- copy 0:literal
+  +target
+  5:integer <- copy 0:literal
+]
++mem: storing 0 in location 5
+-mem: storing 0 in location 4