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

SCM Repository

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

View of /branches/vis12/src/compiler/basis/basis.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1992 - (download) (annotate)
Thu Sep 27 10:23:12 2012 UTC (7 years, 1 month ago) by jhr
File size: 3114 byte(s)
  Working on dynamic sequence loading
(* basis.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Type definitions for Basis functions.
 *)

structure Basis : sig

    val env : Env.env

  (* certain operations are restricted to only appear at global scope (i.e., not in an
   * strand 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_cross,
	  BV.op_outer,
	  BV.op_D,
	  BV.op_Dotimes,
	  BV.op_norm,
	  BV.op_not,
	(* functions *)
	  BV.fn_inside,
	  BV.fn_length,
	  BV.fn_max,
	  BV.fn_min,
	  BV.fn_modulate,
	  BV.fn_normalize,
	  BV.fn_principleEvec,
	  BV.fn_trace
	] @ (List.map #2 BV.mathFns)

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

  (* overloaded operators and functions *)
    val overloads = [
          (N.op_at, [BV.at_Td, BV.at_dT, BV.at_dd]),
	  (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_add, [BV.add_ii, BV.add_tt, BV.add_ff]),
	  (N.op_sub, [BV.sub_ii, BV.sub_tt, BV.sub_ff]),
	  (N.op_mul, [BV.mul_ii, BV.mul_rr, BV.mul_rt, BV.mul_tr, BV.mul_rf, BV.mul_fr]),
	  (N.op_div, [BV.div_ii, BV.div_rr, BV.div_tr, BV.div_tr]),
	  (N.op_exp, [BV.exp_ri, BV.exp_rr]),
	  (N.op_convolve, [BV.convolve_vk, BV.convolve_kv]),
	  (N.op_lt, [BV.lt_ii, BV.lt_rr]),
	  (N.op_neg, [BV.neg_i, BV.neg_t, BV.neg_f]),
	  (N.fn_clamp, [BV.clamp_rrr, BV.clamp_vvv]),
	  (N.fn_lerp, [BV.lerp5, BV.lerp3]),
	  (N.fn_evals, [BV.evals2x2, BV.evals3x3]),
	  (N.fn_evecs, [BV.evecs2x2, BV.evecs3x3]),
	(* assignment operators are bound to the corresponding binary operator *)
	  (N.asgn_add, [BV.add_ii, BV.add_tt, BV.add_ff]),
	  (N.asgn_sub, [BV.sub_ii, BV.sub_tt, BV.sub_ff]),
	  (N.asgn_mul, [BV.mul_ii, BV.mul_rr, BV.mul_tr, BV.mul_fr]),
	  (N.asgn_div, [BV.div_ii, BV.div_rr, BV.div_tr, BV.div_tr])
	]

    (* 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)
	  fun insOvld ((f, fns), env) = Env.insertFunc(env, f, fns)
	  val env = List.foldl insF (Env.new()) basisFunctions
	  val env = List.foldl insV env basisVars
	  val env = List.foldl insOvld env overloads
	  in
	    env
	  end

    local
(* FIXME: the image and load functions are now handled as special syntax in the parser, so it
 * shouldn't be necessary to maintain a restricted set of functions.
 *)
      val restricted = List.foldl Var.Set.add' Var.Set.empty [
	      BV.fn_image, 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