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

SCM Repository

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

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

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

revision 188, Thu Jul 29 22:28:39 2010 UTC revision 189, Fri Jul 30 19:37:01 2010 UTC
# Line 14  Line 14 
14    
15      structure S = Simple      structure S = Simple
16      structure VMap = Var.Map      structure VMap = Var.Map
17        structure VSet = Var.Set
18      structure IL = HighIL      structure IL = HighIL
19    
20      fun lookup env x = (case VMap.find x      fun lookup env x = (case VMap.find x
# Line 23  Line 24 
24                  ])                  ])
25            (* end case *))            (* end case *))
26    
27      (* create a new instance of a variable *)
28        fun newVar x = IL.newVar (Var.nameOf x)
29    
30    (* expression translation *)    (* expression translation *)
31      fun cvtExpr (env, lhs, exp) = (case exp      fun cvtExpr (env, lhs, exp) = (case exp
32             of S.E_Var x => [(lhs, IL.VAR(lookup env x))]             of S.E_Var x => [(lhs, IL.VAR(lookup env x))]
# Line 36  Line 40 
40              | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))]              | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))]
41            (* end case *))            (* end case *))
42    
43      and cvtStmt (env, stm) = (case stm    (* convert a statement, where env is the mapping from Simple AST variables to
44       * their current SSA name, assigned is the set of AST variables assigned to
45       * in the current context, and stm is the statement to convert.
46       *)
47        and cvtStmt (env, assigned, stm, preStms, k) = (case stm
48             of S.S_Block stms =>             of S.S_Block stms =>
49              | S.S_Assign(x, e) =>              | S.S_Assign(x, e) => let
50                    val x' = newVar x
51                    val stms = cvtExp(env, x', e)
52                    val assigned = VSet.add(assigned, x)
53                    val env = VMap.insert(env, x, x')
54                    in
55                      k (env, assigned, stm::preStms)
56                    end
57              | S.S_IfThenElse(x, s1, s2) =>              | S.S_IfThenElse(x, s1, s2) =>
58              | S.S_New(name, xs) =>              | S.S_New(name, xs) =>
59              | S.S_Die =>              | S.S_Die =>

Legend:
Removed from v.188  
changed lines
  Added in v.189

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