Module: RVM::Interpreter
- Included in:
- Languages::Math::Compiler
- Defined in:
- lib/rvm/interpreter.rb,
lib/rvm/environment.rb,
lib/rvm/optimisation.rb
Overview
This Module hold all the VM classes that are used to execute and evaluate code for the VM, so it is quite important to read and understand if you feel like making a own compiler.
For someone not interested in going as deep into building a own compiler it still is a good start for understanding how rVM works, yet it is not mandatory to read.
The basic idea of this objects is that the compiler translates the source code into a tree of RVM::Interpreter objects to build the behavior that is expected. Once that is done the code can be executed by calling #execute for the root of the object tree.
Defined Under Namespace
Classes: Assignment, Block, Condition, Constant, CoreCall, Declaration, Element, Environment, FunctionCall, FunctionDefinition, Loop, ObjectContext, Parameter, Return, ReturnException, RuntimeError, Sequence, SetClassFunction, SimpleAssignment, SimpleDeclaration, SimpleVariable, Variable, VariableStorage, VariableStorageCallback
Class Method Summary collapse
-
.const(type, value, pos = nil) ⇒ Object
This is a helper function that generates a constat of a simple constant, for example if you’ve a lot of string constants it is way quickly to call this then writing it out the whole time.
-
.env(aenv = {}) ⇒ Object
This is a helper fuctio to quickly generate a empty enviorment.
Instance Method Summary collapse
-
#optimize ⇒ Object
Optimization of the loop.
Class Method Details
.const(type, value, pos = nil) ⇒ Object
This is a helper function that generates a constat of a simple constant, for example if you’ve a lot of string constants it is way quickly to call this then writing it out the whole time.
82 83 84 |
# File 'lib/rvm/interpreter.rb', line 82 def Interpreter.const type, value, pos = nil RVM::Interpreter::Constant.new(RVM::Classes[type].new(value), pos) end |
.env(aenv = {}) ⇒ Object
This is a helper fuctio to quickly generate a empty enviorment. A hash can be passed to store variables.
:locals can be a hash holding local variables :functions can be a hash to hold functions defined in the the scope
74 75 76 77 |
# File 'lib/rvm/interpreter.rb', line 74 def Interpreter.env aenv = {} RVM::debug "Interpreter.env" if $DEBUG Environment.new aenv end |
Instance Method Details
#optimize ⇒ Object
Optimization of the loop
307 308 309 310 311 |
# File 'lib/rvm/interpreter.rb', line 307 def optimize @condition = @condition.optimize @body = @body.optimize super end |