Class: Heist::Runtime::Stackless

Inherits:
Object
  • Object
show all
Defined in:
lib/heist/runtime/stackless.rb

Overview

The Stackless class provides a faster execution model than Stack, as it does not provide fine-grained enough escape points to allow fully for continuations. Continuations aside, Stackless supports all the same language features as Stack, including using a trampoline to implement tail call optimisation.

Instance Method Summary collapse

Instance Method Details

#<<(frame) ⇒ Object

Returns the result of evaluating the Expression in the given Frame object. This API probably looks a little weird; it’s like this for consistency with the Stack API so the two can be used interchangeably without changing the implementation of Expression#eval.

The expression is evaluated by repeatedly calling Functions until a concrete value is returned. Calling a Scheme procedure returns a Body object that binds its body to the Scope created by calling the procedure. As functions do not evaluate themselves we can turn what would be a recursive process into an iterative one and optimise tail calls. This technique is known as trampolining.



24
25
26
27
28
# File 'lib/heist/runtime/stackless.rb', line 24

def <<(frame)
  @current = frame
  @current = process! while incomplete?
  @current
end