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.
1175
1176
1177
1178
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1175
def initialize(body)
super body
@name = :__eval_script__
end
|
Instance Method Details
#assign_local_reference(var) ⇒ Object
1218
1219
1220
1221
1222
1223
1224
1225
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1218
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
1232
1233
1234
1235
1236
1237
1238
1239
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1232
def bytecode(g)
super(g)
container_bytecode(g) do
@body.bytecode(g)
g.ret
end
end
|
#new_local(name) ⇒ Object
1214
1215
1216
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1214
def new_local(name)
variables[name] ||= Compiler::EvalLocalVariable.new name
end
|
#push_state(g) ⇒ Object
1227
1228
1229
1230
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1227
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.
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1203
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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1184
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
1241
1242
1243
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1241
def sexp_name
:eval
end
|
#should_cache? ⇒ Boolean
1180
1181
1182
|
# File 'lib/rubinius/code/ast/definitions.rb', line 1180
def should_cache?
!@body.kind_of?(AST::ClosedScope)
end
|