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

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS<br />

ValueExpr: the imperative version <strong>of</strong> the if expression<br />

∗/<br />

TRIfExpr :<br />

IfExpr × ExpType × FUNC × TRANS × TYPES →<br />

ValueExpr × TYPES<br />

TRIfExpr(ie, et, func, trans, types) ≡<br />

let<br />

(ifcond, types1) =<br />

TRValueExpr(<br />

condition(ie), Known(TypeLiteral(BOOL)),<br />

func, trans, types),<br />

(ifcase, types2) =<br />

TRValueExpr(if_case(ie), et, func, trans, types1),<br />

(elsiflist, types3) =<br />

TRElsif(elsif_list(ie), et, func, trans, types2),<br />

(elsecase, types4) =<br />

TRValueExpr(<br />

else_case(ie), et, func, trans, types3)<br />

in<br />

(Make_IfExpr(<br />

mk_IfExpr(ifcond, ifcase, elsiflist, elsecase)),<br />

types4)<br />

end,<br />

/∗Transforms an elsif list.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

eil: the elsif list<br />

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

Result:<br />

=======<br />

Elsif_list: the imperative version <strong>of</strong> the elsif<br />

list<br />

∗/<br />

TRElsif :<br />

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

Elsif ∗ × TYPES<br />

TRElsif(eil, et, func, trans, types) ≡<br />

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

else<br />

let<br />

(ve1, types1) =<br />

TRValueExpr(<br />

216

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

Saved successfully!

Ooh no, something went wrong!