X-Git-Url: http://nitlanguage.org diff --git a/src/nit.nit b/src/nit.nit index 5fbefd5..24bb00e 100644 --- a/src/nit.nit +++ b/src/nit.nit @@ -17,17 +17,22 @@ # A naive Nit interpreter module nit -import modelbuilder -import exprbuilder -import naiveinterpreter +import interpreter +import frontend +import parser_util # Create a tool context to handle options and paths var toolcontext = new ToolContext +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") 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") +var opt_loop = new OptionBool("Repeatedly run the program for each line in file-name arguments", "-n") +toolcontext.option_context.add_option(opt_mixins, opt_eval, opt_loop) # We do not add other options, so process them now! -toolcontext.process_options +toolcontext.process_options(args) # We need a model to collect stufs var model = new Model @@ -35,19 +40,55 @@ var model = new Model var modelbuilder = new ModelBuilder(model, toolcontext) var arguments = toolcontext.option_context.rest -if arguments.is_empty then - toolcontext.option_context.usage - return -end var progname = arguments.first # Here we load an process all modules passed on the command line -var mmodules = modelbuilder.parse_and_build([progname]) -modelbuilder.full_propdef_semantic_analysis +var mmodules: Array[MModule] + +if opt_eval.value then + var amodule = toolcontext.parse_module(progname) + toolcontext.check_errors + + var parent = null + if opt_loop.value then + var nruntime = modelbuilder.load_module("niti_runtime") + if nruntime == null then + toolcontext.check_errors + abort + end + parent = nruntime.mmodule + end + + modelbuilder.load_rt_module(parent, amodule, "-") + + mmodules = [amodule.mmodule.as(not null)] +else + mmodules = modelbuilder.parse([progname]) +end + +mmodules.add_all modelbuilder.parse(opt_mixins.value) +modelbuilder.run_phases if toolcontext.opt_only_metamodel.value then exit(0) +var mainmodule: nullable MModule + # Here we launch the interpreter on the main module -assert mmodules.length == 1 -var mainmodule = mmodules.first -modelbuilder.run_naive_interpreter(mainmodule, arguments) +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 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) +else + modelbuilder.run_naive_interpreter(self_mm, self_args) +end +