@@ -107,12 +107,38 @@ def $refresh_exppulls(ep*) = (ep', $composesubsts(s*))
107107 -- (if (ep', s) = $refresh_exppull(ep))*
108108
109109
110+ def $refresh_exppush(exppush) : (exppush, subst)
111+ def $refresh_exppushs(exppush*) : (exppush*, subst)
112+
113+ def $refresh_exppush(e `-> x `: t) = (e `-> x' `: t, s)
114+ -- if (x', s) = $refresh_expid(x)
115+
116+ def $refresh_exppushs(eq*) = (eq', $composesubsts(s*))
117+ -- (if (eq', s) = $refresh_exppush(eq))*
118+
119+
110120def $refresh_iter(iter) : (iter, subst)
111121
112122def $refresh_iter(QUEST) = (QUEST, {})
113123def $refresh_iter(STAR) = (STAR, {})
114124def $refresh_iter(PLUS) = (PLUS, {})
115- def $refresh_iter(SUP x e) = (SUP x' e, s) -- if (x', s) = $refresh_expid(x)
125+ def $refresh_iter(SUP x e) = (SUP x' e, s)
126+ -- if (x', s) = $refresh_expid(x)
127+
128+
129+ def $refresh_prem(prem) : (prem, subst)
130+ def $refresh_prems(prem*) : (prem*, subst)
131+
132+ def $refresh_prem(REL x a* `: e) = (REL x a* `: e, {})
133+ def $refresh_prem(IF e) = (IF e, {})
134+ def $refresh_prem(ELSE) = (ELSE, {})
135+ def $refresh_prem(LET `{q*} e_1 `= e_2) = (LET `{q'*} $subst_exp(s, e_1) `= e_2, s)
136+ -- if (q'*, s) = $refresh_params(q*)
137+ def $refresh_prem(ITER pr it ep* eq*) = (ITER pr it ep* eq'*, s)
138+ -- if (eq'*, s) = $refresh_exppushs(eq*)
139+
140+ def $refresh_prems(pr*) =
141+ $refresh_list(prem, $refresh_prem, $subst_prem, pr*)
116142
117143
118144;; Lists
@@ -142,12 +168,8 @@ def $subst_typ(s, MATCH x a* WITH inst*) = MATCH x $subst_arg(s, a)* WITH $subs
142168
143169def $subst_deftyp(subst, deftyp) : deftyp
144170def $subst_deftyp(s, ALIAS t) = ALIAS $subst_typ(s, t)
145- def $subst_deftyp(s, STRUCT (a `: t `- `{q*} pr*)*) = STRUCT (a `: $subst_typ(s, t') `- `{$subst_param(s ++ s', q')*} $subst_prem(s ++ s' ++ s'', pr)*)*
146- -- if (t', s') = $refresh_typ(t)
147- -- if (q'*, s'') = $refresh_params(q*)
148- def $subst_deftyp(s, VARIANT (m `: t `- `{q*} pr*)*) = VARIANT (m `: $subst_typ(s, t') `- `{$subst_param(s ++ s', q')*} $subst_prem(s ++ s' ++ s'', pr)*)*
149- -- if (t', s') = $refresh_typ(t)
150- -- if (q'*, s'') = $refresh_params(q*)
171+ def $subst_deftyp(s, STRUCT (a `: tpr)*) = STRUCT (a `: $subst_typprems(s, tpr))*
172+ def $subst_deftyp(s, VARIANT (m `: tpr)*) = VARIANT (m `: $subst_typprems(s, tpr))*
151173
152174def $subst_typbind(subst, typbind) : typbind
153175def $subst_typbind(s, x `: t) = x' `: $subst_typ(s, t)
@@ -164,6 +186,9 @@ def $subst_iter(s, SUP x e) = SUP x $subst_exp(s, e)
164186def $subst_exppull(subst, exppull) : exppull
165187def $subst_exppull(s, x `: t `<- e') = x `: $subst_typ(s, t) `<- $subst_exp(s, e')
166188
189+ def $subst_exppush(subst, exppush) : exppush
190+ def $subst_exppush(s, e' `-> x `: t) = $subst_exp(s, e') `-> x `: $subst_typ(s, t)
191+
167192
168193;; Expressions
169194
@@ -223,7 +248,7 @@ def $subst_sym(s, ITER g it ep*) = ITER $subst_sym(s ++ s' ++ s'', g) $subst_ite
223248 -- if (ep'*, s'') = $refresh_exppulls(ep*)
224249
225250
226- ;; Definitions
251+ ;; Arguments and Parameters
227252
228253def $subst_arg(subst, arg) : arg
229254def $subst_arg(s, TYP t) = TYP $subst_typ(s, t)
@@ -239,30 +264,49 @@ def $subst_param(s, FUN x `: p* `-> t) = FUN x `: $subst_param(s, p')* `-> $subs
239264def $subst_param(s, GRAM x `: p* `-> t) = GRAM x `: $subst_param(s, p')* `-> $subst_typ(s ++ s', t)
240265 -- if (p'*, s') = $refresh_params(p*)
241266
267+
268+ ;; Premises
269+
242270def $subst_prem(subst, prem) : prem
243271def $subst_prem(s, REL x a* `: e) = REL x $subst_arg(s, a)* `: $subst_exp(s, e)
244272def $subst_prem(s, IF e) = IF $subst_exp(s, e)
245273def $subst_prem(s, ELSE) = ELSE
246- def $subst_prem(s, LET e_1 `= e_2) = LET $subst_exp(s, e_1) `= $subst_exp(s, e_2)
247- def $subst_prem(s, ITER pr it ep*) = ITER $subst_prem(s ++ s' ++ s'', pr) $subst_iter(s, it') $subst_exppull(s, ep')*
274+ def $subst_prem(s, LET `{q*} e_1 `= e_2) = LET `{$subst_param(s, q)*} $subst_exp(s, e_1) `= $subst_exp(s, e_2)
275+ ;; Assume: q* fresh (from caller $subst_typprems, $subst_expprems)
276+ def $subst_prem(s, ITER pr it ep* eq*) = ITER $subst_prem(s ++ s' ++ s'', pr') $subst_iter(s, it') $subst_exppull(s, ep')* $subst_exppush(s ++ s''', eq')*
277+ ;; Assume: eq* fresh (from caller $subst_typprems, $subst_expprems)
248278 -- if (it', s') = $refresh_iter(it)
249279 -- if (ep'*, s'') = $refresh_exppulls(ep*)
280+ -- if (pr', s''') = $refresh_prem(pr)
281+
250282
283+ def $subst_typprems(subst, typprems) : typprems
284+ def $subst_typprems(s, t `- `{q*} pr*) = $subst_typ(s, t') `- `{$subst_param(s ++ s', q')*} $subst_prem(s ++ s' ++ s'', pr')*
285+ -- if (t', s') = $refresh_typ(t)
286+ -- if (q'*, s'') = $refresh_params(q*)
287+ -- if (pr'*, s''') = $refresh_prems(pr*)
288+
289+ def $subst_expprems(subst, expprems) : expprems
290+ def $subst_expprems(s, e `- pr*) = $subst_exp(s ++ s', e) `- $subst_prem(s, pr)*
291+ -- if (pr'*, s') = $refresh_prems(pr*)
292+
293+
294+ ;; Definitions
251295
252296def $subst_inst(subst, inst) : inst
253297def $subst_inst(s, INST `{q*} a* `=> dt) = INST `{$subst_param(s, q')*} $subst_arg(s ++ s', a)* `=> $subst_deftyp(s ++ s', dt)
254298 -- if (q'*, s') = $refresh_params(q*)
255299
256300def $subst_rule(subst, rul) : rul
257- def $subst_rule(s, RULE `{q*} e `- pr* ) = RULE `{$subst_param(s, q')*} $subst_exp (s ++ s', e) `- $subst_prem(s ++ s', pr)*
301+ def $subst_rule(s, RULE `{q*} epr ) = RULE `{$subst_param(s, q')*} $subst_expprems (s ++ s', epr)
258302 -- if (q'*, s') = $refresh_params(q*)
259303
260304def $subst_clause(subst, clause) : clause
261- def $subst_clause(s, CLAUSE `{q*} a* `=> e `- pr* ) = CLAUSE `{$subst_param(s, q')*} $subst_arg(s ++ s', a)* `=> $subst_exp (s ++ s', e) `- $subst_prem(s ++ s', pr)*
305+ def $subst_clause(s, CLAUSE `{q*} a* `=> epr ) = CLAUSE `{$subst_param(s, q')*} $subst_arg(s ++ s', a)* `=> $subst_expprems (s ++ s', epr)
262306 -- if (q'*, s') = $refresh_params(q*)
263307
264308def $subst_prod(subst, prod) : prod
265- def $subst_prod(s, PROD `{q*} g `=> e `- pr* ) = PROD `{$subst_param(s, q')*} $subst_sym(s ++ s', g) `=> $subst_exp (s ++ s', e) `- $subst_prem(s ++ s', pr)*
309+ def $subst_prod(s, PROD `{q*} g `=> epr ) = PROD `{$subst_param(s, q')*} $subst_sym(s ++ s', g) `=> $subst_expprems (s ++ s', epr)
266310 -- if (q'*, s') = $refresh_params(q*)
267311
268312
0 commit comments