module abstract_compiler
import literal
-import typing
-import auto_super_init
+import semantize
import platform
import c_tools
return self.compiler.modelbuilder.force_get_primitive_method(self.current_node.as(not null), name, recv.mclass, self.compiler.mainmodule)
end
- fun compile_callsite(callsite: CallSite, args: Array[RuntimeVariable]): nullable RuntimeVariable
+ fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
do
- return self.send(callsite.mproperty, args)
+ var initializers = callsite.mpropdef.initializers
+ if not initializers.is_empty then
+ var recv = arguments.first
+
+ assert initializers.length == arguments.length - 1 else debug("expected {initializers.length}, got {arguments.length - 1}")
+ var i = 1
+ for p in initializers do
+ if p isa MMethod then
+ self.send(p, [recv, arguments[i]])
+ else if p isa MAttribute then
+ self.write_attribute(p, recv, arguments[i])
+ else abort
+ i += 1
+ end
+
+ return self.send(callsite.mproperty, [recv])
+ end
+
+ return self.send(callsite.mproperty, arguments)
end
fun native_array_instance(elttype: MType, length: RuntimeVariable): RuntimeVariable is abstract
for i in [0..auto_super_init.msignature.arity+1[ do
args.add(arguments[i])
end
+ assert auto_super_init.mproperty != mpropdef.mproperty
v.compile_callsite(auto_super_init, args)
end
end
+ if auto_super_call then
+ v.supercall(mpropdef, arguments.first.mtype.as(MClassType), arguments)
+ end
var n_block = n_block
if n_block != null then
private fun compile_to_c(v: AbstractCompilerVisitor, mpropdef: MMethodDef, arguments: Array[RuntimeVariable])
do
if mpropdef == self.mfree_init then
+ if mpropdef.mproperty.is_root_init then
+ assert self.super_inits == null
+ assert arguments.length == 1
+ if not mpropdef.is_intro then
+ v.supercall(mpropdef, arguments.first.mtype.as(MClassType), arguments)
+ end
+ return
+ end
+
var super_inits = self.super_inits
if super_inits != null then
var args_of_super = arguments
v.send(su, args_of_super)
end
end
+
var recv = arguments.first
var i = 1
# Collect undefined attributes