niti: implements intern `init` for NativeString and NativeArray
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 14:18:41 +0000 (10:18 -0400)
committerJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 14:18:41 +0000 (10:18 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/naive_interpreter.nit

index e9d0a97..7f8d5ee 100644 (file)
@@ -794,6 +794,9 @@ redef class AMethPropdef
                                return v.bool_instance(args[0].to_f.is_inf != 0)
                        end
                else if cname == "NativeString" then
+                       if pname == "init" then
+                               return v.native_string_instance("!" * args[1].to_i)
+                       end
                        var recvval = args.first.val.as(Buffer)
                        if pname == "[]" then
                                var arg1 = args[1].to_i
@@ -852,6 +855,10 @@ redef class AMethPropdef
                else if pname == "calloc_string" then
                        return v.native_string_instance("!" * args[1].to_i)
                else if cname == "NativeArray" then
+                       if pname == "init" then
+                               var val = new Array[Instance].filled_with(v.null_instance, args[1].to_i)
+                               return new PrimitiveInstance[Array[Instance]](args[0].mtype, val)
+                       end
                        var recvval = args.first.val.as(Array[Instance])
                        if pname == "[]" then
                                if args[1].to_i >= recvval.length or args[1].to_i < 0 then