Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /trunk/src/compiler/env/env.sml
ViewVC logotype

Diff of /trunk/src/compiler/env/env.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 110, Wed Jun 23 19:28:48 2010 UTC revision 169, Thu Jul 22 20:07:37 2010 UTC
# Line 10  Line 10 
10    
11      val new : unit -> env      val new : unit -> env
12    
13        val findFunc : env * Atom.atom -> AST.var option
14    
15      val findVar : env * Atom.atom -> AST.var option      val findVar : env * Atom.atom -> AST.var option
16    
17      (* insert a function binding *)
18        val insertFunc : env * Atom.atom * AST.var -> env
19    
20      (* insert variable bindings *)
21      val insertGlobal : env * Atom.atom * AST.var -> env      val insertGlobal : env * Atom.atom * AST.var -> env
22      val insertLocal : env * Atom.atom * AST.var -> env      val insertLocal : env * Atom.atom * AST.var -> env
23    
# Line 22  Line 28 
28    
29    (* global environment holds global variables and actors *)    (* global environment holds global variables and actors *)
30      datatype global_env = GE of {      datatype global_env = GE of {
31          vEnv : AST.var ATbl.hash_table          fEnv : AST.var ATbl.hash_table,         (* functions *)
32            vEnv : AST.var ATbl.hash_table          (* global variable bindings *)
33        }        }
34    
35      datatype env = E of {      datatype env = E of {
# Line 31  Line 38 
38        }        }
39    
40      fun new () = E{      fun new () = E{
41              g = GE{vEnv = ATbl.mkTable(128, Fail "global env")},              g = GE{
42                    fEnv = ATbl.mkTable(128, Fail "global function env"),
43                    vEnv = ATbl.mkTable(128, Fail "global variable env")
44                  },
45              vEnv = AMap.empty              vEnv = AMap.empty
46            }            }
47    
48        fun findFunc (E{g=GE{fEnv, ...}, ...}, x) = ATbl.find fEnv x
49    
50      fun findVar (E{g=GE{vEnv=gvEnv, ...}, vEnv}, x) = (case AMap.find(vEnv, x)      fun findVar (E{g=GE{vEnv=gvEnv, ...}, vEnv}, x) = (case AMap.find(vEnv, x)
51             of NONE => ATbl.find gvEnv x             of NONE => ATbl.find gvEnv x
52              | someVar => someVar              | someVar => someVar
53            (* end case *))            (* end case *))
54    
55        fun insertFunc (env as E{g=GE{fEnv, ...}, ...}, f, f') = (
56              ATbl.insert fEnv (f, f');
57              env)
58    
59      fun insertGlobal (env as E{g=GE{vEnv, ...}, ...}, x, x') = (      fun insertGlobal (env as E{g=GE{vEnv, ...}, ...}, x, x') = (
60            ATbl.insert vEnv (x, x');            ATbl.insert vEnv (x, x');
61            env)            env)

Legend:
Removed from v.110  
changed lines
  Added in v.169

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0