structure Syntax = struct (* SML syntax *) datatype etype = Tyvar of string | Tycon of etype list * string | TyTuple of etype list | Tyfun of etype * etype datatype pat = PWild | PVar of string | PInt of int | PTuple of pat list | PCon of string list * pat datatype expr = EIdent of string | EDot of structExpr * string | EBuiltin of string | EInt of int | EStr of string | ETuple of expr list | EList of expr list | EApp of expr * expr | ETyped of expr * etype | EAndAlso of expr * expr | EOrElse of expr * expr | ELet of dec list * expr | ELambda of pat * expr | ECase of expr * (pat * expr) list and dec = DVal of pat * expr | DValRec of pat * expr | DFun of string * (pat list * expr) list | DDatatype of string list * string * (string * etype option) list | DType of string * etype | DStruct of string * string option * structExpr | DSig of string * (string * etype) list and structExpr = SIdent of string | SDot of structExpr * string | SStruct of dec list datatype ty = TInt | TBool | TString | TVar of int | TTuple of ty list | TFun of ty * ty | TList of ty | TDatatype of string list datatype structType = TStruct of (string * structType) list * (string * ty) list (*| TFunctor of structType * structType *) datatype typedPat = TPWild | TPVar of string | TPInt of int | TPTuple of (typedPat * ty) list | TPCon of string list * (typedPat * ty) datatype typedExpr = TEIdent of string | TEDot of (typedStructExpr * structType) * string | TEBuiltin of string | TEInt of int | TEStr of string | TETuple of (typedExpr * ty) list | TEList of (typedExpr * ty) list | TEApp of (typedExpr * ty) * (typedExpr * ty) | TEAndAlso of (typedExpr * ty) * (typedExpr * ty) | TEOrElse of (typedExpr * ty) * (typedExpr * ty) | TELet of typedDec list * (typedExpr * ty) | TELambda of (typedPat * ty) * (typedExpr * ty) | TECase of (typedExpr * ty) * ((typedPat * ty) * (typedExpr * ty)) list and typedDec = TDVal of (typedPat * ty) * (typedExpr * ty) | TDValRec of (typedPat * ty) * (typedExpr * ty) | TDFun of string * ((typedPat * ty) list * (typedExpr * ty)) list | TDDatatype of string * (string * ty option) list | TDStruct of string * (typedStructExpr * structType) and typedStructExpr = TSIdent of string | TSDot of (typedStructExpr * structType) * string | TSStruct of typedDec list (* Lambda language *) type var = int datatype primop = PExit | PAdd | PSub | PMul | PDiv | PLess | PEq | PIf | PRead | PWrite | PWriteErr datatype lexp = LVar of var | LFn of var * lexp | LFix of (var * var * lexp) list * lexp | LApp of lexp * lexp | LInt of int | LString of string | LRecord of lexp list | LSelect of int * lexp | LPrim of primop | LSwitch of lexp * (int * lexp) list * lexp option (* CPS *) datatype value = VVar of var | VLabel of var | VInt of int datatype cexp = CRecord of ((value * int list) list * var) list * cexp | CSelect of int * value * var * cexp | CApp of value * value list | CFix of (var * var list * cexp) list * cexp | CPrimop of primop * value list * var list * cexp list datatype opcode = OAlloc of var * value | OCall | OPoke of int * var * value | OPeek of var * int * value | OShuf of var * value | OExit of value | OAdd of var * value * value | OSub of var * value * value | OMul of var * value * value | ODiv of var * value * value | OLess of var * value * value | OEq of var * value * value | OIf of value * var | OLabel of var | ORead of var * var * value * value | OWrite of var * value * value | OWriteErr of var * value * value end