lib/nydp.rb in nydp-0.0.6 vs lib/nydp.rb in nydp-0.0.7
- old
+ new
@@ -5,36 +5,46 @@
def self.load_rake_tasks; PLUGINS.each &:load_rake_tasks ; end
def self.setup ns; PLUGINS.each { |plg| plg.setup ns } ; end
def self.loadfiles; PLUGINS.map(&:loadfiles).flatten ; end
def self.testfiles; PLUGINS.map(&:testfiles).flatten ; end
def self.plugin_names ; PLUGINS.map(&:name) ; end
- def self.loadall vm, ns, files
+ def self.loadall ns, files
+ vm = VM.new
files.each { |f|
reader = Nydp::StreamReader.new(File.new(f))
Nydp::Runner.new(vm, ns, reader).run
}
end
- def self.repl
- puts "welcome to nydp"
+ def self.build_nydp extra_files=nil
ns = { }
setup(ns)
- vm = VM.new
- loadall vm, ns, loadfiles
+ loadall ns, loadfiles
+ loadall ns, extra_files if extra_files
+ ns
+ end
+
+ def self.apply_function ns, function_name, *args
+ function = Nydp::Symbol.mk(function_name, ns).value
+ args = Nydp::Pair.from_list args
+ vm = VM.new
+
+ function.invoke vm, args
+ return vm.pop_arg
+ end
+
+ def self.repl
+ puts "welcome to nydp"
+ puts "^D to exit"
reader = Nydp::ReadlineReader.new $stdin, "nydp > "
- Nydp::Runner.new(vm, ns, reader, $stdout).run
+ Nydp::Runner.new(VM.new, build_nydp, reader, $stdout).run
end
def self.tests *options
verbose = options.include?(:verbose) ? "t" : "nil"
puts "welcome to nydp : running tests"
- ns = { }
- setup(ns)
- vm = VM.new
- loadall vm, ns, loadfiles
- loadall vm, ns, testfiles
reader = Nydp::StringReader.new "(run-all-tests #{verbose})"
- Nydp::Runner.new(vm, ns, reader).run
+ Nydp::Runner.new(VM.new, build_nydp(testfiles), reader).run
end
end
require "nydp/core"