else if pname == "atoi" then
v.ret(v.new_expr("atoi({arguments[0]});", ret.as(not null)))
return true
- else if pname == "init" then
+ else if pname == "new" then
v.ret(v.new_expr("(char*)nit_alloc({arguments[1]})", ret.as(not null)))
return true
end
return v.bool_instance(args[0].to_f.is_inf != 0)
end
else if cname == "NativeString" then
- if pname == "init" then
+ if pname == "new" then
return v.native_string_instance("!" * args[1].to_i)
end
var recvval = args.first.val.as(Buffer)
else if pname == "calloc_string" then
return v.native_string_instance("!" * args[1].to_i)
else if cname == "NativeArray" then
- if pname == "init" then
+ if pname == "new" 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
for mprop in props do
if not mtype.has_mproperty(mmodule, mprop) then continue
if not mmodule.is_visible(mprop.intro_mclassdef.mmodule, mprop.visibility) then continue
+
+ # new-factories are invisible outside of the class
+ if mprop isa MMethod and mprop.is_new and (not mtype isa MClassType or mprop.intro_mclassdef.mclass != mtype.mclass) then
+ continue
+ end
+
if res == null then
res = mprop
continue
name = "init"
name_node = n_kwinit
else if n_kwnew != null then
- name = "init"
+ name = "new"
name_node = n_kwnew
else
abort
return
end
- var meth_name = "init"
+ var meth_name = "new"
var meth = toolcontext.modelbuilder.try_get_mproperty_by_name2( self,
mmodule, mtype, meth_name )
if meth == null then
+ meth_name = "init"
+ meth = toolcontext.modelbuilder.try_get_mproperty_by_name2( self,
+ mmodule, mtype, meth_name )
+ end
+
+ if meth == null then
toolcontext.error(location, "Method {meth_name} not found in {n_type.collect_text}." )
return
end
end
var mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name)
+ if name == "new" and mproperty == null then
+ name = "init"
+ mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name)
+ end
+
if mproperty == null then
#self.modelbuilder.error(node, "Type error: property {name} not found in {unsafe_type} (ie {recvtype})")
if recv_is_self then
if nid != null then
name = nid.text
else
- name = "init"
+ name = "new"
end
var callsite = v.get_method(self, recvtype, name, false)
if callsite == null then return