import platform
import c_tools
private import annotation
+import mixin
# Add compiling options
redef class ToolContext
# Create a tool context to handle options and paths
var toolcontext = new ToolContext
-var opt_mixins = new OptionArray("Additionals module to min-in", "-m")
-toolcontext.option_context.add_option(opt_mixins)
-
toolcontext.tooldescription = "Usage: nitg [OPTION]... file.nit...\nCompiles Nit programs."
# We do not add other options, so process them now!
# Here we load an process all modules passed on the command line
var mmodules = modelbuilder.parse(arguments)
-var mixins = modelbuilder.parse(opt_mixins.value)
if mmodules.is_empty then return
modelbuilder.run_phases
for mmodule in mmodules do
toolcontext.info("*** PROCESS {mmodule} ***", 1)
var ms = [mmodule]
- if not mixins.is_empty then
- ms.add_all mixins
- end
toolcontext.run_global_phases(ms)
end
import literal
import semantize
private import parser::tables
+import mixin
redef class ToolContext
# --discover-call-trace
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Loading and additional module refinements at link-time.
+#
+# Used to factorize some code used by the engines.
+module mixin
+
+import modelbuilder
+
+redef class ToolContext
+ # --mixin
+ var opt_mixins = new OptionArray("Additionals module to min-in", "-m", "--mixin")
+
+ redef init
+ do
+ super
+ option_context.add_option(opt_mixins)
+ end
+
+ redef fun make_main_module(mmodules)
+ do
+ var mixins = opt_mixins.value
+ if not mixins.is_empty then
+ mmodules.add_all modelbuilder.parse(opt_mixins.value)
+ modelbuilder.run_phases
+ end
+
+ var mainmodule = super
+
+ return mainmodule
+ end
+end
# 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)
+toolcontext.option_context.add_option(opt_eval, opt_loop)
# We do not add other options, so process them now!
toolcontext.process_options(args)
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
-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