|
| 1 | +# This file is part of NIT ( http://www.nitlanguage.org ). |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Compile Nit into Java code runnable on the Java Virtual Machine. |
| 16 | +module nitj |
| 17 | + |
| 18 | +import compiler::java_compiler |
| 19 | + |
| 20 | +# Create a tool context to handle options and paths |
| 21 | +var toolcontext = new ToolContext |
| 22 | +toolcontext.process_options(args) |
| 23 | + |
| 24 | +# We need a model to collect stufs |
| 25 | +var model = new Model |
| 26 | +# And a model builder to parse files |
| 27 | +var modelbuilder = new ModelBuilder(model, toolcontext) |
| 28 | + |
| 29 | +# Collect arguments |
| 30 | +var arguments = toolcontext.option_context.rest |
| 31 | +if arguments.is_empty then |
| 32 | + toolcontext.option_context.usage |
| 33 | + return |
| 34 | +end |
| 35 | +if arguments.length > 1 then |
| 36 | + print "Too much arguments: {arguments.join(" ")}" |
| 37 | + toolcontext.option_context.usage |
| 38 | + return |
| 39 | +end |
| 40 | +var progname = arguments.first |
| 41 | + |
| 42 | +# Here we load an process all modules passed on the command line |
| 43 | +var mmodules = modelbuilder.parse([progname]) |
| 44 | + |
| 45 | +if mmodules.is_empty then return |
| 46 | +modelbuilder.run_phases |
| 47 | + |
| 48 | +var mainmodule |
| 49 | +if mmodules.length == 1 then |
| 50 | + mainmodule = mmodules.first |
| 51 | +else |
| 52 | + mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location) |
| 53 | + mainmodule.set_imported_mmodules(mmodules) |
| 54 | +end |
| 55 | + |
| 56 | +var analysis = modelbuilder.do_rapid_type_analysis(mainmodule) |
| 57 | + |
| 58 | +# Do compilation |
| 59 | +modelbuilder.run_java_compiler(mainmodule, analysis) |
0 commit comments