Class: Heist::Scheme::Program

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/parser/nodes.rb

Overview

Program is the root of the parse tree; parsing any string of Scheme code produces one of these.

Instance Method Summary collapse

Instance Method Details

#convert!Object

Converts all the Treetop objects in the Program to Heist objects and raw Ruby data ready for interpretation using a Runtime.



33
34
35
36
# File 'lib/parser/nodes.rb', line 33

def convert!
  return @data if @data
  @data = Runtime::Cons.construct(elements[1].elements, true) { |c| c.eval }
end

#eval(scope) ⇒ Object

Evaluates all the expressions in the Program in order, returning the result of the last expression.



26
27
28
29
# File 'lib/parser/nodes.rb', line 26

def eval(scope)
  convert!
  @data.map { |part| Heist.evaluate(part, scope) }.last
end