From dcd0caa1a853368af2ac360763943b20538e380b Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 15 Dec 2015 16:59:38 -0500 Subject: [PATCH] compiler: intern methods on NativeArray can fallback instead of no-op Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 5 ++--- src/compiler/global_compiler.nit | 9 +++++---- src/compiler/separate_compiler.nit | 9 +++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 7824b92..f0a05c9 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1180,7 +1180,7 @@ abstract class AbstractCompilerVisitor 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 + fun native_array_def(pname: String, ret_type: nullable MType, arguments: Array[RuntimeVariable]): Bool do return false # Return an element of a native array. # The method is unsafe and is just a direct wrapper for the specific implementation of native arrays @@ -2491,8 +2491,7 @@ redef class AMethPropdef return true end else if cname == "NativeArray" then - v.native_array_def(pname, ret, arguments) - return true + return v.native_array_def(pname, ret, arguments) else if cname == "Int8" then if pname == "output" then v.add("printf(\"%\"PRIi8 \"\\n\", {arguments.first});") diff --git a/src/compiler/global_compiler.nit b/src/compiler/global_compiler.nit index d9958d8..d2a8a0c 100644 --- a/src/compiler/global_compiler.nit +++ b/src/compiler/global_compiler.nit @@ -385,18 +385,19 @@ class GlobalCompilerVisitor var recv = "((struct {arguments[0].mcasttype.c_name}*){arguments[0]})->values" if pname == "[]" then self.ret(self.new_expr("{recv}[{arguments[1]}]", ret_type.as(not null))) - return + return true else if pname == "[]=" then self.add("{recv}[{arguments[1]}]={arguments[2]};") - return + return true 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 + return true else if pname == "copy_to" then var recv1 = "((struct {arguments[1].mcasttype.c_name}*){arguments[1]})->values" self.add("memmove({recv1},{recv},{arguments[2]}*sizeof({elttype.ctype}));") - return + return true end + return false end redef fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index e13c735..e67c199 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -2110,18 +2110,19 @@ class SeparateCompilerVisitor var res = self.new_expr("{recv}[{arguments[1]}]", compiler.mainmodule.object_type) res.mcasttype = ret_type.as(not null) self.ret(res) - return + return true else if pname == "[]=" then self.add("{recv}[{arguments[1]}]={arguments[2]};") - return + return true else if pname == "length" then self.ret(self.new_expr("((struct instance_{nclass.c_name}*){arguments[0]})->length", ret_type.as(not null))) - return + return true else if pname == "copy_to" then var recv1 = "((struct instance_{nclass.c_name}*){arguments[1]})->values" self.add("memmove({recv1}, {recv}, {arguments[2]}*sizeof({elttype.ctype}));") - return + return true end + return false end redef fun native_array_get(nat, i) -- 1.7.9.5