Class: Rubinius::AST::EvalExpression
- Inherits:
-
Container
- Object
- Node
- ClosedScope
- Container
- Rubinius::AST::EvalExpression
- Defined in:
- lib/compiler/ast/definitions.rb
Instance Attribute Summary
Attributes inherited from Container
#file, #name, #pre_exe, #variable_scope
Attributes inherited from ClosedScope
Attributes inherited from Node
Instance Method Summary collapse
- #assign_local_reference(var) ⇒ Object
-
#initialize(body) ⇒ EvalExpression
constructor
A new instance of EvalExpression.
- #new_local(name) ⇒ Object
- #push_state(g) ⇒ Object
-
#search_local(name) ⇒ Object
Returns a cached reference to a variable or searches all surrounding scopes for a variable.
- #search_scopes(name) ⇒ Object
- #sexp_name ⇒ Object
- #should_cache? ⇒ Boolean
Methods inherited from Container
Methods inherited from ClosedScope
#module?, #nest_scope, #new_nested_local, #to_sexp
Methods included from Compiler::LocalVariables
#allocate_slot, #local_count, #local_names, #variables
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(body) ⇒ EvalExpression
Returns a new instance of EvalExpression.
651 652 653 654 |
# File 'lib/compiler/ast/definitions.rb', line 651 def initialize(body) super body @name = :__eval_script__ end |
Instance Method Details
#assign_local_reference(var) ⇒ Object
695 696 697 698 699 700 701 702 |
# File 'lib/compiler/ast/definitions.rb', line 695 def assign_local_reference(var) unless reference = search_local(var.name) variable = new_local var.name reference = variable.reference end var.variable = reference end |
#new_local(name) ⇒ Object
690 691 692 693 |
# File 'lib/compiler/ast/definitions.rb', line 690 def new_local(name) variable = Compiler::EvalLocalVariable.new name variables[name] = variable end |
#push_state(g) ⇒ Object
704 705 706 707 |
# File 'lib/compiler/ast/definitions.rb', line 704 def push_state(g) g.push_state self g.state.push_eval self end |
#search_local(name) ⇒ Object
Returns a cached reference to a variable or searches all surrounding scopes for a variable. If no variable is found, it returns nil and a nested scope will create the variable in itself.
679 680 681 682 683 684 685 686 687 688 |
# File 'lib/compiler/ast/definitions.rb', line 679 def search_local(name) if variable = variables[name] return variable.nested_reference end if variable = search_scopes(name) variables[name] = variable return variable.nested_reference end end |
#search_scopes(name) ⇒ Object
660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/compiler/ast/definitions.rb', line 660 def search_scopes(name) depth = 1 scope = @variable_scope while scope if !scope.method.for_eval? and slot = scope.method.local_slot(name) return Compiler::NestedLocalVariable.new(depth, slot) elsif scope.eval_local_defined?(name, false) return Compiler::EvalLocalVariable.new(name) end depth += 1 scope = scope.parent end end |
#sexp_name ⇒ Object
709 710 711 |
# File 'lib/compiler/ast/definitions.rb', line 709 def sexp_name :eval end |
#should_cache? ⇒ Boolean
656 657 658 |
# File 'lib/compiler/ast/definitions.rb', line 656 def should_cache? !@body.kind_of?(AST::ClosedScope) end |