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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/src/compiler/codegen/target-env.sml
ViewVC logotype

Annotation of /branches/pure-cfg/src/compiler/codegen/target-env.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1505 - (view) (download)

1 : jhr 1447 (* target-env.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure TargetEnv : sig
8 :    
9 :     type 'info env
10 :    
11 :     datatype scope
12 :     = NoScope
13 :     | GlobalScope
14 :     | InitiallyScope
15 :     | StrandScope of TreeIL.var list (* strand initialization *)
16 : jhr 1505 | MethodScope of StrandUtil.method_name * TreeIL.var list (* method body; vars are state variables *)
17 : jhr 1447
18 :     (* create a new environment *)
19 :     val new : 'info -> 'info env
20 :    
21 :     (* mark the global initialization scope *)
22 :     val scopeGlobal : 'info env -> 'info env
23 :     (* mark the initial strand creation scope *)
24 :     val scopeInitially : 'info env -> 'info env
25 :     (* mark the strand initialization scope; the variables are strand state vars *)
26 :     val scopeStrand : 'info env * TreeIL.var list -> 'info env
27 :     (* mark the strand method scope; the variables are strand state vars *)
28 : jhr 1505 val scopeMethod : 'info env * StrandUtil.method_name * TreeIL.var list -> 'info env
29 : jhr 1447
30 :     val scope : 'info env -> scope
31 :     val info : 'info env -> 'info
32 :    
33 :     val bind : 'info env * TreeIL.var * CLang.typed_var -> 'info env
34 :     val lookup : 'info env * TreeIL.var -> CLang.typed_var
35 :    
36 :     end = struct
37 :    
38 :     structure V = TreeIL.Var
39 :     structure CL = CLang
40 :    
41 :     datatype 'info env = ENV of {
42 :     info : 'info, (* target-specific info *)
43 :     vMap : CL.typed_var V.Map.map, (* mapping from TreeIL variables to target variables *)
44 :     scope : scope (* current translation scope *)
45 :     }
46 :    
47 :     and scope
48 :     = NoScope
49 :     | GlobalScope
50 :     | InitiallyScope
51 :     | StrandScope of TreeIL.var list (* strand initialization *)
52 : jhr 1505 | MethodScope of StrandUtil.method_name * TreeIL.var list (* method body; vars are state variables *)
53 : jhr 1447
54 :     (* create a new environment *)
55 :     fun new info = ENV{
56 :     info = info,
57 :     vMap = V.Map.empty,
58 :     scope = NoScope
59 :     }
60 :    
61 :     (* define the current translation context *)
62 :     fun setScope scope (ENV{info, vMap, ...}) = ENV{info=info, vMap=vMap, scope=scope}
63 :     fun scopeGlobal env = setScope GlobalScope env
64 :     fun scopeInitially env = setScope InitiallyScope env
65 :     fun scopeStrand (env, svars) = setScope (StrandScope svars) env
66 :     fun scopeMethod (env, name, svars) = setScope (MethodScope(name, svars)) env
67 :    
68 :     fun scope (ENV{scope, ...}) = scope
69 :     fun info (ENV{info, ...}) = info
70 :    
71 :     (* bind a TreeIL varaiable to a target variable *)
72 :     fun bind (ENV{info, vMap, scope}, x, x') = ENV{
73 :     info = info,
74 :     vMap = V.Map.insert(vMap, x, x'),
75 :     scope = scope
76 :     }
77 :    
78 :     fun lookup (ENV{vMap, ...}, x) = (case V.Map.find (vMap, x)
79 :     of SOME x' => x'
80 :     | NONE => raise Fail(concat["TargetEnv.lookup(_, ", V.name x, ")"])
81 :     (* end case *))
82 :    
83 :     end

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