Commit a06b3202 authored by Erwan Jahier's avatar Erwan Jahier

Add some non-regression tests for lutin + allow negative integers in range decl (for lutin).

parent dba1fafa
\section{The Lutin program interpreter}
\section{Executing Lutin programs}
\subsection{The toplevel interpreter options}
\subsection{The toplevel interpreter}
Here is the output of {\tt lutin --help}:
\begin{alltt}
......@@ -18,7 +18,8 @@ programs.
\paragraph{Calling the Lutin interpreter from C.}
In order to do that from C, one can use the functions provided in the
\verb+luc4c_stubs.h+ header file. A complete example can be found in
\verb+luc4c_stubs.h+ header file (that should be in the
distribution). A complete example can be found in
\verb+examples/lutin/C/+. It contains, a C file, a lutin file that
is called in the C file, and a Makefile that illustrates the
different compilers and options that should be used to generate a
......
......@@ -37,6 +37,8 @@ endif
test-lutin:
cd lutin/up_and_down && make test;
cd lutin/xlurette && make test;
cd lutin/C && make test;
cd lutin/ocaml && make test
test: test-lucky test-lutin
......
CC = gcc -g
LINKER= gcc -g
EXE=
CFLAGS = \
-L../../../lib \
-I../../../include
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl -lstdc++
LUC2C=../../../$(HOSTTYPE)/bin/luc2c
ifeq ($(HOSTTYPE),mac)
LINKER=g++ -g
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl
endif
ifeq ($(HOSTTYPE),win32)
EXE=.exe
CFLAGS = \
-L../../../lib \
-I../../../include \
-Winline -Wimplicit-function-declaration
LIBS = -lluc4c_nc -llucky_nc -lgmp -lws2_32 -lm -lstdc++ -mno-cygwin -lole32
LUC2C=../../../$(HOSTTYPE)/bin/luc2c$(EXE)
endif
ifeq ($(HOSTTYPE),cygwin)
EXE=.exe
CFLAGS = \
-L../../../lib \
-I../../../include \
-Winline -Wimplicit-function-declaration
LIBS = -lluc4c_nc -llucky_nc -lgmp -lws2_32 -lm -lstdc++
LUC2C=../../../$(HOSTTYPE)/bin/luc2c$(EXE)
endif
################################################################
# Calling lucky from C
foo.c: foo.lut
$(LUC2C) foo.lut
foo.o : foo.c
$(CC) -c $(CFLAGS) foo.c
call_foo.o: call_foo.c
$(CC) -c $(CFLAGS) call_foo.c
foo$(EXE): foo.o call_foo.o
$(LINKER) $(CFLAGS) -o $@ $^ $(LIBS)
################################################################
clean:
rm -f run *.o *~ foo foo.h foo.c *.gp *.plot *.rif
test : clean foo$(EXE)
ifeq ($(HOSTTYPE),win32)
foo$(EXE)
else
./foo > test.rif
rm -f test.res && diff -u -i test.rif.exp test.rif > test.res
[ ! -s test.res ] && make clean
endif
utest:
cp test.rif test.rif.exp
#include <stdlib.h>
#include <stdio.h>
#include "foo.h"
// Output procedures
void foo_O_x(foo_ctx* ctx, int v) { ctx->_x = v; };
void foo_O_y(foo_ctx* ctx, int v) { ctx->_y = v; };
void foo_O_z(foo_ctx* ctx, double v) { ctx->_z = v; };
// a little main that calls the foo.lut program
int main(){
int i = 0;
foo_ctx* ctx;
ctx = foo_new_ctx(NULL);
lucky_set_seed(1);
// setting inputs
foo_I_a(ctx, 10);
foo_I_b(ctx, 0);
foo_I_c(ctx, 20.0);
printf("#inputs \"a\":int \"b\":bool \"c\":real\n");
printf("#outputs \"x\":int \"y\":bool \"z\":real\n");
for (i=0; i<10; i++){
foo_step(ctx, step_inside);
printf("# step %d \n%d %d %f #outs %d %d %f\n",
i, ctx->_a, ctx->_b, ctx->_c, ctx->_x, ctx->_y, ctx->_z);
}
return 0;
}
let abs_int(x: int) = if x>=0 then x else -x
let abs_real(x: real) = if x>=0.0 then x else -x
node main(a:int; b:bool; c:real) returns ( x:int; y:bool; z:real) =
loop
{
(b=>y) and abs_int(x - a) < 5 and abs_real(z - c) < 5.0
}
# Interpreting the lutin file foo.lut with node main
#inputs "a":int "b":bool "c":real
#outputs "x":int "y":bool "z":real
# step 0
10 0 20.000000 #outs 6 0 16.278233
# step 1
10 0 20.000000 #outs 6 1 21.603283
# step 2
10 0 20.000000 #outs 9 1 17.399245
# step 3
10 0 20.000000 #outs 13 1 19.172617
# step 4
10 0 20.000000 #outs 11 0 19.251183
# step 5
10 0 20.000000 #outs 8 1 15.253516
# step 6
10 0 20.000000 #outs 7 0 21.425417
# step 7
10 0 20.000000 #outs 9 1 17.336461
# step 8
10 0 20.000000 #outs 7 0 19.618259
# step 9
10 0 20.000000 #outs 14 0 16.016641
xxx:
rm toto.rif; lucky -l 2000 -pp lucky_cpp rabbit-speed.luc | grep outs | cut -d ' ' -f 2 | lucky rabbit-dir.luc > toto.rif
v:
rm -f toto2.rif ;sed -e 's/#inputs \"Speed\":real/#inputs/' toto.rif > toto2.rif
gnuplot-rif -x11 toto2.rif
cat toto2.gp | cut -d ' ' -f 3-15 | grep -v End_of_file | grep -v Lucky | grep -v steps > zz.gp
gnuplot zz.plot
MAIN=rabbit
CMXA_LIB = unix.cmxa str.cmxa bdd.cmxa polka.cmxa luc4ocaml.cmxa
CMA_LIB=luc4ocaml.cma
LUC4OCAML_INSTALL_DIR = -I ../../$(HOSTTYPE)/lib
LUC4OCAML_INSTALL_DIR = -I ../../../$(HOSTTYPE)/lib
# LUC4OCAML_INSTALL_DIR = -I +lucky
ifeq ($(HOSTTYPE),win32)
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),cygwin)
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),mac)
LD_ARCH=-DMAC
endif
$(MAIN).opt:$(MAIN).ml
ocamlopt.opt $(LUC4OCAML_INSTALL_DIR) graphics.cmxa $(CMXA_LIB) $(MAIN).ml -o $(MAIN).opt
ocamlopt.opt -cc g++ -cclib -lgmp $(LUC4OCAML_INSTALL_DIR) graphics.cmxa $(CMXA_LIB) $(MAIN).ml -o $(MAIN).opt
$(MAIN):$(MAIN).ml
ocamlopt.opt $(LUC4OCAML_INSTALL_DIR) graphics.cma $(CMA_LIB) $(MAIN).ml -o $(MAIN)
ocamlc.opt $(LUC4OCAML_INSTALL_DIR) graphics.cma $(CMA_LIB) $(MAIN).ml -o $(MAIN)
demo: $(MAIN).opt
......@@ -36,21 +38,9 @@ clean:
%_lut.luc: crazy_rabbit.lut
lutin -o $@ $< -main $*
lut: moving-obstacle3.lut
lutin -o moving-obstacle3-lut.luc moving-obstacle3.lut -main moving_obstacle
lutin -o rabbit-speed-lut.luc rabbit-speed.lut -main
louis:
lutin -o louis.luc crazy_rabbit.lut -main louis
test: $(MAIN)
./$(MAIN).opt | grep -v "The random engine is initialized with the seed" > $(MAIN).out && \
rm -f test.res && diff -u -i $(MAIN).out.exp $(MAIN).out \
> test.res
test: clean $(MAIN).opt
./$(MAIN).opt 1000 0.0 test | grep -v "The random engine is initialized with the seed"
rm -f test.res && diff -u -i $(MAIN).out.exp $(MAIN).out > test.res && \
[ ! -s test.res ] && make clean
utest:
......
(*
Demonstrate the use of Lucky from Ocaml.
Demonstrate the use of Lutin from Ocaml.
This is the demo that comes with the presention contained in synchron2005.pdf
Confere the Makefile for building and use.
*)
......@@ -164,8 +162,8 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir-line.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-line.lut"])
i
"0.0";
ignore (Graphics.read_key ())
......@@ -179,8 +177,8 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir-line.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-line.lut"])
i
delay;
ignore (Graphics.read_key ())
......@@ -194,8 +192,8 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir.lut"])
i
"0.0";
ignore (Graphics.read_key ())
......@@ -209,9 +207,9 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop_obstacle
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed_lut.luc"])
(Luc4ocaml.make ["rabbit-dir-obstacle_lut.luc"])
(Luc4ocaml.make ["obstacle.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-obstacle.lut"])
(Luc4ocaml.make ["obstacle.lut"])
i
"0.0";
ignore (Graphics.read_key ())
......@@ -225,9 +223,9 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop_obstacle
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir-obstacle.luc"])
(Luc4ocaml.make ~pp:"lucky_cpp" ["moving-obstacle.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-obstacle.lut"])
(Luc4ocaml.make ["moving-obstacle.lut"])
(i*10)
"0.0";
ignore (Graphics.read_key ())
......@@ -241,9 +239,9 @@ let launch_demo () =
if (Graphics.read_key ()) = 'g' then
(
main_loop_obstacle
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir-obstacle.luc"])
(Luc4ocaml.make ~pp:"lucky_cpp" ["moving-obstacle2.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-obstacle.lut"])
(Luc4ocaml.make ["moving-obstacle2.lut"])
(i*10)
"0.0";
ignore (Graphics.read_key ())
......@@ -258,9 +256,9 @@ let _ =
Graphics.moveto 100 100;
ignore (Graphics.read_key ());
main_loop_obstacle
(Luc4ocaml.make ~pp:"lucky_cpp" ["rabbit-speed.luc"])
(Luc4ocaml.make ["rabbit-dir-obstacle.luc"])
(Luc4ocaml.make ~pp:"lucky_cpp" ["moving-obstacle3-lut.luc"])
(Luc4ocaml.make ["rabbit-speed.lut"])
(Luc4ocaml.make ["rabbit-dir-obstacle.lut"])
(Luc4ocaml.make ["moving-obstacle3.lut::moving_obstacle3"])
(int_of_string Sys.argv.(1))
Sys.argv.(2);
ignore (Graphics.read_key ())
......
......@@ -11,6 +11,7 @@ let up_and_downR(x, px : real ref; min, max, delta : real) =
node mainR () returns (x : real) =
exist px : real in
......
CMXA_LIB = unix.cmxa str.cmxa bdd.cmxa polka.cmxa luc4ocaml.cmxa
CMA_LIB=luc4ocaml.cma
LUC4OCAML_INSTALL_DIR = -I ../../../$(HOSTTYPE)/lib
# LUC4OCAML_INSTALL_DIR = -I +lucky
ifeq ($(HOSTTYPE),win32)
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),cygwin)
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),mac)
LD_ARCH=-DMAC
endif
################################################################
MAIN=call_foo
$(MAIN).opt:$(MAIN).ml
ocamlopt.opt -cc g++ -cclib -lgmp $(LUC4OCAML_INSTALL_DIR) $(CMXA_LIB) $(MAIN).ml -o $(MAIN).opt
$(MAIN):$(MAIN).ml
ocamlc.opt $(LUC4OCAML_INSTALL_DIR) graphics.cma $(CMA_LIB) $(MAIN).ml -o $(MAIN)
################################################################
clean:
rm -f *.top *.cmi *.cmo *.cmx *.o *.cma *.cmxa *.a *.cmi *.cmo *.cmi *.cmx *.o *~ $(MAIN) $(MAIN).opt *~ *.pp_luc *.rif test.res
test: clean $(MAIN).opt
./$(MAIN).opt
rm -f test.res && diff -u -i $(MAIN).rif.exp $(MAIN).rif > test.res && \
[ ! -s test.res ] && make clean
utest:
cp $(MAIN).rif $(MAIN).rif.exp
(* Demonstrate the use of Lutin from Ocaml. *)
open Luc4ocaml
let oc = open_out "call_foo.rif"
(* node main(a:int; b:bool; c:real) returns ( x:int; y:bool; z:real) = *)
let rec main_loop foo_state (a, b, c) cpt =
let foo_inputs = ["a",I a ; "b", B b; "c", F c] in
let (foo_state, (foo_outputs, _)) = Luc4ocaml.step foo_state foo_inputs in
let I x = List.assoc "x" foo_outputs
and B y = List.assoc "y" foo_outputs
and F z = List.assoc "z" foo_outputs
in
if cpt = 0 then () else (
rif_write oc foo_state foo_inputs foo_outputs;
main_loop foo_state (x, not y, z) (cpt-1)
)
let _ =
let foo_state = Luc4ocaml.make ~seed:1 ["foo.lut::main"] in
rif_write_interface oc foo_state false;
main_loop foo_state (0, true, 0.0) 100
#inputs "a":int "b":bool "c":real
#outputs "x":int "y":bool "z":real
#step 1
0 T 0.00 #outs 0 T 1.27
#step 2
0 F 1.27 #outs -4 T 2.87
#step 3
-4 F 2.87 #outs -5 T 0.27
#step 4
-5 F 0.27 #outs -2 T -0.55
#step 5
-2 F -0.55 #outs -1 F -1.30
#step 6
-1 T -1.30 #outs -3 T -6.05
#step 7
-3 F -6.05 #outs -6 F -4.62
#step 8
-6 T -4.62 #outs -2 T -7.29
#step 9
-2 F -7.29 #outs -5 F -7.67
#step 10
-5 T -7.67 #outs -1 T -11.65
#step 11
-1 F -11.65 #outs -1 F -7.22
#step 12
-1 T -7.22 #outs -2 T -5.87
#step 13
-2 F -5.87 #outs -6 F -2.90
#step 14
-6 T -2.90 #outs -8 T -7.09
#step 15
-8 F -7.09 #outs -12 T -3.44
#step 16
-12 F -3.44 #outs -11 F 0.14
#step 17
-11 T 0.14 #outs -11 T 4.01
#step 18
-11 F 4.01 #outs -15 T 6.24
#step 19
-15 F 6.24 #outs -19 F 10.55
#step 20
-19 T 10.55 #outs -15 T 11.19
#step 21
-15 F 11.19 #outs -16 F 9.95
#step 22
-16 T 9.95 #outs -18 T 7.19
#step 23
-18 F 7.19 #outs -19 T 4.33
#step 24
-19 F 4.33 #outs -20 T 6.30
#step 25
-20 F 6.30 #outs -16 T 2.88
#step 26
-16 F 2.88 #outs -15 F 5.04
#step 27
-15 T 5.04 #outs -15 T 7.31
#step 28
-15 F 7.31 #outs -16 F 3.14
#step 29
-16 T 3.14 #outs -20 T 0.48
#step 30
-20 F 0.48 #outs -19 F -0.09
#step 31
-19 T -0.09 #outs -21 T 4.59
#step 32
-21 F 4.59 #outs -20 T 5.88
#step 33
-20 F 5.88 #outs -20 F 8.11
#step 34
-20 T 8.11 #outs -19 T 11.00
#step 35
-19 F 11.00 #outs -18 T 7.29
#step 36
-18 F 7.29 #outs -22 F 3.31
#step 37
-22 T 3.31 #outs -23 T 8.27
#step 38
-23 F 8.27 #outs -27 F 7.32
#step 39
-27 T 7.32 #outs -31 T 9.99
#step 40
-31 F 9.99 #outs -28 T 14.79
#step 41
-28 F 14.79 #outs -29 T 18.49
#step 42
-29 F 18.49 #outs -32 F 13.89
#step 43
-32 T 13.89 #outs -33 T 18.40
#step 44
-33 F 18.40 #outs -33 F 19.28
#step 45
-33 T 19.28 #outs -33 T 22.28
#step 46
-33 F 22.28 #outs -30 T 25.10
#step 47
-30 F 25.10 #outs -28 F 26.73
#step 48
-28 T 26.73 #outs -29 T 26.75
#step 49
-29 F 26.75 #outs -30 T 22.08
#step 50
-30 F 22.08 #outs -29 F 24.34
#step 51
-29 T 24.34 #outs -26 T 22.27
#step 52
-26 F 22.27 #outs -30 F 23.27
#step 53
-30 T 23.27 #outs -34 T 25.21
#step 54
-34 F 25.21 #outs -30 F 27.14
#step 55
-30 T 27.14 #outs -33 T 29.39
#step 56
-33 F 29.39 #outs -30 T 24.58
#step 57
-30 F 24.58 #outs -29 F 26.22
#step 58
-29 T 26.22 #outs -29 T 26.73
#step 59
-29 F 26.73 #outs -31 T 22.00
#step 60
-31 F 22.00 #outs -35 T 22.73
#step 61
-35 F 22.73 #outs -32 F 27.24
#step 62
-32 T 27.24 #outs -29 T 31.10
#step 63
-29 F 31.10 #outs -30 F 28.86
#step 64
-30 T 28.86 #outs -31 T 23.98
#step 65
-31 F 23.98 #outs -32 T 27.40
#step 66
-32 F 27.40 #outs -36 F 27.87
#step 67
-36 T 27.87 #outs -36 T 31.65
#step 68
-36 F 31.65 #outs -40 F 34.81
#step 69
-40 T 34.81 #outs -43 T 31.99
#step 70
-43 F 31.99 #outs -40 F 29.09
#step 71
-40 T 29.09 #outs -42 T 30.44
#step 72
-42 F 30.44 #outs -46 F 25.59
#step 73
-46 T 25.59 #outs -50 T 28.74
#step 74
-50 F 28.74 #outs -49 F 30.13
#step 75
-49 T 30.13 #outs -51 T 25.89
#step 76
-51 F 25.89 #outs -49 F 26.71
#step 77
-49 T 26.71 #outs -49 T 24.85
#step 78
-49 F 24.85 #outs -52 F 21.42
#step 79
-52 T 21.42 #outs -56 T 22.05
#step 80
-56 F 22.05 #outs -59 F 26.56
#step 81
-59 T 26.56 #outs -56 T 26.94
#step 82
-56 F 26.94 #outs -54 T 31.18
#step 83
-54 F 31.18 #outs -54 T 35.55
#step 84
-54 F 35.55 #outs -55 F 34.23
#step 85
-55 T 34.23 #outs -58 T 33.14
#step 86
-58 F 33.14 #outs -58 F 29.72
#step 87
-58 T 29.72 #outs -60 T 30.48
#step 88
-60 F 30.48 #outs -58 T 26.51
#step 89
-58 F 26.51 #outs -57 T 25.39
#step 90
-57 F 25.39 #outs -57 F 26.90
#step 91
-57 T 26.90 #outs -55 T 22.86
#step 92
-55 F 22.86 #outs -59 F 21.60
#step 93
-59 T 21.60 #outs -61 T 26.38
#step 94
-61 F 26.38 #outs -57 F 28.28
#step 95
-57 T 28.28 #outs -60 T 26.62
#step 96
-60 F 26.62 #outs -62 T 29.70
#step 97
-62 F 29.70 #outs -63 T 31.80
#step 98
-63 F 31.80 #outs -60 T 31.89
#step 99
-60 F 31.89 #outs -64 T 32.38
#step 100
-64 F 32.38 #outs -68 T 30.22
let abs_int(x: int) =
if x>=0 then x else -x
let abs_real(x: real) =
if x>=0.0 then x else -x
node main(a:int; b:bool; c:real) returns ( x:int [-100000; 100000]; y:bool; z:real [-100000.0;100000.0]) =
loop
{
(b=>y) and abs_int(x - a) < 5 and abs_real(z - c) < 5.0
}
......@@ -116,6 +116,12 @@ let (