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

SCM Repository

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

Annotation of /branches/charisee/src/compiler/basis/math-funs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3112 - (view) (download)

1 : jhr 1923 (* math-funs.sml
2 : jhr 1115 *
3 : jhr 1923 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 1115 * All rights reserved.
5 :     *
6 : jhr 1923 * These are a subset of the C math functions, which the various IL optimization passes
7 :     * treat as "black boxes", so we do not need to have a separate operator constructor
8 : jhr 1115 * for each.
9 :     *)
10 :    
11 : jhr 1923 structure MathFuns :> sig
12 : jhr 1115
13 :     type name
14 :    
15 : jhr 1923 val toAtom : name -> Atom.atom
16 : jhr 1115 val toString : name -> string
17 :     val same : name * name -> bool
18 :     val hash : name -> word
19 :    
20 : jhr 1923 (* number of arguments; all args are real and result is a real *)
21 :     val arity : name -> int
22 :    
23 :     (* Basis functions *)
24 : jhr 1115 val pow : name
25 :     val allFuns : name list
26 :    
27 :     structure Tbl : MONO_HASH_TABLE where type Key.hash_key = name
28 :    
29 :     end = struct
30 :    
31 : jhr 1923 datatype name = N of Atom.atom * int
32 : jhr 1115
33 : jhr 1923 fun toAtom (N(f, _)) = f
34 :     fun toString (N(f, _)) = Atom.toString f
35 :     fun same (N(f1, _), N(f2, _)) = Atom.same(f1, f2)
36 :     fun hash (N(f, _)) = Atom.hash f
37 : jhr 1115
38 : jhr 1923 fun arity (N(_, n)) = n
39 : jhr 1115
40 : jhr 1923 (* Basis functions (in alphabetical order). The names used here are from the C math.h API *)
41 :     val pow = N(Atom.atom "pow", 2)
42 : jhr 1115 val allFuns = [
43 : jhr 1923 N(Atom.atom "acos", 1),
44 :     N(Atom.atom "asin", 1),
45 :     N(Atom.atom "atan", 1),
46 :     N(Atom.atom "atan2", 2),
47 : jhr 2356 N(Atom.atom "ceil", 1),
48 : jhr 1923 N(Atom.atom "cos", 1),
49 : jhr 2356 N(Atom.atom "floor", 1),
50 : jhr 1923 N(Atom.atom "fmod", 2),
51 :     N(Atom.atom "log", 1),
52 :     N(Atom.atom "log10", 1),
53 : jhr 2356 N(Atom.atom "log2", 1),
54 : jhr 1923 pow, (* also used to implement ^ operator *)
55 :     N(Atom.atom "sin", 1),
56 : cchiw 3112 (* N(Atom.atom "sqrt", 1),*)
57 : jhr 1923 N(Atom.atom "tan", 1)
58 : jhr 1115 ]
59 :    
60 : jhr 1923 structure Tbl = HashTableFn (
61 :     struct
62 :     type hash_key = name
63 :     val hashVal = hash
64 :     val sameKey = same
65 :     end)
66 : jhr 1115
67 :     end

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