X-Git-Url: http://nitlanguage.org diff --git a/src/nit.nit b/src/nit.nit index 7ed1528..6441b1a 100644 --- a/src/nit.nit +++ b/src/nit.nit @@ -18,18 +18,22 @@ module nit import interpreter -import frontend +import frontend::code_gen import parser_util +import vm # Create a tool context to handle options and paths var toolcontext = new ToolContext +toolcontext.option_context.options_before_rest = true toolcontext.tooldescription = "Usage: nit [OPTION]... ...\nInterprets and debugs Nit programs." -# Add an option "-o" to enable compatibilit with the tests.sh script -var opt = new OptionString("compatibility (does noting)", "-o") +# Add an option "-o" to enable compatibility with the tests.sh script +var opt = new OptionString("Does nothing. Used for compatibility.", "-o") +opt.hidden = true toolcontext.option_context.add_option(opt) -var opt_mixins = new OptionArray("Additionals module to min-in", "-m") var opt_eval = new OptionBool("Specifies the program from command-line", "-e") -toolcontext.option_context.add_option(opt_mixins, opt_eval) +var opt_loop = new OptionBool("Repeatedly run the program for each line in file-name arguments", "-n") +var opt_vm = new OptionBool("Run the virtual machine instead of the naive interpreter (experimental)", "--vm") +toolcontext.option_context.add_option(opt_eval, opt_loop, opt_vm) # We do not add other options, so process them now! toolcontext.process_options(args) @@ -49,36 +53,39 @@ if opt_eval.value then toolcontext.check_errors var parent = null + if opt_loop.value then + parent = modelbuilder.get_mmodule_by_name(null, null, "niti_runtime") + if parent == null then + toolcontext.check_errors + abort + end + end modelbuilder.load_rt_module(parent, amodule, "-") mmodules = [amodule.mmodule.as(not null)] +else if progname == "-" then + var content = stdin.read_all + var amodule = toolcontext.parse_module(content) + toolcontext.check_errors + modelbuilder.load_rt_module(null, amodule, "-") + mmodules = [amodule.mmodule.as(not null)] else mmodules = modelbuilder.parse([progname]) end -mmodules.add_all modelbuilder.parse(opt_mixins.value) modelbuilder.run_phases +toolcontext.run_global_phases(modelbuilder.parsed_modules) -if toolcontext.opt_only_metamodel.value then exit(0) - -var mainmodule: nullable MModule +if toolcontext.opt_only_metamodel.value then toolcontext.quit -# Here we launch the interpreter on the main module -if mmodules.length == 1 then - mainmodule = mmodules.first -else - mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location) - mainmodule.set_imported_mmodules(mmodules) -end +var mainmodule = toolcontext.make_main_module(mmodules) var self_mm = mainmodule var self_args = arguments -if toolcontext.opt_debugger_autorun.value then - modelbuilder.run_debugger_autorun(self_mm, self_args) -else if toolcontext.opt_debugger_mode.value then - modelbuilder.run_debugger(self_mm, self_args) +if opt_vm.value then + modelbuilder.run_virtual_machine(self_mm, self_args) else modelbuilder.run_naive_interpreter(self_mm, self_args) end