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

SCM Repository

[diderot] View of /branches/lamont/src/compiler/ast/ast.sml
ViewVC logotype

View of /branches/lamont/src/compiler/ast/ast.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2416 - (download) (annotate)
Mon Aug 19 12:57:45 2013 UTC (5 years, 11 months ago) by lamonts
File size: 3533 byte(s)
Adding KDTree code for c-tagert and parallel c-target
(* ast.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * A typed abstract-syntax tree representation of Diderot programs.
 *)

structure AST =
  struct

    structure Ty = Types

    type field = Atom.atom

  (* AST variable kinds *)
    datatype var_kind
      = BasisVar
      | InputVar
      | GlobalVar
      | FunVar                  (* user-defined function *)
      | StrandParam             (* parameter to strand definition *)
      | StrandStateVar          (* strand state variable *)
      | StrandOutputVar         (* strand output variable *)
      | LocalVar                (* local variable in method *)

    datatype var = V of {
        name : Atom.atom,	(* print name of variable *)
        id : Stamp.stamp,       (* unique ID *)
        kind : var_kind,        (* variable kind *)
        ty : Ty.scheme          (* type scheme *)
      }

    datatype program = Program of {
	props : StrandUtil.program_prop list,
	decls : decl list
      }

    and decl
      = D_Input of var * string option * expr option
      | D_Var of var_decl                       (* global variable decl *)
      | D_Func of var * var list * stmt         (* user-defined function *)
      | D_Strand of strand                      (* strand decl *)
      | D_InitialArray of create * iter list
      | D_InitialCollection of create * iter list
      | D_Global of stmt 

    and var_decl
      = VD_Decl of var * expr

(* FIXME: these could probably be atoms *)
    and strand_set
       = SS_All
       | SS_Active
       | SS_Stable 

(* FIXME: these should be variables *)
    and reduction
       = R_Max
       | R_Min
       | R_Exists
       | R_All
       | R_Product
       | R_Sum
       | R_Mean 
       | R_Variance

    and strand = Strand of {
        name : Atom.atom,
        params : var list,
        state : var_decl list,
        methods : method list
      }

    and method
      = M_Method of StrandUtil.method_name * stmt

    and create
      = C_Create of (Atom.atom * expr list)

    and iter
    (* NOTE: the typechecker restricts the variable and expression to have integer type *)
      = I_Range of var * expr * expr

    and stmt
      = S_Block of stmt list
      | S_Decl of var_decl
      | S_Foreach of var * Ty.ty * expr * stmt
      | S_IfThenElse of expr * stmt * stmt
      | S_Assign of var * expr
      | S_New of Atom.atom * expr list
      | S_Die
      | S_Stabilize
      | S_Return of expr
      | S_Print of expr list
  
    and expr
      = E_Var of var
      | E_Lit of Literal.literal
      | E_Reduction of reduction * var * strand_set list * expr * Ty.ty * Ty.ty
      | E_Selector of expr * field * Ty.ty 
      | E_Tuple of expr list
      | E_Apply of var * Ty.meta_var list * expr list * Ty.ty
                (* note: operators can be polymorphic, so we record the meta-variable parameters. *)
      | E_Cons of expr list                             (* tensor-value construction *)
      | E_Seq of expr list                              (* sequence-value construction *)
      | E_Slice of expr * expr option list * Ty.ty      (* tensor slicing *)
      | E_Cond of expr * expr * expr * Ty.ty            (* ty is result type *)
      | E_LoadNrrd of Ty.meta_var list * string * Ty.ty (* dynamic sequence and image loading *)
      | E_Coerce of {                                   (* coercion between types *)
            srcTy : Ty.ty,
            dstTy : Ty.ty,
            e : expr
          }

  end

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