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.
1160
1161
1162
1163
|
# File 'lib/rubinius/ast/definitions.rb', line 1160
def initialize(body)
super body
@name = :__eval_script__
end
|
Instance Method Details
#assign_local_reference(var) ⇒ Object
1203
1204
1205
1206
1207
1208
1209
1210
|
# File 'lib/rubinius/ast/definitions.rb', line 1203
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
1217
1218
1219
1220
1221
1222
1223
1224
|
# File 'lib/rubinius/ast/definitions.rb', line 1217
def bytecode(g)
super(g)
container_bytecode(g) do
@body.bytecode(g)
g.ret
end
end
|
#new_local(name) ⇒ Object
1199
1200
1201
|
# File 'lib/rubinius/ast/definitions.rb', line 1199
def new_local(name)
variables[name] ||= Compiler::EvalLocalVariable.new name
end
|
#push_state(g) ⇒ Object
1212
1213
1214
1215
|
# File 'lib/rubinius/ast/definitions.rb', line 1212
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.
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
|
# File 'lib/rubinius/ast/definitions.rb', line 1188
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
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
|
# File 'lib/rubinius/ast/definitions.rb', line 1169
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
1226
1227
1228
|
# File 'lib/rubinius/ast/definitions.rb', line 1226
def sexp_name
:eval
end
|
#should_cache? ⇒ Boolean
1165
1166
1167
|
# File 'lib/rubinius/ast/definitions.rb', line 1165
def should_cache?
!@body.kind_of?(AST::ClosedScope)
end
|