Class: Crisp::Runtime

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

Overview

The Crisp Runtime

Each runtime holds its own environment. All predefined functions are loaded when creating a new runtime. Run code by calling run with the output of the parser as argurment.

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Runtime

create a new env and load all functions when creating a new runtime



9
10
11
12
# File 'lib/crisp/runtime.rb', line 9

def initialize(env = nil)
  @env = env || Env.new
  Functions.load(@env) if !env
end

Instance Method Details

#run(ast) ⇒ Object

run the parsed code (abstract syntax tree)



15
16
17
# File 'lib/crisp/runtime.rb', line 15

def run(ast)
  ast.eval(@env)
end