Class: Rubinius::ToolSet.current::TS::AST::EvalExpression
Instance Attribute Summary
Attributes inherited from Container
#file, #name, #pre_exe, #variable_scope
Attributes inherited from ClosedScope
#body
Attributes inherited from Node
#line
Instance Method Summary
collapse
Methods inherited from Container
#container_bytecode, #pop_state, #to_sexp
Methods inherited from ClosedScope
#attach_and_call, #module?, #nest_scope, #new_nested_local, #to_sexp
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
Returns a new instance of EvalExpression.
1026
1027
1028
1029
|
# File 'lib/rubinius/ast/definitions.rb', line 1026
def initialize(body)
super body
@name = :__eval_script__
end
|
Instance Method Details
#assign_local_reference(var) ⇒ Object
1069
1070
1071
1072
1073
1074
1075
1076
|
# File 'lib/rubinius/ast/definitions.rb', line 1069
def assign_local_reference(var)
unless reference = search_local(var.name)
variable = new_local var.name
reference = variable.reference
end
var.variable = reference
end
|
#bytecode(g) ⇒ Object
1083
1084
1085
1086
1087
1088
1089
1090
|
# File 'lib/rubinius/ast/definitions.rb', line 1083
def bytecode(g)
super(g)
container_bytecode(g) do
@body.bytecode(g)
g.ret
end
end
|
#new_local(name) ⇒ Object
1065
1066
1067
|
# File 'lib/rubinius/ast/definitions.rb', line 1065
def new_local(name)
variables[name] ||= Compiler::EvalLocalVariable.new name
end
|
#push_state(g) ⇒ Object
1078
1079
1080
1081
|
# File 'lib/rubinius/ast/definitions.rb', line 1078
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.
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
# File 'lib/rubinius/ast/definitions.rb', line 1054
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
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
# File 'lib/rubinius/ast/definitions.rb', line 1035
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
1092
1093
1094
|
# File 'lib/rubinius/ast/definitions.rb', line 1092
def sexp_name
:eval
end
|
#should_cache? ⇒ Boolean
1031
1032
1033
|
# File 'lib/rubinius/ast/definitions.rb', line 1031
def should_cache?
!@body.kind_of?(AST::ClosedScope)
end
|