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

SCM Repository

[diderot] View of /branches/lamont/src/compiler/basis/math-funs.sml
ViewVC logotype

View of /branches/lamont/src/compiler/basis/math-funs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (download) (annotate)
Fri Mar 15 22:18:22 2013 UTC (6 years, 6 months ago) by jhr
File size: 1727 byte(s)
  Merging in changes from vis12 branch.
(* math-funs.sml
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * These are a subset of the C math functions, which the various IL optimization passes
 * treat as "black boxes", so we do not need to have a separate operator constructor
 * for each.
 *)

structure MathFuns :> sig

    type name

    val toAtom : name -> Atom.atom
    val toString : name -> string
    val same : name * name -> bool
    val hash : name -> word

  (* number of arguments; all args are real and result is a real *)
    val arity : name -> int

  (* Basis functions *)
    val pow : name
    val allFuns : name list

    structure Tbl : MONO_HASH_TABLE where type Key.hash_key = name

  end = struct

    datatype name = N of Atom.atom * int

    fun toAtom (N(f, _)) = f
    fun toString (N(f, _)) = Atom.toString f
    fun same (N(f1, _), N(f2, _)) = Atom.same(f1, f2)
    fun hash (N(f, _)) = Atom.hash f

    fun arity (N(_, n)) = n

  (* Basis functions (in alphabetical order). The names used here are from the C math.h API *)
    val pow = N(Atom.atom "pow", 2)
    val allFuns = [
	    N(Atom.atom "acos", 1),
	    N(Atom.atom "asin", 1),
	    N(Atom.atom "atan", 1),
	    N(Atom.atom "atan2", 2),
	    N(Atom.atom "ceil", 1),
	    N(Atom.atom "cos", 1),
	    N(Atom.atom "floor", 1),
	    N(Atom.atom "fmod", 2),
	    N(Atom.atom "log", 1),
	    N(Atom.atom "log10", 1),
	    N(Atom.atom "log2", 1),
	    pow,			(* also used to implement ^ operator *)
	    N(Atom.atom "sin", 1),
	    N(Atom.atom "sqrt", 1),
	    N(Atom.atom "tan", 1)
	  ]

    structure Tbl = HashTableFn (
      struct
	type hash_key = name
	val hashVal = hash
	val sameKey = same
      end)

  end

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