Class: CodeTools::AST::EvalExpression

Inherits:
Container show all
Defined in:
lib/rubinius/code/ast/definitions.rb

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

#initialize(body) ⇒ EvalExpression

Returns a new instance of EvalExpression.



1163
1164
1165
1166
# File 'lib/rubinius/code/ast/definitions.rb', line 1163

def initialize(body)
  super body
  @name = :__eval_script__
end

Instance Method Details

#assign_local_reference(var) ⇒ Object



1206
1207
1208
1209
1210
1211
1212
1213
# File 'lib/rubinius/code/ast/definitions.rb', line 1206

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



1220
1221
1222
1223
1224
1225
1226
1227
# File 'lib/rubinius/code/ast/definitions.rb', line 1220

def bytecode(g)
  super(g)

  container_bytecode(g) do
    @body.bytecode(g)
    g.ret
  end
end

#new_local(name) ⇒ Object



1202
1203
1204
# File 'lib/rubinius/code/ast/definitions.rb', line 1202

def new_local(name)
  variables[name] ||= Compiler::EvalLocalVariable.new name
end

#push_state(g) ⇒ Object



1215
1216
1217
1218
# File 'lib/rubinius/code/ast/definitions.rb', line 1215

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.



1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/rubinius/code/ast/definitions.rb', line 1191

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



1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/rubinius/code/ast/definitions.rb', line 1172

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_nameObject



1229
1230
1231
# File 'lib/rubinius/code/ast/definitions.rb', line 1229

def sexp_name
  :eval
end

#should_cache?Boolean

Returns:

  • (Boolean)


1168
1169
1170
# File 'lib/rubinius/code/ast/definitions.rb', line 1168

def should_cache?
  !@body.kind_of?(AST::ClosedScope)
end