(* Sto: stores implemented as integer maps *) (* The store maps integers to 'data *) exception SegmentationFault datatype 'data sto = Sto of 'data Intmap.intmap fun empty () = Sto (Intmap.empty ()) fun getsto (Sto imap) loc = if loc < 0 then raise SegmentationFault else Intmap.retrieve(imap, loc); fun setsto (Sto imap) loc v = if loc < 0 then raise SegmentationFault else Sto (Intmap.insert(imap, loc, v)); fun printsto (Sto imap) pr = let fun printpair (i, d) = String.concat["(", Int.toString i, ", ", pr d, ")\n"] in List.app (print o printpair) (Intmap.listItems imap) end; fun printstoi sto = printsto sto Int.toString; (* Bind variable in env and store *) fun bindvar x v (env, nextloc) sto = let val env1 = Env.bind1 env (x, nextloc) in ((env1, nextloc + 1), setsto sto nextloc v) end fun bindvars [] [] env sto = (env, sto) | bindvars (x1::xr) (v1::vr) env sto = let val (env1, sto1) = bindvar x1 v1 env sto in bindvars xr vr env1 sto1 end | bindvars _ _ _ _ = raise Fail "parameter/argument mismatch"