X-Git-Url: http://nitlanguage.org diff --git a/src/compiler/java_compiler.nit b/src/compiler/java_compiler.nit index 85613cf..0933a36 100644 --- a/src/compiler/java_compiler.nit +++ b/src/compiler/java_compiler.nit @@ -754,6 +754,17 @@ class JavaCompilerVisitor # TODO return array_instance(varargs, elttype) end + # Nit instances + + # Generate a alloc-instance + init-attributes + fun init_instance(mtype: MClassType): RuntimeVariable do + var recv = new_recv(mtype) + var mclass = mtype.mclass + add("{recv} = new RTVal({mclass.rt_name}.get{mclass.rt_name}());") + # TODO init attributes + return recv + end + # Utils # Display a info message @@ -1139,6 +1150,31 @@ redef class ASendExpr end end +redef class ANewExpr + redef fun expr(v) + do + var mtype = self.recvtype + assert mtype != null + + if mtype.mclass.name == "NativeArray" then + # TODO handle native arrays + v.info("NOT YET IMPLEMENTED new NativeArray") + end + + var recv = v.init_instance(mtype) + + var callsite = self.callsite + if callsite == null then return recv + + var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs) + var res2 = v.compile_callsite(callsite, args) + if res2 != null then + return res2 + end + return recv + end +end + redef class ASelfExpr redef fun expr(v) do return v.frame.as(not null).arguments.first end