(* TEST
 readonly_files = "main.c";
 arguments = "-DINT_FLOAT -DFUN=test main.c";
 asmgen;
*)

(**************************************************************************)
(*                                                                        *)
(*                                OCaml                                   *)
(*                                                                        *)
(*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           *)
(*                                                                        *)
(*   Copyright 1996 Institut National de Recherche en Informatique et     *)
(*     en Automatique.                                                    *)
(*                                                                        *)
(*   All rights reserved.  This file is distributed under the terms of    *)
(*   the GNU Lesser General Public License version 2.1, with the          *)
(*   special exception on linking described in the file LICENSE.          *)
(*                                                                        *)
(**************************************************************************)

("res_square": skip 8)
("h": skip 8)
("x": skip 8)
("s": skip 8)
("res_integr": skip 8)

(function "square" (x: val)
   (let r "res_square"
        (store float r ( *f (load float x) (load float x)))
        r))

(function "integr" (f: val low: val high: val n: int)
  (letmut (h val "h" x val "x" s val "s" i int n)
    (store float h (/f (-f (load float high) (load float low)) (floatofint n)))
    (store float x (load float low))
    (store float s 0.0)
    (while (> i 0)
      (store float s (+f (load float s) (load float (app f x val))))
      (store float x (+f (load float x) (load float h)))
      (assign i (- i 1)))
    (store float "res_integr" ( *f (load float s) (load float h)))
    "res_integr"))

("low": skip 8)
("hi": skip 8)

(function "test" (n: int)
  (store float "low" 0.0)
  (store float "hi" 1.0)
  (load float (app "integr" "square" "low" "hi" n val)))
