This commit only introduce a stub and a way to test it.
Code generation will be added in next commits.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
--- /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.
+
+# Compile Nit code to Java code
+#
+# 3 runtime structures are used to represent Nit instance in Java generated code:
+# * `RTClass` to represent a class, it's super-type table and its VFT
+# * `RTMethod` to reprensent a compiled method definition
+# * `RTVal` to reprensent a Nit instance, the null value or a native value
+#
+# More details are given in the documentation of these 3 classes.
+#
+# TODO Factorize with `abstract_compiler`
+module java_compiler
+
+import rapid_type_analysis
+import frontend
+
+redef class ToolContext
+
+ # Where to output the generated binary
+ var opt_output = new OptionString("Output file", "-o", "--output")
+
+ # Where to output tmp files
+ var opt_compile_dir = new OptionString("Directory used to generate temporary files", "--compile-dir")
+
+ redef init do
+ super
+ option_context.add_option(opt_output, opt_compile_dir)
+ end
+end
+
+redef class ModelBuilder
+
+ # Start the Java compiler
+ fun run_java_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis) do
+ var time0 = get_time
+ toolcontext.info("*** GENERATING JAVA ***", 1)
+
+ toolcontext.info("NOT YET IMPLEMENTED", 0)
+
+ var time1 = get_time
+ toolcontext.info("*** END GENERATING JAVA: {time1-time0} ***", 2)
+ end
+end
--- /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.
+
+# Compile Nit into Java code runnable on the Java Virtual Machine.
+module nitj
+
+import compiler::java_compiler
+
+# Create a tool context to handle options and paths
+var toolcontext = new ToolContext
+toolcontext.process_options(args)
+
+# We need a model to collect stufs
+var model = new Model
+# And a model builder to parse files
+var modelbuilder = new ModelBuilder(model, toolcontext)
+
+# Collect arguments
+var arguments = toolcontext.option_context.rest
+if arguments.is_empty then
+ toolcontext.option_context.usage
+ return
+end
+if arguments.length > 1 then
+ print "Too much arguments: {arguments.join(" ")}"
+ 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([progname])
+
+if mmodules.is_empty then return
+modelbuilder.run_phases
+
+var mainmodule
+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 analysis = modelbuilder.do_rapid_type_analysis(mainmodule)
+
+# Do compilation
+modelbuilder.run_java_compiler(mainmodule, analysis)
OPT="--vm $OPT"
savdirs="sav/niti/"
;;
+ nitj)
+ engine=nitj;
+ OPT="--compile-dir $compdir"
+ enginebinname=nitj;
+ savdirs="sav/nitc-common/"
+ ;;
emscripten)
enginebinname=nitc
OPT="-m emscripten_nodejs.nit --semi-global $OPT --compile-dir $compdir"