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 168, Wed Jul 21 20:58:37 2010 UTC revision 176, Mon Jul 26 19:47:48 2010 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Translate AST code into the IL representation.   * Translate Simple-AST code into the IL representation.
7   *)   *)
8    
9  structure Translate : sig  structure Translate : sig
10    
11      val translate : AST.program -> ??      val translate : Simple.program -> HighIL.program
12    
13    end = struct    end = struct
14    
15        structure S = Simple
16      structure VMap = Var.Map      structure VMap = Var.Map
17      structure IL = HighIL      structure IL = HighIL
18    
19        fun lookup env x = (case VMap.find x
20               of SOME x' => x'
21                | NONE => raise Fail(concat[
22                      "no binding for ", Var.toString x, " in environment"
23                    ])
24              (* end case *))
25    
26    (* expression translation *)    (* expression translation *)
27      fun cvtExpr (env, exp, kont) = let      fun cvtExpr (env, exp) = (case exp
28            fun cvt e = (case e             of S.E_Var x => IL.VAR(lookup env x)
29                   of AST.E_Var(x, tyArgs, ty) =>              | S.E_Lit lit => IL.LIT lit
30                    | AST.E_Lit lit =>              | S.E_Tuple xs => raise Fail "E_Tuple not implemeted"
31                    | AST.E_Tuple es =>              | S.E_Apply(f, tyArgs, args, ty) =>
32                    | AST.E_Apply(f, tyArgs, args, ty) =>              | S.E_Cons args => IL.CONS(List.map (lookup env) args)
                   | AST.E_Cons of expr list  
                   | AST.E_Cond(e1, e2, e3) =>  
33                  (* end case *))                  (* end case *))
           in  
           end  
34    
35      and cvtStmt (env, stm) = (case stm      and cvtStmt (env, stm) = (case stm
36             of AST.S_Block of stmt list             of S.S_Block stms =>
37              | AST.S_Decl of var_decl              | S.S_Assign(x, e) =>
38              | AST.S_IfThenElse of expr * stmt * stmt              | S.S_IfThenElse(x, s1, s2) =>
39              | AST.S_Assign of var * expr              | S.S_New(name, xs) =>
40              | AST.S_New of Atom.atom * expr list              | S.S_Die =>
41              | AST.S_Die              | S.S_Stabilize =>
             | AST.S_Stabilize  
42            (* end case *))            (* end case *))
43    
44        fun translate (S.Program{globals, globaInit, actors}) = ??
45    
46    end    end

Legend:
Removed from v.168  
changed lines
  Added in v.176

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