Vector Test:

The file tests the code generation for the vector module.

The VECTOR module type is defind in the the file src/ A model
implementation for n-dimensional vector over aribtrary number and tuple
types is in functor 'VectorStaged' in the file src/

The following instantiation is an example for creating a vector
module over the floating point number type with a 2-record representation
for its coordinate tuple:

type module V2R = VectorStaged (Float_Real_Exact)(Record2D)

Code generation for the following functions are tested in

(* vector substraction a - b *)
val sub : 'a vector_s -> 'a vector_s -> 'a vector_s
(* vector dot product *)
val dot : 'a vector_s -> 'a vector_s -> 'a N.ns
(* vector length *)
val length : 'a vector_s -> 'a N.ns

It is instructive to describe one of the generators in details. Consider
the function Gen.length in which has the following code:

module Gen (V : VECTOR) =
let length _ =
    .< fun a -> .~(Staged.to_code (V.length (of_atom .< a >.))) >.

First, the output is a code for a function with one parameter, 'a', which
is a vector of type V.vector. The code expression from 'a' is constructed
by 'of_atom ..'. of_atom creates a code_expr expression with atomicity
flag = true. This will help later in the desion of generating let-bindings.
The resultant vector expression is passed to V.length, and the produced
staged expression is converted to code before inling it.

The output file contains the outputs. We show here a snippet.

The following two instantiations were done over float number types. The
first instantiation is has a 2D pair type for storing the coordinates:

module V2P = VectorStaged (Float_Real_Exact)(Pair2D)
module GV2P = Gen(V2P)
GV2P.length ()

which produces the code:

- : ('a, V2P.vector -> V2P.N.n) code =
. (sqrt ( ((fst a_1) *. (fst a_1))
                      +. ((snd a_1) *. (snd a_1))) )>.

The second instantiation is has a 3D record type for storing the

module V3R = VectorStaged (Float_Real_Exact)(Record3D)
module GV3R = Gen(V3R)
GV3R.length ()

which produces the code:

- : ('a, V3R.vector -> V3R.N.n) code =
. (sqrt ( (a_1.z *. a_1.z) +.
                     ((a_1.x *. a_1.x) +.
                     (a_1.y *. a_1.y)) ))>.