# A single C file regroups many compiled rumtime functions
# Note that we do not try to be clever an a small change in a Nit source file may change the content of all the generated .c files
var time0 = get_time
+ self.toolcontext.info("*** WRITING C ***", 1)
".nit_compile".mkdir
var outname = self.toolcontext.opt_output.value
if outname == null then
- outname = "{mainmodule.name}.bin"
+ outname = "{mainmodule.name}"
end
var hfilename = compiler.header.file.name + ".h"
#p = "..".join_path(p)
cc_includes += " -I \"" + p + "\""
end
- makefile.write("CC = ccache cc\nCFLAGS = -g -O2{cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc\n\n")
+ makefile.write("CC = ccache cc\nCFLAGS = -g -O2\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc\n\n")
makefile.write("all: {outname}\n\n")
var ofiles = new Array[String]
# Compile each generated file
for f in cfiles do
var o = f.strip_extension(".c") + ".o"
- makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) -D NONITCNI -c -o {o} {f}\n\n")
+ makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) $(CINCL) -D NONITCNI -c -o {o} {f}\n\n")
ofiles.add(o)
end
self.toolcontext.info("Generated makefile: {makename}", 2)
var time1 = get_time
- self.toolcontext.info("*** END COMPILING TO C: {time1-time0} ***", 2)
+ self.toolcontext.info("*** END WRITING C: {time1-time0} ***", 2)
# Execute the Makefile
abstract class AbstractCompiler
type VISITOR: AbstractCompilerVisitor
- # The main module of the program
- var mainmodule: MModule protected writable
+ # The main module of the program currently compiled
+ # Is assigned during the separate compilation
+ var mainmodule: MModule writable
+
+ # The real main module of the program
+ var realmainmodule: MModule
# The modeulbuilder used to know the model and the AST
var modelbuilder: ModelBuilder protected writable
init(mainmodule: MModule, modelbuilder: ModelBuilder)
do
self.mainmodule = mainmodule
+ self.realmainmodule = mainmodule
self.modelbuilder = modelbuilder
end
else if pname == "force_garbage_collection" then
v.add("nit_gcollect();")
return
+ else if pname == "native_argc" then
+ v.ret(v.new_expr("glob_argc", ret.as(not null)))
+ return
+ else if pname == "native_argv" then
+ v.ret(v.new_expr("glob_argv[{arguments[1]}]", ret.as(not null)))
+ return
end
v.add("printf(\"NOT YET IMPLEMENTED {class_name}:{mpropdef} at {location.to_s}\\n\");")
debug("Not implemented {mpropdef}")