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 ValueExpr: the imperative version of the if expression ∗/ TRIfExpr : IfExpr × ExpType × FUNC × TRANS × TYPES → ValueExpr × TYPES TRIfExpr(ie, et, func, trans, types) ≡ let (ifcond, types1) = TRValueExpr( condition(ie), Known(TypeLiteral(BOOL)), func, trans, types), (ifcase, types2) = TRValueExpr(if_case(ie), et, func, trans, types1), (elsiflist, types3) = TRElsif(elsif_list(ie), et, func, trans, types2), (elsecase, types4) = TRValueExpr( else_case(ie), et, func, trans, types3) in (Make_IfExpr( mk_IfExpr(ifcond, ifcase, elsiflist, elsecase)), types4) end, /∗Transforms an elsif list.∗/ /∗ Arguments: ======= eil: the elsif list et: the expected type of the if expression Result: ======= Elsif_list: the imperative version of the elsif list ∗/ TRElsif : Elsif ∗ × ExpType × FUNC × TRANS × TYPES → Elsif ∗ × TYPES TRElsif(eil, et, func, trans, types) ≡ if eil = 〈〉 then (〈〉, types) else let (ve1, types1) = TRValueExpr( 216

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER condition(hd eil), Known(TypeLiteral(BOOL)), func, trans, types ), (ve2, types2) = TRValueExpr( elsif_case(hd eil), et, func, trans, types1), (elsiftl, types3) = TRElsif(tl eil, et, func, trans, types2) in (〈mk_Elsif(ve1, ve2)〉 elsiftl, types3) end end, /∗Transforms a case branch list.∗/ /∗ Arguments: ======= cbl: the case branch list et: the expected type of the case expression Results: ======= CaseBranch_list: the imperative version of the case branch list ∗/ TRCaseBranchList : CaseBranch ∗ × ExpType × FUNC × TRANS × TYPES → CaseBranch ∗ × TYPES TRCaseBranchList(cbl, et, func, trans, types) ≡ if cbl = 〈〉 then (〈〉, types) else let (p, types1) = TRPattern(pattern(hd cbl), func, trans, types), (ve, types2) = TRValueExpr( value_expr(hd cbl), et, func, trans, types1), (cbl ′ , types3) = TRCaseBranchList( tl cbl, et, func, trans, types2) in (〈mk_CaseBranch(p, ve)〉 cbl ′ , types3) end end, 217

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

condition(hd eil),<br />

Known(TypeLiteral(BOOL)), func, trans, types<br />

),<br />

(ve2, types2) =<br />

TRValueExpr(<br />

elsif_case(hd eil), et, func, trans, types1),<br />

(elsiftl, types3) =<br />

TRElsif(tl eil, et, func, trans, types2)<br />

in<br />

(〈mk_Elsif(ve1, ve2)〉 elsiftl, types3)<br />

end<br />

end,<br />

/∗Transforms a case branch list.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

cbl: the case branch list<br />

et: the expected type <strong>of</strong> the case expression<br />

Results:<br />

=======<br />

CaseBranch_list: the imperative version <strong>of</strong> the<br />

case branch list<br />

∗/<br />

TRCaseBranchList :<br />

CaseBranch ∗ × ExpType × FUNC × TRANS × TYPES →<br />

CaseBranch ∗ × TYPES<br />

TRCaseBranchList(cbl, et, func, trans, types) ≡<br />

if cbl = 〈〉 then (〈〉, types)<br />

else<br />

let<br />

(p, types1) =<br />

TRPattern(pattern(hd cbl), func, trans, types),<br />

(ve, types2) =<br />

TRValueExpr(<br />

value_expr(hd cbl), et, func, trans, types1),<br />

(cbl ′ , types3) =<br />

TRCaseBranchList(<br />

tl cbl, et, func, trans, types2)<br />

in<br />

(〈mk_CaseBranch(p, ve)〉 cbl ′ , types3)<br />

end<br />

end,<br />

217

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

Saved successfully!

Ooh no, something went wrong!