compiler: special handling of `new NativeArray`
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 12:58:17 +0000 (08:58 -0400)
committerJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 12:58:17 +0000 (08:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit

index 9061b5f..92520bf 100644 (file)
@@ -2608,7 +2608,13 @@ redef class ANewExpr
                var mtype = self.mtype.as(MClassType)
                var recv
                var ctype = mtype.ctype
-               if ctype == "val*" then
+               if mtype.mclass.name == "NativeArray" then
+                       assert self.n_args.n_exprs.length == 1
+                       var l = v.expr(self.n_args.n_exprs.first, null)
+                       assert mtype isa MGenericType
+                       var elttype = mtype.arguments.first
+                       return v.native_array_instance(elttype, l)
+               else if ctype == "val*" then
                        recv = v.init_instance(mtype)
                else if ctype == "void*" then
                        recv = v.new_expr("NULL/*special!*/", mtype)