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 3349 - (view) (download)

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

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