about summary refs log tree commit diff stats
path: root/cpp/024brace
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-17 00:03:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-17 00:03:33 -0700
commit7ac221e43a94132f30d4ca6770efa47bd74f6566 (patch)
tree7999a9fe63b2f600aa3e9ed6c1713ff245ba4e2b /cpp/024brace
parentdecaddb418abcb6094e339f1b8dd4bb519b761ad (diff)
downloadmu-7ac221e43a94132f30d4ca6770efa47bd74f6566.tar.gz
942
Diffstat (limited to 'cpp/024brace')
-rw-r--r--cpp/024brace7
1 files changed, 4 insertions, 3 deletions
diff --git a/cpp/024brace b/cpp/024brace
index 5a2d346f..72318faa 100644
--- a/cpp/024brace
+++ b/cpp/024brace
@@ -76,7 +76,7 @@ void transform_braces(const recipe_number r) {
       }
       else {
         reagent ing(0);  // literal
-        ing.value = index - matching_brace(open_braces.top(), braces) - 1;
+        ing.value = matching_brace(open_braces.top(), braces) - index - 1;
         inst.ingredients.push_back(ing);
         trace("after-brace") << "jump " << ing.value << ":offset";
       }
@@ -90,10 +90,11 @@ void transform_braces(const recipe_number r) {
 size_t matching_brace(size_t index, const list<pair<int, size_t> >& braces) {
   int stacksize;
   for (list<pair<int, size_t> >::const_iterator p = braces.begin(); p != braces.end(); ++p) {
-    if (p->second <= index) continue;
+    if (p->second < index) continue;
     stacksize += (p->first ? 1 : -1);
-    if (stacksize == -1) return p->second;
+    if (stacksize == 0) return p->second;
   }
+  assert(false);
   return -1;
 }