lib/nydp.rb in nydp-0.3.0 vs lib/nydp.rb in nydp-0.4.0
- old
+ new
@@ -3,10 +3,11 @@
module Nydp
class Namespace < Hash
end
+ # TODO: write VM #apply_function so we have fewer calls to VM.new
def self.apply_function ns, function_name, *args
function = r2n(function_name.to_sym, ns).value
args = r2n args, ns
vm = VM.new(ns)
@@ -16,10 +17,12 @@
def self.reader txt ; Nydp::StringReader.new txt ; end
def self.eval_src ns, src_txt, name=nil ; eval_with Nydp::Runner, ns, src_txt, name ; end
def self.eval_with runner, ns, src_txt, name ; runner.new(VM.new(ns), ns, reader(src_txt), nil, name).run ; end
def self.ms t1, t0 ; ((t1 - t0) * 1000).to_i ; end
+ def self.new_tokeniser reader ; Nydp::Tokeniser.new reader ; end
+ def self.new_parser ns ; Nydp::Parser.new(ns) ; end
def self.indent_message indent, msg
msg.split(/\n/).map { |line| "#{indent}#{line}" }.join("\n")
end
@@ -45,15 +48,16 @@
end
end
def self.repl options={ }
toplevel do
- silent = options[:silent]
+ silent = options.delete :silent
+ ns = options.delete :ns
launch_time = Time.now
last_script_time = Time.now
puts "welcome to nydp #{options.inspect}" unless silent
reader = Nydp::ReadlineReader.new $stdin, "nydp > "
- ns = build_nydp do |script|
+ ns ||= build_nydp do |script|
this_script_time = Time.now
puts "script #{script} time #{ms this_script_time, last_script_time}ms" if options[:verbose]
last_script_time = this_script_time
end
load_time = Time.now