Class: CodeTools::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.
1124
1125
1126
1127
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1124
def initialize(body)
super body
@name = :__eval_script__
end
|
Instance Method Details
#assign_local_reference(var) ⇒ Object
1167
1168
1169
1170
1171
1172
1173
1174
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1167
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
1181
1182
1183
1184
1185
1186
1187
1188
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1181
def bytecode(g)
super(g)
container_bytecode(g) do
@body.bytecode(g)
g.ret
end
end
|
#new_local(name) ⇒ Object
1163
1164
1165
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1163
def new_local(name)
variables[name] ||= Compiler::EvalLocalVariable.new name
end
|
#push_state(g) ⇒ Object
1176
1177
1178
1179
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1176
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.
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1152
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
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1133
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
1190
1191
1192
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1190
def sexp_name
:eval
end
|
#should_cache? ⇒ Boolean
1129
1130
1131
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1129
def should_cache?
!@body.kind_of?(AST::ClosedScope)
end
|