Closure in signature are not only signature.
This commit prepare to add more metainfo like 'break' closure or optionality.
var first_closure_index = signature.arity + 1 # Wich parameter is the first closure
for i in [0..signature.closures.length[ do
var closcn = closure_cname(i)
- var cs = signature.closures[i] # Closure signature
+ var cs = signature.closures[i].signature # Closure signature
var subparams = new Array[String] # Parameters of the closure
subparams.add("struct {closcn}*")
for j in [0..cs.arity[ do
var cname = "OC_{v.nmc.method.cname}_{v.out_contexts.length}"
_cname = cname
var args = new Array[String]
- for i in [0..signature.arity[ do
+ for i in [0..closure.signature.arity[ do
args.add(" param{i}")
end
do
var params = new Array[String]
params.add("struct {closcn}* closctx")
- for i in [0..signature.arity[ do
+ for i in [0..closure.signature.arity[ do
var p = "val_t {args[i]}"
params.add(p)
end
var ret: String
- if signature.return_type != null then
+ if closure.signature.return_type != null then
ret = "val_t"
else
ret = "void"
v.add_instr("{v.nmc.continue_label}: while(false);")
var ret: String = null
- if signature.return_type != null then ret = v.nmc.continue_value
+ if closure.signature.return_type != null then ret = v.nmc.continue_value
v.nmc.continue_value = old_cv
v.nmc.continue_label = old_cl
end
var s = "({ivar}->fun({cargs.join(", ")})) /* Invoke closure {variable} */"
var va: String = null
- if variable.signature.return_type != null then
+ if variable.closure.signature.return_type != null then
va = v.cfc.get_var
v.add_assignment(va, s)
else
readable attr _return_type: MMType
# The closure parameters
- readable attr _closures: Array[MMSignature] = new Array[MMSignature]
+ readable attr _closures: Array[MMClosure] = new Array[MMClosure]
# Number of parameters
meth arity: Int
end
end
+# A closure in a signature
+class MMClosure
+ # The signature of the closure
+ readable attr _signature: MMSignature
+
+ # Adapt the signature to a different receiver
+ meth adaptation_to(r: MMType): MMClosure
+ do
+ return new MMClosure(_signature.adaptation_to(r))
+ end
+
+ init(s: MMSignature)
+ do
+ _signature = s
+ end
+
+ meth not_for_self: MMClosure
+ do
+ return new MMClosure(_signature.not_for_self)
+ end
+end
+
# Inheritance relation between two types
abstract class MMAncestor
# The inherited type
redef meth check_control_flow(v)
do
- if v.control_flow_ctx.unreash == false and signature.return_type != null then
+ if v.control_flow_ctx.unreash == false and closure.signature.return_type != null then
v.error(self, "Control error: Reached end of bloc (a 'continue' with a value was expected).")
end
end
prop.signature = new MMSignature(new Array[MMType], null, v.local_class.get_type)
if v.signature_builder.closure_decls != null then
for clos in v.signature_builder.closure_decls do
- prop.signature.closures.add(clos.signature)
+ prop.signature.closures.add(clos.variable.closure)
end
end
end
v.signature_builder.signature.vararg_rank = v.signature_builder.vararg_rank
end
for clos in v.signature_builder.closure_decls do
- v.signature_builder.signature.closures.add(clos.signature)
+ v.signature_builder.signature.closures.add(clos.variable.closure)
end
end
end
end
redef class AClosureDecl
-
- redef readable attr _signature: MMSignature
-
redef readable attr _variable: ClosureVariable
redef meth accept_property_verifier(v)
if sig == null then
sig = new MMSignature(new Array[MMType], null, v.local_class.get_type)
end
- _signature = sig
+ var clos = new MMClosure(sig)
v.signature_builder = old_signature_builder
old_signature_builder.closure_decls.add(self)
- _variable = new ClosureVariable(n_id.to_symbol, self, sig)
+ _variable = new ClosureVariable(n_id.to_symbol, self, clos)
end
end
redef meth kind do return once "closure"
# The signature of the closure
- readable attr _signature: MMSignature
+ readable attr _closure: MMClosure
- init(n: Symbol, d: PNode, s: MMSignature)
+ init(n: Symbol, d: PNode, c: MMClosure)
do
super(n, d)
- _signature = s
+ _closure = c
end
end
end
redef class PClosureDecl
- # The signature of the declared closure
- meth signature: MMSignature is abstract
-
- # Associated bloc variable
+ # Associated closure variable
meth variable: ClosureVariable is abstract
end
end
redef class PClosureDef
- # Associated signature
- readable writable attr _signature: MMSignature
+ # Associated closure
+ readable writable attr _closure: MMClosure
# Automatic variables
readable writable attr _variables: Array[AutoVariable]
redef meth after_typing(v)
do
var va = variable
- var sig = va.signature
+ var sig = va.closure.signature
var args = process_signature(v, sig, n_id.to_symbol, n_args.to_a)
if args == null then return
_prop = null
if _accept_typing2 then super
end
- private meth accept_typing2(v: TypingVisitor, sig: MMSignature) is abstract
+ private meth accept_typing2(v: TypingVisitor, clos: MMClosure) is abstract
end
redef class AClosureDef
- redef meth accept_typing2(v, sig)
+ redef meth accept_typing2(v, clos)
do
+ var sig = clos.signature
if sig.arity != n_id.length then
v.error(self, "Error: {sig.arity} automatic variable names expected, {n_id.length} found.")
return
end
- signature = sig
+ closure = clos
var old_stype = v.closure_stype
v.closure_stype = sig.return_type