% $Id: MV.oz,v 1.5 2012/01/03 15:20:19 leavens Exp $ % Values and the meaning function for Value Expressions % AUTHOR: Gary T. Leavens % Representation of Values: % ::= record(>) % | closure(> ) % | num() % | bool() % | loc() % ::= % > ::= an Oz record containing locations for all fields. \insert 'Environment.oz' declare fun {MV Exp Env} %% ENSURES: Result is the meaning of Exp in Env case Exp of varId(V ...) then loc({ApplyEnv Env V}) [] atomExp(A ...) then record(A) [] boolExp(B ...) then bool(B) [] intLit(N ...) then num(N) [] floatLit(N ...) then num(N) [] recordExp(atomExp(L) FieldList ...) andthen {All FieldList NamedColonField} then record({List.toRecord L {Map FieldList fun {$ colonFld(Feat varId(V))} {GetFeature Feat}#{ApplyEnv Env V} end}}) [] procExp(Formals Body ...) then closure({Map Formals fun {$ varIdPat(V)} V end} Body Env) else raise unknownValueExp(Exp) end end end fun {GetFeature F} % Returns an Oz Literal for the given feature AST case F of atomExp(A ...) then A [] intLit(I ...) then I [] boolExp(B ...) then B end end fun {NamedColonField F} %% ENSURES: Result is true if F is a named field (like x:E) case F of colonFld(_ varId(_)) then true else false end end