SCM Repository
View of /trunk/src/compiler/env/env.sml
Parent Directory
|
Revision Log
Revision 169 -
(download)
(annotate)
Thu Jul 22 20:07:37 2010 UTC (11 years, 11 months ago) by jhr
File size: 1605 byte(s)
Thu Jul 22 20:07:37 2010 UTC (11 years, 11 months ago) by jhr
File size: 1605 byte(s)
Split function and variable namespaces and add notion of restricted operations that cannot appear inside actor or initialization code.
(* env.sml * * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) * All rights reserved. *) structure Env : sig type env val new : unit -> env val findFunc : env * Atom.atom -> AST.var option val findVar : env * Atom.atom -> AST.var option (* insert a function binding *) val insertFunc : env * Atom.atom * AST.var -> env (* insert variable bindings *) val insertGlobal : env * Atom.atom * AST.var -> env val insertLocal : env * Atom.atom * AST.var -> env end = struct structure ATbl = AtomTable structure AMap = AtomMap (* global environment holds global variables and actors *) datatype global_env = GE of { fEnv : AST.var ATbl.hash_table, (* functions *) vEnv : AST.var ATbl.hash_table (* global variable bindings *) } datatype env = E of { g : global_env, vEnv : AST.var AMap.map } fun new () = E{ g = GE{ fEnv = ATbl.mkTable(128, Fail "global function env"), vEnv = ATbl.mkTable(128, Fail "global variable env") }, vEnv = AMap.empty } fun findFunc (E{g=GE{fEnv, ...}, ...}, x) = ATbl.find fEnv x fun findVar (E{g=GE{vEnv=gvEnv, ...}, vEnv}, x) = (case AMap.find(vEnv, x) of NONE => ATbl.find gvEnv x | someVar => someVar (* end case *)) fun insertFunc (env as E{g=GE{fEnv, ...}, ...}, f, f') = ( ATbl.insert fEnv (f, f'); env) fun insertGlobal (env as E{g=GE{vEnv, ...}, ...}, x, x') = ( ATbl.insert vEnv (x, x'); env) fun insertLocal (env as E{vEnv, g}, x, x') = E{vEnv = AMap.insert(vEnv, x, x'), g = g} end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |