@@ -226,6 +226,53 @@ declare-asset Arg AssetKind :- std.do! [
226226 )
227227].
228228
229+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230+ %%% auxiliary code for wrapper-mixin
231+
232+ pred extract_from_record_decl i: (term -> gref -> prop), i:indt-decl, o:gref.
233+ extract_from_record_decl P (parameter ID _ Ty R) Out :-
234+ @pi-parameter ID Ty p\
235+ extract_from_record_decl P (R p) Out.
236+ extract_from_record_decl P (record _ _ _ (field _ _ Ty (x\end-record))) GR0 :-
237+ P Ty GR0.
238+
239+ pred extract_from_rtty i: (term -> gref -> prop), i: term, o:gref.
240+ extract_from_rtty P (prod N Ty TF) Out1 :-
241+ @pi-decl N Ty p\
242+ extract_from_rtty P (TF p) Out1.
243+ extract_from_rtty P Ty Gr :- P Ty Gr.
244+
245+ pred xtr_fst_op i:term, o:gref.
246+ xtr_fst_op Ty Gr1 :-
247+ Ty = (app [global Gr0| _]),
248+ factory-alias->gref Gr0 Gr1 ok.
249+
250+ pred xtr_snd_op i:term, o:gref.
251+ xtr_snd_op Ty Gr :-
252+ % TODO: use factory? from database.elpi
253+ Ty = (app [global Gr0| Args]),
254+ factory-alias->gref Gr0 Gr1 ok,
255+ factory-nparams Gr1 N,
256+ std.nth N Args (app [global Gr| _]).
257+
258+ pred extract_wrapped i:indt-decl, o:gref.
259+ extract_wrapped In Out :-
260+ extract_from_record_decl (extract_from_rtty xtr_fst_op) In Out.
261+
262+ pred extract_subject i:indt-decl, o:gref.
263+ extract_subject In Out :-
264+ extract_from_record_decl (extract_from_rtty xtr_snd_op) In Out.
265+
266+ pred wrapper_mixin_aux i:gref, o:gref, o:gref.
267+ wrapper_mixin_aux XX Gr1 Gr2 :-
268+ XX = (indt I),
269+ coq.env.indt-decl I D,
270+ extract_subject D Gr1,
271+ extract_wrapped D Gr2.
272+
273+ %%% end auxiliary code for wrapper-mixin
274+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275+
229276pred declare-mixin-or-factory i:list prop, i:list constant, i:list term, i:term,
230277 i:term, i:record-decl, i:list-w-params factoryname, i:id, i:asset.
231278declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
@@ -262,6 +309,12 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
262309
263310 % TODO: should this be in the Exports module?
264311
312+ % if the wrapper option is on, build the wrapper clause
313+ if (get-option "wrapper" tt)
314+ ((wrapper_mixin_aux (indt R) NSbj WMxn),
315+ (WrapperClauses = [wrapper-mixin (indt R) NSbj WMxn]))
316+ (WrapperClauses = []),
317+
265318 if-verbose (coq.say {header} "declare notation Build"),
266319
267320 GRDepsClauses => phant.of-gref ff GRK [] PhGRK,
@@ -278,7 +331,7 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
278331 if-verbose (coq.say {header} "start module Exports"),
279332
280333 log.coq.env.begin-module "Exports" none,
281- std.flatten [Clauses, GRDepsClauses, [
334+ std.flatten [Clauses, GRDepsClauses, WrapperClauses, [
282335 factory-constructor (indt R) GRK,
283336 factory-nparams (indt R) NParams,
284337 factory-builder-nparams BuildConst NParams,
0 commit comments