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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3189 - (download) (annotate)
Thu Apr 2 18:49:21 2015 UTC (4 years, 5 months ago) by cchiw
File size: 4255 byte(s)
lift curl expression
(* 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 : unit -> 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_D,
          BV.op_Dotimes,
          BV.op_Ddot,
        (*  BV.op_norm,*)
            BV.op_not,
        (* functions *)
          BV.fn_inside,
          BV.fn_max,
          BV.fn_min,
          BV.fn_modulate,
          BV.fn_principleEvec
        ] @ (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_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, BV.add_ft, BV.add_tf]),
          (N.op_sub, [BV.sub_ii, BV.sub_tt, BV.sub_ff, BV.sub_ft, BV.sub_tf]),
          (N.op_mul, [BV.mul_ii, BV.mul_rr, BV.mul_rt, BV.mul_tr, BV.mul_rf, BV.mul_fr,BV.mul_ss,BV.mul_sf,BV.mul_fs,BV.mul_st, BV.mul_ts]),
          (N.op_div, [BV.div_ii, BV.div_rr, BV.div_tr, BV.div_tr, BV.div_fr,BV.div_ss, BV.div_fs]),
          (N.op_exp, [BV.exp_ri, BV.exp_rr]),
          (N.op_curl, [BV.curl2D, BV.curl3D]),
          (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]),

          (*first operator is tensor, next is field *)
          (N.op_outer,[BV.op_outer_tt,BV.op_outer_ff]),
          (N.op_dot, [BV.op_inner_tt, BV.op_inner_tf, BV.op_inner_ft, BV.op_inner_ff]),
          (N.op_cross, [BV.op_cross2_tt,BV.op_cross3_tt,BV.op_cross2_ff,BV.op_cross3_ff]),
          (N.op_norm,  [BV.op_norm_t, BV.op_norm_f]),
          (N.fn_normalize,[BV.fn_normalize_t, BV.fn_normalize_f]),
          (N.fn_trace, [BV.fn_trace_t, BV.fn_trace_f]),
          (N.fn_transpose, [BV.fn_transpose_t, BV.fn_transpose_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]),
          (N.fn_det,    [BV.fn_det_t2,BV.fn_det_t3,BV.fn_det_f2,BV.fn_det_f3]),
          (N.fn_sqrt, [BV.fn_sqrt_f,BV.fn_sqrt_t]),
          (N.fn_cos,[BV.fn_cos_f]),
          (N.fn_acos,[BV.fn_acos_f]),
          (N.fn_sin,[BV.fn_sin_f]),
          (N.fn_asin,[BV.fn_asin_f]),

        (* assignment operators are bound to the corresponding binary operator *)
          (N.asgn_add, [BV.add_ii, BV.add_tt, BV.add_ff, BV.add_ft]),
          (N.asgn_sub, [BV.sub_ii, BV.sub_tt, BV.sub_ff, BV.sub_ft]),
          (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 *)
    fun env () = let
          fun insF (x, env) = Env.insertFunc(env, Atom.atom(Var.nameOf x), Env.PrimFun[x])
          fun insV (x, env) = Env.insertGlobal(env, Atom.atom(Var.nameOf x), x)
          fun insOvld ((f, fns), env) = Env.insertFunc(env, f, Env.PrimFun 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
      val restricted = List.foldl Var.Set.add' Var.Set.empty [
              BV.fn_image
            ]
    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