Closure templates and the new_closure instruction are implemented. But ast_cfg currently never generates either of them.
Therefore, the remaining work is to have ast_cfg generate a closure template for each partial application, and a corresponding new_closure instruction. Then we can remove parcall, parcall_ctor and parcall_global.
Also needs a review of the typedict code. (Both the whole notion of prepending typedict arguments to closure templates, and also the type dict augmentation of the new_closure instruction.) In particular, in typedict.augment_instr_globalrefs, I am not sure what to do about ArgTypes, which should correspond to the types of the cvars. Do these need to be unified and have type dicts augmented? I wrote some unification code, but didn't commit it, since it currently only does a typecheck (and that isn't the role of typedict):
% Unify the cvar types with ArgTypes
( tables.lookup_function(PT, Name, Func) ->
( Func ^ func_cvars = yes(CVars) -> CVarTypes = map(func({_,T}) = T, CVars), list.foldl_corresponding(...?, CVarTypes, ArgTypes, Varset, _),
; error("augment_instr_globalrefs: new_closure on non_CT: " ++ Name)
)
; error("augment_instr_globalrefs: not a global: " ++ Name)
),
Closure templates and the new_closure instruction are implemented. But ast_cfg currently never generates either of them.
Therefore, the remaining work is to have ast_cfg generate a closure template for each partial application, and a corresponding new_closure instruction. Then we can remove parcall, parcall_ctor and parcall_global.
Also needs a review of the typedict code. (Both the whole notion of prepending typedict arguments to closure templates, and also the type dict augmentation of the new_closure instruction.) In particular, in typedict. augment_ instr_globalref s, I am not sure what to do about ArgTypes, which should correspond to the types of the cvars. Do these need to be unified and have type dicts augmented? I wrote some unification code, but didn't commit it, since it currently only does a typecheck (and that isn't the role of typedict):
% Unify the cvar types with ArgTypes lookup_ function( PT, Name, Func) ->
CVarTypes = map(func({_,T}) = T, CVars),
list. foldl_correspon ding(.. .?, CVarTypes, ArgTypes, Varset, _),
error( "augment_ instr_globalref s: new_closure on non_CT: "
++ Name)
error( "augment_ instr_globalref s: not a global: " ++ Name)
( tables.
( Func ^ func_cvars = yes(CVars) ->
;
)
;
),