]> git.saurik.com Git - cycript.git/commitdiff
Fixed non-local return insanity.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 2 Jul 2010 08:03:25 +0000 (08:03 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 2 Jul 2010 08:03:25 +0000 (08:03 +0000)
Parser.hpp
Replace.cpp

index 2d3a59f4b1417fc53e6e5035832b51fec01ab932..361beaa105fe696b8d7903daef41b0111004be40 100644 (file)
@@ -367,6 +367,7 @@ struct CYContext {
     CYIdentifierUsageVector rename_;
 
     CYNonLocal *nonlocal_;
+    CYNonLocal *nextlocal_;
     unsigned unique_;
 
     CYContext(apr_pool_t *pool, CYOptions &options) :
@@ -374,6 +375,7 @@ struct CYContext {
         options_(options),
         scope_(NULL),
         nonlocal_(NULL),
+        nextlocal_(NULL),
         unique_(0)
     {
     }
index 250b5550cfcf4ff3ddc040588d765999787b7059..9cbd30fbbe86c958e67a6dfb5401bcb3dc24cbd8 100644 (file)
@@ -175,9 +175,9 @@ CYExpression *CYCondition::Replace(CYContext &context) {
 void CYContext::NonLocal(CYStatement *&statements) {
     CYContext &context(*this);
 
-    if (nonlocal_->identifier_ != NULL) {
+    if (nextlocal_ != NULL && nextlocal_->identifier_ != NULL) {
         CYVariable *cye($V("$cye"));
-        CYVariable *unique($ CYVariable(nonlocal_->identifier_));
+        CYVariable *unique($ CYVariable(nextlocal_->identifier_));
 
         statements = $$->*
             $E($ CYAssign(unique, $ CYObject()))->*
@@ -376,17 +376,19 @@ void CYFunction::Replace_(CYContext &context, bool outer) {
     scope.parent_ = context.scope_;
     context.scope_ = &scope;
 
+    CYNonLocal *nonlocal(context.nonlocal_);
+    CYNonLocal *nextlocal(context.nextlocal_);
+
     bool localize;
-    if (nonlocal_ != NULL)
+    if (nonlocal_ != NULL) {
         localize = false;
-    else {
+        context.nonlocal_ = nonlocal_;
+    } else {
         localize = true;
         nonlocal_ = $ CYNonLocal();
+        context.nextlocal_ = nonlocal_;
     }
 
-    CYNonLocal *nonlocal(context.nonlocal_);
-    context.nonlocal_ = nonlocal_;
-
     if (!outer && name_ != NULL)
         Inject(context);
 
@@ -396,6 +398,8 @@ void CYFunction::Replace_(CYContext &context, bool outer) {
 
     if (localize)
         context.NonLocal(code_.statements_);
+
+    context.nextlocal_ = nextlocal;
     context.nonlocal_ = nonlocal;
 
     context.scope_ = scope.parent_;
@@ -554,7 +558,8 @@ void CYProgram::Replace(CYContext &context) {
     scope.parent_ = context.scope_;
     context.scope_ = &scope;
 
-    context.nonlocal_ = $ CYNonLocal();
+    context.nextlocal_ = $ CYNonLocal();
+
     statements_ = statements_->ReplaceAll(context);
     context.NonLocal(statements_);
 
@@ -632,7 +637,7 @@ CYExpression *CYRubyBlock::Replace(CYContext &context) {
 
 CYExpression *CYRubyProc::Replace(CYContext &context) {
     CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_));
-    function->nonlocal_ = context.nonlocal_;
+    function->nonlocal_ = context.nextlocal_;
     return function;
 }