1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Compile Nit into Java code runnable on the Java Virtual Machine.
18 import compiler
::java_compiler
20 # Create a tool context to handle options and paths
21 var toolcontext
= new ToolContext
22 toolcontext
.process_options
(args
)
24 # We need a model to collect stufs
26 # And a model builder to parse files
27 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
30 var arguments
= toolcontext
.option_context
.rest
31 if arguments
.is_empty
then
32 toolcontext
.option_context
.usage
35 if arguments
.length
> 1 then
36 print
"Too much arguments: {arguments.join(" ")}"
37 toolcontext
.option_context
.usage
40 var progname
= arguments
.first
42 # Here we load an process all modules passed on the command line
43 var mmodules
= modelbuilder
.parse
([progname
])
45 if mmodules
.is_empty
then return
46 modelbuilder
.run_phases
49 if mmodules
.length
== 1 then
50 mainmodule
= mmodules
.first
52 mainmodule
= new MModule(model
, null, mmodules
.first
.name
, mmodules
.first
.location
)
53 mainmodule
.set_imported_mmodules
(mmodules
)
56 var analysis
= modelbuilder
.do_rapid_type_analysis
(mainmodule
)
59 modelbuilder
.run_java_compiler
(mainmodule
, analysis
)