Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS /∗Transforms a list of value declarations.∗/ /∗ Arguments: ======= vdl: the list of value declarations Results: ===== DResult: the result ∗/ TRValueDecl : ValueDef ∗ × TYPINGS × FUNC × TRANS → DResult TRValueDecl(vdl, typings, func, trans) ≡ if CheckValueDefList(vdl, typings, func, trans) then /∗The value declaration list is transformable and is transformed.∗/ Transformable( ValueDecl(TRValueDefList(vdl, func, trans))) else /∗The value declaration list is not transformable. ∗/ Not_transformable end, /∗Checks for transformability of a value definfition list.∗/ /∗ Arguments: ======= vdl: the list of value definitions Results: ===== Bool: true if the list is transformable, false otherwise ∗/ CheckValueDefList : ValueDef ∗ × TYPINGS × FUNC × TRANS → Bool CheckValueDefList(vdl, typings, func, trans) ≡ if vdl = 〈〉 then true else CheckValueDef(hd vdl, typings, func, trans) ∧ CheckValueDefList(tl vdl, typings, func, trans) end, 152

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER /∗Checks for transformability of a value definition. ∗/ /∗ Arguments: ======= vd: the value definition Results: ===== Bool: true if the value definition is transformable, false otherwise ∗/ CheckValueDef : ValueDef × TYPINGS × FUNC × TRANS → Bool CheckValueDef(vd, typings, func, trans) ≡ case vd of ExplicitValueDef(st, ve) → if containsTRANSName( Known(type_expr(st)), typings, dom trans) then case binding(st) of IdBinding(id) → let (b, env, types) = CheckValueExpr( ve, Known(type_expr(st)), typings, func, trans, [ ], [ ]) in b end, Make_ProductBinding(pb) → false end else true end, ExplicitFunctionDef(st, ffa, ve, precond) → case type_expr(st) of FunctionTypeExpr(arg, fa, res) → let /∗Establishes ENV and TYPES.∗/ (b1, ffap, env, types, prlet) = TRFormalFuncAppl(ffa, func, trans), (b2, env ′ , types ′ ) = CheckOptPreCondition( precond, Known(TypeLiteral(BOOL)), 153

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER<br />

/∗Checks for transformability <strong>of</strong> a value definition.<br />

∗/<br />

/∗<br />

Arguments:<br />

=======<br />

vd: the value definition<br />

Results:<br />

=====<br />

Bool: true if the value definition is transformable,<br />

false otherwise<br />

∗/<br />

CheckValueDef :<br />

ValueDef × TYPINGS × FUNC × TRANS → Bool<br />

CheckValueDef(vd, typings, func, trans) ≡<br />

case vd <strong>of</strong><br />

ExplicitValueDef(st, ve) →<br />

if<br />

containsTRANSName(<br />

Known(type_expr(st)), typings, dom trans)<br />

then<br />

case binding(st) <strong>of</strong><br />

IdBinding(id) →<br />

let<br />

(b, env, types) =<br />

CheckValueExpr(<br />

ve, Known(type_expr(st)), typings,<br />

func, trans, [ ], [ ])<br />

in<br />

b<br />

end,<br />

Make_ProductBinding(pb) → false<br />

end<br />

else true<br />

end,<br />

ExplicitFunctionDef(st, ffa, ve, precond) →<br />

case type_expr(st) <strong>of</strong><br />

FunctionTypeExpr(arg, fa, res) →<br />

let<br />

/∗Establishes ENV and TYPES.∗/<br />

(b1, ffap, env, types, prlet) =<br />

TRFormalFuncAppl(ffa, func, trans),<br />

(b2, env ′ , types ′ ) =<br />

CheckOptPreCondition(<br />

precond, Known(TypeLiteral(BOOL)),<br />

153

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!