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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2636 - (download) (annotate)
Tue May 27 16:18:36 2014 UTC (5 years, 1 month ago) by jhr
File size: 2981 byte(s)
  Merging changes from vis12 branch (via staging).  The main change is the new
  syntax for inputs (especially image inputs).
(* 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

  (* 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 : string,          (* 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

    and var_decl
      = VD_Decl of var * expr

    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_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_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 (* 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