src: remove useless comparisons on null
[nit.git] / src / nit.nit
index be71611..24bb00e 100644 (file)
@@ -17,9 +17,9 @@
 # A naive Nit interpreter
 module nit
 
-import naive_interpreter
-import debugger
-import debugger_socket
+import interpreter
+import frontend
+import parser_util
 
 # Create a tool context to handle options and paths
 var toolcontext = new ToolContext
@@ -28,7 +28,9 @@ toolcontext.tooldescription = "Usage: nit [OPTION]... <file.nit>...\nInterprets
 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")
-toolcontext.option_context.add_option(opt_mixins)
+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(args)
 
@@ -41,7 +43,29 @@ var arguments = toolcontext.option_context.rest
 var progname = arguments.first
 
 # Here we load an process all modules passed on the command line
-var mmodules = modelbuilder.parse([progname])
+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