v.add_decl("#include <string.h>")
# TODO: Better way to activate the GC
- #v.add_decl("#include <gc/gc.h>")
- v.add_decl("#define GC_MALLOC(x) calloc(1, (x))")
+ v.add_decl("#include <gc/gc.h>")
+ #v.add_decl("#define GC_MALLOC(x) calloc(1, (x))")
# Declare structure for each live type
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) -I .nit_compile -I ../clib -c -o {o} {f}\n\n")
+ makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) -D NONITCNI -c -o {o} {f}\n\n")
ofiles.add(o)
end
-
- makefile.write("{outname}: {ofiles.join(" ")} {compiler.extern_bodies.join(" ")}\n\t$(CC) -Wl,--warn-unresolved-symbols $(CFLAGS) $(LDFLAGS) $(LDLIBS) -I .nit_compile -I ../clib -o {outname} {ofiles.join(" ")} {compiler.extern_bodies.join(" ")}\n\n")
+ # Compile each required extern body into a specific .o
+ for f in compiler.extern_bodies do
+ i += 1
+ var o = ".nit_compile/{mainmodule.name}.{i}.o"
+ makefile.write("{o}: {f}\n\t$(CC) $(CFLAGS) -D NONITCNI -c -o {o} {f}\n\n")
+ ofiles.add(o)
+ end
+ # Link edition
+ makefile.write("{outname}: {ofiles.join(" ")}\n\t$(CC) $(LDFLAGS) $(LDLIBS) -o {outname} {ofiles.join(" ")}\n\n")
+ # Clean
+ makefile.write("clean:\n\trm {ofiles.join(" ")} 2>/dev/null\n\n")
makefile.close
self.toolcontext.info("Generated makefile: {makename}", 2)
if tryfile.file_exists then
self.extern_bodies.add(tryfile)
end
- #(new OFStream.open("{file.basename("")}._nitni.h")).close
end
end
vararg.add(rawargs[i+1])
end
# FIXME: its it to late to determine the vararg type, this should have been done during a previous analysis
- var elttype = m.msignature.parameter_mtypes[vararg_rank]
+ var elttype = m.msignature.mparameters[vararg_rank].mtype
elttype = self.resolve_for(elttype, recv)
args.add(self.array_instance(vararg, elttype))
do
var recv = args.first
for i in [0..m.msignature.arity[ do
- var t = m.msignature.parameter_mtypes[i]
+ var t = m.msignature.mparameters[i].mtype
if i == m.msignature.vararg_rank then
t = args[i+1].mtype
end
fun add_abort(message: String)
do
if self.current_node != null and self.current_node.location.file != null then
- self.add("fprintf(stderr, \"%s (%s:%d)\\n\", \"{message.escape_to_c}\", \"{self.current_node.location.file.filename.escape_to_c}\", {current_node.location.line_start});")
+ self.add("fprintf(stderr, \"Runtime error: %s (%s:%d)\\n\", \"{message.escape_to_c}\", \"{self.current_node.location.file.filename.escape_to_c}\", {current_node.location.line_start});")
else
- self.add("fprintf(stderr, \"%s\\n\", \"{message.escape_to_c}\");")
+ self.add("fprintf(stderr, \"Runtime error: %s\\n\", \"{message.escape_to_c}\");")
end
self.add("exit(1);")
end
comment.append("(self: {recv}")
arguments.add(selfvar)
for i in [0..self.msignature.arity[ do
- var mtype = self.msignature.parameter_mtypes[i]
+ var mtype = self.msignature.mparameters[i].mtype
if i == self.msignature.vararg_rank then
mtype = v.get_class("Array").get_mtype([mtype])
end
redef class APropdef
private fun compile_to_c(v: GlobalCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
do
- v.add("printf(\"Not implemented {class_name} {mpropdef} at {location.to_s}\\n\");")
+ v.add("printf(\"NOT YET IMPLEMENTED {class_name} {mpropdef} at {location.to_s}\\n\");")
debug("Not yet implemented")
end
end
return
end
- v.add("printf(\"Not implemented {class_name}:{mpropdef} at {location.to_s}\\n\");")
+ v.add("printf(\"NOT IMPLEMENTED {class_name}:{mpropdef} at {location.to_s}\\n\");")
debug("Not implemented {mpropdef}")
end
end
private fun expr(v: GlobalCompilerVisitor): nullable RuntimeVariable
do
debug("Unimplemented expr {class_name}")
- v.add("printf(\"Not implemented {class_name}:{location.to_s}\\n\");")
+ v.add("printf(\"NOT YET IMPLEMENTED {class_name}:{location.to_s}\\n\");")
var mtype = self.mtype
if mtype == null then
return null
var ok = v.send(v.get_property("is_ok", it.mtype), [it])
assert ok != null
v.add("if(!{ok}) break;")
- var i = v.send(v.get_property("item", it.mtype), [it])
- assert i != null
- v.assign(v.variable(variables.first), i)
+ if self.variables.length == 1 then
+ var i = v.send(v.get_property("item", it.mtype), [it])
+ assert i != null
+ v.assign(v.variable(variables.first), i)
+ else if self.variables.length == 2 then
+ var i = v.send(v.get_property("key", it.mtype), [it])
+ assert i != null
+ v.assign(v.variable(variables[0]), i)
+ i = v.send(v.get_property("item", it.mtype), [it])
+ assert i != null
+ v.assign(v.variable(variables[1]), i)
+ else
+ abort
+ end
v.stmt(self.n_block)
v.add("CONTINUE_{v.escapemark_name(escapemark)}: (void)0;")
v.send(v.get_property("next", it.mtype), [it])
do
var recv = v.expr(self.n_expr, null)
var args = [recv]
- for a in compute_raw_arguments do
+ for a in self.raw_arguments.as(not null) do
args.add(v.expr(a, null))
end
var mproperty = self.mproperty.as(not null)
do
var recv = v.expr(self.n_expr, null)
var args = [recv]
- for a in compute_raw_arguments do
+ for a in self.raw_arguments.as(not null) do
args.add(v.expr(a, null))
end
var value = v.expr(self.n_value, null)