From 06293152b6505062453463ef34c0d90e0c8db17e Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 2 Jul 2010 08:03:25 +0000 Subject: [PATCH] Fixed non-local return insanity. --- Parser.hpp | 2 ++ Replace.cpp | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index 2d3a59f..361beaa 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -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) { } diff --git a/Replace.cpp b/Replace.cpp index 250b555..9cbd30f 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -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; } -- 2.47.2