Class: RVM::Interpreter::SimpleDeclaration

Inherits:
Declaration show all
Defined in:
lib/rvm/optimisation.rb

Overview

For details see RVM::Interpreter::Declration, this is a optimized version vor simple cases.

Only #value# is evaluated before the assignment is done.

Instance Attribute Summary

Attributes inherited from Element

#pos

Instance Method Summary collapse

Methods inherited from Declaration

#data_type, #pretty_print

Constructor Details

#initialize(name, value, pos = nil) ⇒ SimpleDeclaration

A Declaration is initialized wiht 2 to 3 parameters.

name

The name of the variable to store, it will be executed, usually this will be a Constant, unless dynamic naming is needed by the implemented language.

value

The value that will be assigned to the variable, for a = 1 + 1 ‘1+1’ would be the value to assign, so as this already suggests the value will be executed.

pos

The position within the source code of the definition - for deugging purpose.



88
89
90
91
92
# File 'lib/rvm/optimisation.rb', line 88

def initialize name, value, pos = nil
  @pos = pos
  @name = name.to_s
  @value = value
end

Instance Method Details

#execute(env) ⇒ Object

Only the value is evaluated before assigning it, the name is taken to be a string.

For details see RVM::Interpreter::Declration



98
99
100
101
# File 'lib/rvm/optimisation.rb', line 98

def execute env
  RVM::debug "Executing SimpleAssignment at #{@pos}..." if $DEBUG
  env.declare(@name,@value.execute(env)).val
end

#optimizeObject



103
104
105
106
# File 'lib/rvm/optimisation.rb', line 103

def optimize
  @value = @value.optimize
  self
end