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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 189 - (download) (annotate)
Fri Jul 30 19:37:01 2010 UTC (9 years, 2 months ago) by jhr
File size: 1840 byte(s)
  Working on translation to HighIL
(* translate.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Translate Simple-AST code into the IL representation.
 *)

structure Translate : sig

    val translate : Simple.program -> HighIL.program

  end = struct

    structure S = Simple
    structure VMap = Var.Map
    structure VSet = Var.Set
    structure IL = HighIL

    fun lookup env x = (case VMap.find x
	   of SOME x' => x'
	    | NONE => raise Fail(concat[
		  "no binding for ", Var.toString x, " in environment"
		])
	  (* end case *))

  (* create a new instance of a variable *)
    fun newVar x = IL.newVar (Var.nameOf x)

  (* expression translation *)
    fun cvtExpr (env, lhs, exp) = (case exp
	   of S.E_Var x => [(lhs, IL.VAR(lookup env x))]
	    | S.E_Lit lit => [(lhs, IL.LIT lit)]
	    | S.E_Tuple xs => raise Fail "E_Tuple not implemeted"
	    | S.E_Apply(f, tyArgs, args, ty) => let
		val args' = List.map (lookup env) args
		in
		  TranslateBasis.translate (lhs, f, tyArgs, args')
		end
	    | S.E_Cons args => [(lhs, IL.CONS(List.map (lookup env) args))]
	  (* end case *))

  (* convert a statement, where env is the mapping from Simple AST variables to
   * their current SSA name, assigned is the set of AST variables assigned to
   * in the current context, and stm is the statement to convert.
   *)
    and cvtStmt (env, assigned, stm, preStms, k) = (case stm
	   of S.S_Block stms =>
	    | S.S_Assign(x, e) => let
		val x' = newVar x
		val stms = cvtExp(env, x', e)
		val assigned = VSet.add(assigned, x)
		val env = VMap.insert(env, x, x')
		in
		  k (env, assigned, stm::preStms)
		end
	    | S.S_IfThenElse(x, s1, s2) =>
	    | S.S_New(name, xs) =>
	    | S.S_Die =>
	    | S.S_Stabilize =>
	  (* end case *))

    fun translate (S.Program{globals, globaInit, actors}) = ??

  end

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