Module: Heist::Runtime::Expression

Included in:
Binding, Cons, Identifier
Defined in:
lib/heist/runtime/data/expression.rb

Overview

Classes may mix in the Expression module to signal that they represent sections of code that may be evaluated. This is mostly a flag module and does not provide much in the way of extensibility, since the evaluator needs to know how to execute all the kinds of expressions you want it to deal with (for reasons such as tail recursion, expressions are not responsible for evaluating themselves).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/heist/runtime/data/expression.rb', line 11

def parent
  @parent
end

Instance Method Details

#eval(scope) ⇒ Object

Returns the result of evaluating the receiving Expression in the given scope. Works by pushing the receiver and scope onto the runtime stack (could be a Stack or Stackless), which then evaluates the expression using a trampoline.



25
26
27
# File 'lib/heist/runtime/data/expression.rb', line 25

def eval(scope)
  scope.runtime.stack << Frame.new(self, scope)
end

#replace(expression) ⇒ Object

Replaces the receiver with expression in the receiver’s parent expression. This is used as part of the macro expansion process.



15
16
17
18
19
# File 'lib/heist/runtime/data/expression.rb', line 15

def replace(expression)
  return unless @parent
  @parent.car = expression
  @parent.hosts(expression)
end