Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
diff --git a/kernel/compiler/local.rb b/kernel/compiler/local.rb index 5fb6394..2c605f4 100644 --- a/kernel/compiler/local.rb +++ b/kernel/compiler/local.rb @@ -11,6 +11,7 @@ class Compiler @names = [] @locals = Hash.new { |h,k| h[k] = Local.new(@scope, k) } @from_eval = false + @skip = false end attr_accessor :from_eval @@ -66,6 +67,14 @@ class Compiler return tup end + def skip? + @skip + end + + def skip! + @skip = true + end + attr_reader :locals attr_accessor :scope end diff --git a/kernel/compiler/nodes.rb b/kernel/compiler/nodes.rb index 05a72bc..e17043e 100644 --- a/kernel/compiler/nodes.rb +++ b/kernel/compiler/nodes.rb @@ -634,7 +634,7 @@ raise "no" dep = 0 @block_scope.reverse_each do |scope| - if scope.key?(name) + if !scope.skip? && scope.key?(name) if scope.from_eval depth = dep + 1 else @@ -655,14 +655,20 @@ raise "no" return nil else # This not found. create it. - in_scope = @block_scope.last + depth = 0 + in_scope = @top_scope + @block_scope.reverse_each do |scope| + if !scope.skip? + in_scope = scope + break + end + depth += 1 + end idx = in_scope.size lcl = in_scope[name] lcl.created_in_block!(idx) if in_scope.from_eval - depth = 1 - else - depth = 0 + depth += 1 end end end @@ -687,6 +693,10 @@ raise "no" def module_body? false end + + def skip! + @block_scope.last.skip! + end end # Example: m(1, *a) @@ -1170,6 +1180,8 @@ raise "no" set(:iter) do @locals = get(:scope).new_block_scope do + get(:scope).skip! + set(:iter_args) do sexp[1] = convert(s(:iter_args, sexp[1])) # local var assignment end diff --git a/spec/tags/frozen/language/for_tags.txt b/spec/tags/frozen/language/for_tags.txt index 060b4f9..c033480 100644 --- a/spec/tags/frozen/language/for_tags.txt +++ b/spec/tags/frozen/language/for_tags.txt @@ -1,3 +1 @@ -fails:The for expression executes code in containing variable scope -fails:The for expression executes code in containing variable scope with 'do' fails:The for expression repeats the loop from the beginning with 'retry'
This paste will be private.
From the Design Piracy series on my blog: