abstract_compiler: generalize `native_array_instance`
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 12:48:59 +0000 (08:48 -0400)
committerJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 12:48:59 +0000 (08:48 -0400)
offers the service `native_array_instance` in all compilation engines

Signed-off-by: Jean Privat <jean@pryen.org>

src/abstract_compiler.nit
src/global_compiler.nit
src/separate_compiler.nit
src/separate_erasure_compiler.nit

index 0093e60..9061b5f 100644 (file)
@@ -888,6 +888,8 @@ abstract class AbstractCompilerVisitor
                return self.send(callsite.mproperty, args)
        end
 
+       fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable is abstract
+
        fun calloc_array(ret_type: MType, arguments: Array[RuntimeVariable]) is abstract
 
        fun native_array_def(pname: String, ret_type: nullable MType, arguments: Array[RuntimeVariable]) is abstract
index 44ec3a1..8c6ac6c 100644 (file)
@@ -353,6 +353,12 @@ class GlobalCompilerVisitor
                end
        end
 
+       redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
+       do
+               var ret_type = self.get_class("NativeArray").get_mtype([elttype])
+               return self.new_expr("NEW_{ret_type.c_name}({length})", ret_type)
+       end
+
        redef fun calloc_array(ret_type, arguments)
        do
                self.ret(self.new_expr("NEW_{ret_type.c_name}({arguments[1]})", ret_type))
index 36b8082..1b6d680 100644 (file)
@@ -1673,7 +1673,7 @@ class SeparateCompilerVisitor
                return res
        end
 
-       fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
+       redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable
        do
                var mtype = self.get_class("NativeArray").get_mtype([elttype])
                self.require_declaration("NEW_{mtype.mclass.c_name}")
index 4de1a05..a960c60 100644 (file)
@@ -581,6 +581,17 @@ class SeparateErasureCompilerVisitor
                return res
        end
 
+       redef fun native_array_instance(elttype, length)
+       do
+               var nclass = self.get_class("NativeArray")
+               var mtype = nclass.get_mtype([elttype])
+               var res = self.new_var(mtype)
+               res.is_exact = true
+               self.require_declaration("NEW_{nclass.c_name}")
+               self.add("{res} = NEW_{nclass.c_name}({length});")
+               return res
+       end
+
        redef fun array_instance(array, elttype)
        do
                var nclass = self.get_class("NativeArray")