Class: Nydp::Runner

Inherits:
Evaluator show all
Defined in:
lib/nydp/runner.rb

Instance Attribute Summary

Attributes inherited from Evaluator

#name, #ns, #vm

Instance Method Summary collapse

Methods inherited from Evaluator

#compile_and_eval, #evaluate, #pre_compile

Constructor Details

#initialize(vm, ns, stream, printer = nil, name = nil) ⇒ Runner

Returns a new instance of Runner.



68
69
70
71
72
73
# File 'lib/nydp/runner.rb', line 68

def initialize vm, ns, stream, printer=nil, name=nil
  super vm, ns, name
  @printer    = printer
  @parser     = Nydp.new_parser(ns)
  @tokens     = Nydp.new_tokeniser stream
end

Instance Method Details



75
76
77
# File 'lib/nydp/runner.rb', line 75

def print val
  @printer.puts val.inspect if @printer
end

#runObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/nydp/runner.rb', line 79

def run
  Nydp.apply_function ns, :"script-run", :"script-start", name
  res = Nydp::NIL
  begin
    while !@tokens.finished
      expr = @parser.expression(@tokens)
      print(res = evaluate(expr)) unless expr.nil?
    end
  ensure
    Nydp.apply_function ns, :"script-run", :"script-end", name
  end
  res
end