import abstract_compiler
import rapid_type_analysis
-import compiler_ffi
+
+redef class ToolContext
+ # option --global
+ var opt_global = new OptionBool("Use global compilation", "--global")
+
+ var global_compiler_phase = new GlobalCompilerPhase(self, null)
+
+ redef init do
+ super
+ option_context.add_option(opt_global)
+ end
+end
+
+class GlobalCompilerPhase
+ super Phase
+ redef fun process_mainmodule(mainmodule, given_mmodules) do
+ if not toolcontext.opt_global.value then return
+
+ var modelbuilder = toolcontext.modelbuilder
+ var analysis = modelbuilder.do_rapid_type_analysis(mainmodule)
+ modelbuilder.run_global_compiler(mainmodule, analysis)
+ end
+end
redef class ModelBuilder
# Entry point to performs a global compilation on the AST of a complete program.
if mtype.mclass.name == "NativeArray" then
# NativeArrays are just a instance header followed by an array of values
+ v.add_decl("int length;")
v.add_decl("{mtype.arguments.first.ctype} values[1];")
end
if is_native_array then
var mtype_elt = mtype.arguments.first
v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}) + length*sizeof({mtype_elt.ctype}));")
+ v.add("((struct {mtype.c_name}*){res})->length = length;")
else
v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}));")
end
end
self.add("{res} = BOX_{valtype.c_name}({value}); /* autobox from {value.mtype} to {mtype} */")
return res
- else if value.mtype.cname_blind == "void*" and mtype.cname_blind == "void*" then
+ else if value.mtype.ctype == "void*" and mtype.ctype == "void*" then
return value
else
# Bad things will appen!
else if pname == "[]=" then
self.add("{recv}[{arguments[1]}]={arguments[2]};")
return
+ else if pname == "length" then
+ self.ret(self.new_expr("((struct {arguments[0].mcasttype.c_name}*){arguments[0]})->length", ret_type.as(not null)))
+ return
else if pname == "copy_to" then
var recv1 = "((struct {arguments[1].mcasttype.c_name}*){arguments[1]})->values"
self.add("memcpy({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));")
var frame = new Frame(v, mmethoddef, recv, arguments)
v.frame = frame
- var sig = new Buffer
- var comment = new Buffer
+ var sig = new FlatBuffer
+ var comment = new FlatBuffer
var ret = mmethoddef.msignature.return_mtype
if ret != null then
ret = v.resolve_for(ret, selfvar)