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

SCM Repository

[diderot] View of /branches/lamont/src/compiler/codegen/target-env.sml
ViewVC logotype

View of /branches/lamont/src/compiler/codegen/target-env.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2081 - (download) (annotate)
Mon Nov 5 23:26:06 2012 UTC (7 years ago) by lamonts
File size: 2841 byte(s)
Creating new developmented branch based on vis12
(* target-env.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure TargetEnv : sig

    type 'info env

    datatype scope
      = NoScope
      | GlobalScope
      | InitiallyScope
      | StrandScope of TreeIL.var list  (* strand initialization *)
      | MethodScope of StrandUtil.method_name * TreeIL.var list  (* method body; vars are state variables *)

  (* create a new environment *)
    val new : 'info -> 'info env

  (* mark the global initialization scope *)
    val scopeGlobal : 'info env -> 'info env
  (* mark the initial strand creation scope *)
    val scopeInitially : 'info env -> 'info env
  (* mark the strand initialization scope; the variables are strand state vars *)
    val scopeStrand : 'info env * TreeIL.var list -> 'info env
  (* mark the strand method scope; the variables are strand state vars *)
    val scopeMethod : 'info env * StrandUtil.method_name * TreeIL.var list -> 'info env

    val scope : 'info env -> scope
    val info : 'info env -> 'info

    val bind : 'info env * TreeIL.var * CLang.typed_var -> 'info env
    val lookup : 'info env * TreeIL.var -> CLang.typed_var

  end = struct

    structure V = TreeIL.Var
    structure CL = CLang

    datatype 'info env = ENV of {
        info : 'info,                   (* target-specific info *)
        vMap : CL.typed_var V.Map.map,  (* mapping from TreeIL variables to target variables *)
        scope : scope                   (* current translation scope *)
      }

    and scope
      = NoScope
      | GlobalScope
      | InitiallyScope
      | StrandScope of TreeIL.var list  (* strand initialization *)
      | MethodScope of StrandUtil.method_name * TreeIL.var list  (* method body; vars are state variables *)

  (* create a new environment *)
    fun new info = ENV{
            info = info,
            vMap = V.Map.empty,
            scope = NoScope
          }

  (* define the current translation context *)
    fun setScope scope (ENV{info, vMap, ...}) = ENV{info=info, vMap=vMap, scope=scope}
    fun scopeGlobal env = setScope GlobalScope env
    fun scopeInitially env = setScope InitiallyScope env
    fun scopeStrand (env, svars) = setScope (StrandScope svars) env
    fun scopeMethod (env, name, svars) = setScope (MethodScope(name, svars)) env

    fun scope (ENV{scope, ...}) = scope
    fun info (ENV{info, ...}) = info

  (* bind a TreeIL varaiable to a target variable *)
    fun bind (ENV{info, vMap, scope}, x, x') = ENV{
            info = info,
            vMap = V.Map.insert(vMap, x, x'),
            scope = scope
          }

    fun lookup (ENV{vMap, ...}, x) = (case V.Map.find (vMap, x)
           of SOME x' => x'
            | NONE => raise Fail(concat["TargetEnv.lookup(_, ", V.name x, ")"])
          (* end case *))

  end

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