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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (download) (annotate)
Fri Aug 6 20:20:42 2010 UTC (9 years ago) by jhr
File size: 2767 byte(s)
  Added infix convolve syntax
(* basis.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Type definitions for Basis functions.
 *)

structure Basis : sig

    val env : Env.env

  (* find an operator by name; this returns a singleton list for regular operators (including
   * type-index operators) and a list of variables for overloaded operators.
   *)
    val findOp : Atom.atom -> AST.var list

  (* certain operations are restricted to only appear at global scope (i.e., not in an
   * actor body).  This function returns true for such operations.
   *)
    val isRestricted : AST.var -> bool

  end = struct

    structure N = BasisNames
    structure BV = BasisVars
    structure ATbl = AtomTable

  (* non-overloaded operators, etc. *)
    val basisFunctions = [
	(* non-overloaded operators *)
	  BV.op_at,
	  BV.op_convolve,
	  BV.op_D,
	  BV.op_norm,
	  BV.op_not,
	  BV.op_subscript,
	(* functions *)
	  BV.fn_CL,
	  BV.fn_convolve,	(* depreciated *)
	  BV.fn_cos,
	  BV.fn_dot,
	  BV.fn_inside,
	  BV.fn_load,
	  BV.fn_max,
	  BV.fn_min,
	  BV.fn_modulate,
	  BV.fn_pow,
	  BV.fn_principleEvec,
	  BV.fn_sin
	]

      val basisVars = [
	(* kernels *)
	  BV.kn_bspln3,
	  BV.kn_bspln5,
	  BV.kn_ctmr,
	  BV.kn_tent
	]

    (* seed the basis environment *)
      val env = let
	    fun insF (x, env) = Env.insertFunc(env, Atom.atom(Var.nameOf x), x)
	    fun insV (x, env) = Env.insertGlobal(env, Atom.atom(Var.nameOf x), x)
	    val env = List.foldl insF (Env.new()) basisFunctions
	    val env = List.foldl insV env basisVars
	    in
	      env
	    end

  (* overloaded operators *)
    val overloads = [
	  (N.op_add, [BV.add_ii, BV.add_tt]),
	  (N.op_sub, [BV.sub_ii, BV.sub_tt]),
	  (N.op_mul, [BV.mul_ii, BV.mul_rr, BV.mul_rt, BV.mul_tr]),
	  (N.op_div, [BV.div_ii, BV.div_rr, BV.div_tr]),
	  (N.op_lt, [BV.lt_ii, BV.lt_rr]),
	  (N.op_lte, [BV.lte_ii, BV.lte_rr]),
	  (N.op_equ, [BV.equ_bb, BV.equ_ii, BV.equ_ss, BV.equ_rr]),
	  (N.op_neq, [BV.neq_bb, BV.neq_ii, BV.neq_ss, BV.neq_rr]),
	  (N.op_gte, [BV.gte_ii, BV.gte_rr]),
	  (N.op_gt, [BV.gt_ii, BV.gt_rr]),
	  (N.op_neg, [BV.neg_i, BV.neg_t, BV.neg_f])
	]

    local
      val find = let
	    val tbl = ATbl.mkTable(64, Fail "op table")
	    in
	      List.app (ATbl.insert tbl) overloads;
	      ATbl.find tbl
	    end
    in
    fun findOp name = (case Env.findFunc(env, name)
	   of SOME x => [x]
	    | NONE => (case find name
		 of SOME xs => xs
		  | NONE => raise Fail("unknown operator "^Atom.toString name)
		(* end case *))
	  (* end case *))
    end (* local *)

    local
      val restricted = List.foldl Var.Set.add' Var.Set.empty [
	      BV.fn_load
	    ]
    in
    fun isRestricted x = Var.Set.member (restricted, x)
    end (* local *)

  end

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