fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
do
if callsite.is_broken then return null
- var initializers = callsite.mpropdef.initializers
- if not initializers.is_empty then
- var recv = arguments.first
-
- var i = 1
- for p in initializers do
- if p isa MMethod then
- var args = [recv]
- for x in p.intro.msignature.mparameters do
- args.add arguments[i]
- i += 1
- end
- self.send(p, args)
- else if p isa MAttribute then
- self.write_attribute(p, recv, arguments[i])
- i += 1
- else abort
- end
- assert i == arguments.length
-
- return self.send(callsite.mproperty, [recv])
- end
-
return self.send(callsite.mproperty, arguments)
end
# of runtime variables to use in the call.
fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable]
do
- var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+ var msignature = mpropdef.msignature.as(not null)
var res = new Array[RuntimeVariable]
res.add(recv)
# This method is used to manage varargs in signatures and returns the real array
# of runtime variables to use in the call.
fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable] do
- var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+ var msignature = mpropdef.msignature.as(not null)
var res = new Array[RuntimeVariable]
res.add(recv)
end
redef fun cs_short_signature do
- if mproperty.is_root_init then
- return new_msignature.cs_short_signature
- end
return msignature.cs_short_signature
end
redef fun cs_signature do
- if mproperty.is_root_init then
- return new_msignature.cs_signature
- end
return msignature.cs_signature
end
# Return `null` if one of the evaluation of the arguments return null.
fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: Instance, args: SequenceRead[AExpr]): nullable Array[Instance]
do
- var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null)
+ var msignature = mpropdef.msignature.as(not null)
var res = new Array[Instance]
res.add(recv)
fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance
do
if callsite == null then return null
- var initializers = callsite.mpropdef.initializers
- if not initializers.is_empty then
- var recv = arguments.first
- var i = 1
- for p in initializers do
- if p isa MMethod then
- var args = [recv]
- for x in p.intro.msignature.mparameters do
- args.add arguments[i]
- i += 1
- end
- self.send(p, args)
- else if p isa MAttribute then
- assert recv isa MutableInstance
- write_attribute(p, recv, arguments[i])
- i += 1
- else abort
- end
- assert i == arguments.length
-
- return send(callsite.mproperty, [recv])
- end
return send(callsite.mproperty, arguments)
end
# The signature attached to the property definition
var msignature: nullable MSignature = null is writable
- # The signature attached to the `new` call on a root-init
- # This is a concatenation of the signatures of the initializers
- #
- # REQUIRE `mproperty.is_root_init == (new_msignature != null)`
- var new_msignature: nullable MSignature = null is writable
-
# List of initialisers to call in root-inits
#
# They could be setters or attributes
- #
- # REQUIRE `mproperty.is_root_init == (new_msignature != null)`
var initializers = new Array[MProperty]
+ # Does the method take the responsibility to call `init`?
+ #
+ # If the method is used as an initializer, then
+ # using this information prevents to call `init` twice.
+ var is_calling_init = false is writable
+
# Is the method definition abstract?
var is_abstract: Bool = false is writable
var mparameters = new Array[MParameter]
var msignature = new MSignature(mparameters, null)
mpropdef.msignature = msignature
- mpropdef.new_msignature = msignature
mprop.is_init = true
self.toolcontext.info("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3)
the_root_init_mmethod = mprop
# Combine the inherited list to what is collected
if longest.initializers.length > 0 then
- mparameters.prepend longest.new_msignature.mparameters
+ mparameters.prepend longest.msignature.mparameters
initializers.prepend longest.initializers
end
end
var root_init = mclassdef.mclass.root_init
if root_init != null then
# Inherit the initializers by refinement
- mpropdef.new_msignature = root_init.new_msignature
assert mpropdef.initializers.is_empty
mpropdef.initializers.add_all root_init.initializers
end
v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule))
end
- # TODO? new_msignature
var sig = msignature
var osig = mmeth.intro.msignature.as(not null)
for i in [0..sig.arity[ do
return
end
- var msignature = candidatedef.new_msignature or else candidatedef.msignature
+ var msignature = candidatedef.msignature
msignature = msignature.resolve_for(recvtype, anchor, mmodule, true)
if msignature.arity > 0 then
end
- var msignature = mpropdef.new_msignature or else mpropdef.msignature
+ var msignature = mpropdef.msignature
if msignature == null then return null # skip error
msignature = resolve_for(msignature, recvtype, recv_is_self).as(MSignature)
return
end
- var msignature = superprop.new_msignature or else superprop.msignature.as(not null)
+ var msignature = superprop.msignature.as(not null)
msignature = v.resolve_for(msignature, recvtype, true).as(MSignature)
var callsite = new CallSite(hot_location, recvtype, v.mmodule, v.anchor, true, superprop.mproperty, superprop, msignature, false)
end
redef fun html_short_signature do
- var new_msignature = self.new_msignature
- if mproperty.is_root_init and new_msignature != null then
- return new_msignature.html_short_signature
- end
return msignature.as(not null).html_short_signature
end
redef fun html_signature do
- var new_msignature = self.new_msignature
- if mproperty.is_root_init and new_msignature != null then
- return new_msignature.html_signature
- end
return msignature.as(not null).html_signature
end
end