(* Oukseh Lee Copyright(c) 2000-2004 KAIST/SNU Research On Program Analysis System (National Creative Research Initiative Center 1998-2003) http://ropas.snu.ac.kr/n All rights reserved. This file is distributed under the terms of an Open Source License. *) structure Lamenv = struct structure L = Lambda structure E = MakeMap(struct type t = L.var val compare = compare end) structure S = MakeMap(struct type t = int val compare = compare end) type value = Const of L.const | Data of data | Tuple of value array | Addr of addr | Closure of closure | Op of L.op and data = L.kappa * value option and addr = int and closure = L.var * L.expr * env * L.var list and env = value E.t and store = value S.t val address_counter = ref 0 fun new_address() = let val i = !address_counter in address_counter++; i end open Format fun print_array f g a = let val g' = ref (fn _ => ()) in Array.iter (fn v => (!g') v; f v; g' := g) a end fun print_kappa k = case k of L.Normal i => printf "#%d" i | L.Except s => printf "%s" s fun print_value v = case v of Const(L.Int i) => printf "%d" i | Const(L.Real r) => printf "%f" r | Const(L.String s) => printf "%s" s | Const(L.Char c) => printf "%c" c | Const(L.Bool true) => printf "true" | Const(L.Bool false) => printf "false" | Const(L.Unit) => printf "unit" | Op(_,s) => printf "(%s)" s | Addr i => printf "&%d" i | Data(k,None) => print_kappa k | Data(k,Some v) => print_kappa k; printf "("; print_value v; printf ")" | Closure(x,e,env,l) => printf "" (* printf "fn %d => , " x; print_env env *) | Tuple l => printf "{ "; print_array print_value (fn _ => printf ", ") l; printf " }" and print_map iter f g m = let val g' = ref (fn _ _ => ()) in iter (fn k v => (!g') k v; f k v; g' := g) m end and print_env m = printf "@["; print_map E.iter (fn k v => printf "%d = @[" k; print_value v) (fn _ _ => printf "@];@\n") m; printf "@];@\n@]" end