Created
April 8, 2009 19:44
-
-
Save rue/91957 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit 6d992de6dbca249251f3c2872edc9f205dd55b39 | |
| Author: Eero Saynatkari <projects@kittensoft.org> | |
| Date: Thu Apr 2 20:02:44 2009 +0300 | |
| Hack Kernel.eval working. | |
| diff --git a/kernel/common/variable_scope.rb b/kernel/common/variable_scope.rb | |
| index 508ba75..ac9635e 100644 | |
| --- a/kernel/common/variable_scope.rb | |
| +++ b/kernel/common/variable_scope.rb | |
| @@ -15,14 +15,29 @@ class VariableScope | |
| end | |
| def set_eval_local(name, val) | |
| - @parent.dynamic_locals[name] = val | |
| + vscope = self | |
| + | |
| + while vscope | |
| + if vscope.dynamic_locals.key? name | |
| + return vscope.dynamic_locals[name] = val | |
| + end | |
| + vscope = vscope.parent | |
| + end | |
| end | |
| def get_eval_local(name) | |
| - @parent.dynamic_locals[name] | |
| + vscope = self | |
| + | |
| + while vscope | |
| + if vscope.dynamic_locals.key? name | |
| + return vscope.dynamic_locals[name] | |
| + end | |
| + vscope = vscope.parent | |
| + end | |
| end | |
| def exitted? | |
| @exitted | |
| end | |
| + | |
| end | |
| diff --git a/kernel/compiler/nodes.rb b/kernel/compiler/nodes.rb | |
| index 78ead9b..d395144 100644 | |
| --- a/kernel/compiler/nodes.rb | |
| +++ b/kernel/compiler/nodes.rb | |
| @@ -1054,7 +1054,7 @@ raise "no" | |
| @slot = @my_scope.size | |
| end | |
| - def find_local(name, in_block=false, allocate=true) | |
| + def find_local(name, in_block = false, allocate = true) | |
| if normal = super(name, in_block, false) | |
| return normal | |
| end | |
| @@ -1064,22 +1064,25 @@ raise "no" | |
| existing = false | |
| unless allocate | |
| - if dynamic = @context.dynamic_locals | |
| - if dynamic.key? name | |
| + vscope = @context.variables | |
| + | |
| + # Check this and enclosing scopes | |
| + while vscope | |
| + if vscope.dynamic_locals.key? name | |
| existing = true | |
| - else | |
| - return nil | |
| + break | |
| end | |
| - else | |
| - return nil | |
| + | |
| + vscope = vscope.parent | |
| end | |
| + | |
| + return nil unless existing | |
| end | |
| - # Seed the dynamic_locals table with the name, so key? works | |
| - # later. | |
| + # Set a placeholder when allocating | |
| @context.set_eval_local(name, nil) unless existing | |
| - return DynamicLocal.new(name) | |
| + DynamicLocal.new name | |
| end | |
| def enlarge_context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment