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

# SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml
 [diderot] / branches / pure-cfg / src / compiler / c-target / c-target.sml

# Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml

revision 683, Thu Mar 24 00:42:27 2011 UTC revision 695, Fri Mar 25 17:52:54 2011 UTC
# Line 341  Line 341
341          val max = binFn RN.max          val max = binFn RN.max
342          end (* local *)          end (* local *)
343
(* math functions *)
fun pow (E(e1, T_Real), E(e2, T_Real)) =
if !Controls.doublePrecision
then E(CL.mkApply("pow", [e1, e2]), T_Real)
else E(CL.mkApply("powf", [e1, e2]), T_Real)
| pow _ = raise Fail "invalid arguments to pow"

local
fun r2r (ff, fd) (E(e, T_Real)) = if !Controls.doublePrecision
then E(CL.mkApply(fd, [e]), T_Real)
else E(CL.mkApply(ff, [e]), T_Real)
| r2r (_, fd) e = invalid (fd, [e])
in
val sin = r2r ("sinf", "sin")
val cos = r2r ("cosf", "cos")
val sqrt = r2r ("sqrtf", "sqrt")
end (* local *)

344        (* rounding *)        (* rounding *)
345          fun trunc (E(e, ty)) = E(CL.mkApply(RN.addTySuffix("trunc", ty), [e]), ty)          fun trunc (E(e, ty)) = E(CL.mkApply(RN.addTySuffix("trunc", ty), [e]), ty)
346          fun round (E(e, ty)) = E(CL.mkApply(RN.addTySuffix("round", ty), [e]), ty)          fun round (E(e, ty)) = E(CL.mkApply(RN.addTySuffix("round", ty), [e]), ty)
# Line 402  Line 384
384                end                end
385            | inside (a, b, _) = invalid("inside", [a, b])            | inside (a, b, _) = invalid("inside", [a, b])
386
387          (* other basis functions *)
388            local
389              val basis = [
390                      (ILBasis.atan2, fn [E(e1, T_Real), E(e2, T_Real)] => SOME[e1, e2] | _ => NONE, T_Real),
391                      (ILBasis.cos,   fn [E(e, T_Real)] => SOME[e] | _ => NONE, T_Real),
392                      (ILBasis.pow,   fn [E(e1, T_Real), E(e2, T_Real)] => SOME[e1, e2] | _ => NONE, T_Real),
393                      (ILBasis.sin,   fn [E(e, T_Real)] => SOME[e] | _ => NONE, T_Real),
394                      (ILBasis.sqrt,  fn [E(e, T_Real)] => SOME[e] | _ => NONE, T_Real),
395                      (ILBasis.tan,   fn [E(e, T_Real)] => SOME[e] | _ => NONE, T_Real)
396                    ]
397              fun mkLookup suffix = let
398                    val tbl = ILBasis.Tbl.mkTable (16, Fail "basis table")
399                    fun ins (f, chkTy, resTy) =
400                          ILBasis.Tbl.insert tbl
401                            (f, (ILBasis.toString f ^ suffix, chkTy, resTy))
402                    in
403                      List.app ins basis;
404                      ILBasis.Tbl.lookup tbl
405                    end
406              val fLookup = mkLookup "f"
407              val dLookup = mkLookup ""
408            in
409            fun apply (f, args) = let
410                  val (f', chkArgs, resTy) = if !Controls.doublePrecision then dLookup f else fLookup f
411                  in
412                    case chkArgs args
413                     of SOME args => E(CL.mkApply(f', args), resTy)
414                      | NONE => raise Fail("invalid arguments for "^ILBasis.toString f)
415                  end
416            end (* local *)
417        end (* Expr *)        end (* Expr *)
418
419    (* statement construction *)    (* statement construction *)

Legend:
 Removed from v.683 changed lines Added in v.695

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