Commit 72e31b8a authored by erwan's avatar erwan

Chore: untrack very old stuff

parent 8671d38c
CC = gcc -g
LINKER= gcc -g
EXE=
CFLAGS = \
-L../../../lib \
-I../../../include
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl -lstdc++
LUC2C=../../../bin/luc2c
ifeq ($(HOSTTYPE),mac)
LINKER=g++ -g
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl
endif
ifeq ($(HOSTTYPE),cross-win32)
EXE=
CFLAGS = \
-L../../../lib \
-I../../../include \
-Winline -Wimplicit-function-declaration
LIBS = -lluc4c_nc -llucky_nc -lgmp -lws2_32 -lm -lstdc++ -lole32
LUC2C=../../../bin/luc2c$(EXE)
LINKER=i586-mingw32msvc-gcc
CC= i586-mingw32msvc-cc
endif
ifeq ($(HOSTTYPE),cross-win32)
EXE=
CFLAGS = \
-L../../../lib \
-I../../../include \
-Winline -Wimplicit-function-declaration
LIBS = -lluc4c_nc -llucky_nc -lgmp -lws2_32 -lm -lstdc++ -mno-cygwin -lole32
LUC2C=../../../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=../../../bin/luc2c$(EXE)
endif
################################################################
# Calling lucky from C
foo.c: foo.luc
$(LUC2C) foo.luc
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.luc 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 \n#outs %d %d %f\n",
i, ctx->_a, ctx->_b, ctx->_c, ctx->_x, ctx->_y, ctx->_z);
}
return 0;
}
--
inputs { a:int; b:bool; c:float }
outputs { x:int; y:bool; z:float }
states { 0:stable }
start_state { 0 }
transitions { 0 -> 0 ~cond
b=>y and abs(x - a) < 5 and abs(z - c) < 5.0 }
#-----------------------------------------------------
# Dynamic linking of C code with Lucky
#
#-----------------------------------------------------
# Directories
SRCDIR=.
OBJDIR=./obj
MAIN=foo
#settings for Linux (and other posix systems ?)
DLEXT=so
EXE=
CC=gcc
MKDLLFLAGS=
LFLAGS=
SOFLAGS=-shared
#settings for WIN32
ifeq ($(HOSTTYPE),win32)
DLEXT=dll
EXE=.exe
CC=$(GCC)
MKDLLFLAGS=-Wl,--out-implib,$(OBJDIR)/$(MAIN).a
LFLAGS=-lm
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),cygwin)
DLEXT=dll
EXE=.exe
LD=gcc -DWIN32
CC=gcc -DWIN32
MKDLLFLAGS=-Wl,--out-implib,$(OBJDIR)/$(MAIN).a
LFLAGS=-lm
LD_ARCH=-DWIN32
endif
ifeq ($(HOSTTYPE),mac)
LD=g++
CC=gcc
SOFLAGS = -dynamiclib
LD_ARCH=-DMAC
endif
all: $(OBJDIR)/$(MAIN).$(DLEXT)
$(OBJDIR):
mkdir $(OBJDIR)
$(OBJDIR)/$(MAIN).$(DLEXT) : $(OBJDIR)/$(MAIN).o
$(LD) $(LFLAGS) $(SOFLAGS) -o $(OBJDIR)/$(MAIN).$(DLEXT) \
$(OBJDIR)/$(MAIN).o \
$(MKDLLFLAGS)
$(OBJDIR)/%.o : $(OBJDIR) $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $(SRCDIR)/$*.c -o $(OBJDIR)/$*.o
call_external_c_code.luc_pp:call_external_c_code.luc
../../../bin/lucky_cpp call_external_c_code.luc call_external_c_code.luc_pp $(LD_ARCH)
EXPDIR=`../../../bin/lutin$(EXE) --ocaml-version`
$(EXPDIR):
[ -d $(EXPDIR) ] || mkdir -p $(EXPDIR) ; make utest
test: clean $(OBJDIR)/$(MAIN).$(DLEXT) call_external_c_code.luc_pp $(EXPDIR)
rm -f test.rif0 && \
../../../bin/lucky$(EXE) -l 10 $(OPT) -seed 834966010 \
call_external_c_code.luc_pp | sed -e "s/^M//" | grep -v " Lucky Version" > test.rif
rm -f test.res && diff -u -i $(EXPDIR)/test.rif.exp test.rif > test.res
[ ! -s test.res ] && make clean
utest:
cp test.rif $(EXPDIR)/test.rif.exp
clean:
rm -rf $(OBJDIR) *.rif *.rif0 call_external_c_code.luc_pp
--
-- A simple Lucky program calling a function "bar" defined in "foo.so"
--
libraries {
#ifdef MAC
foo_lib = "./obj/foo.so";
math_lib = "libm.dylib" -- the standard C math lib (which path ougth to be in LD_LIBRARY_PATH)
#else
#ifdef WIN32
foo_lib = "./obj/foo.dll";
math_lib = "libm.dll"
#else
foo_lib = "./obj/foo.so";
math_lib = "libm.so"
#endif
#endif
}
functions {
sqrt : float -> float : math_lib;
sin : float -> float : math_lib;
rand_up_to : int * int -> int : foo_lib;
}
outputs {
f1 : float ~init 1.0;
f2 : float;
i : int;
}
nodes {0: stable }
start_node { 0 }
transitions {
0 -> 0 ~cond
0.0 < f1 and f1 < 100.0
and f2 = sin(sqrt(pre f1))
and i = rand_up_to(0,10)
}
-- "lucky -l 10 call_external_c_code.luc" generates outputs such as:
--
-- #The random engine was initialized with the seed 3064352
-- #inputs
-- #outputs "f1":real "f2":real "i":int
-- #step 1
--
-- #outs 51.62 0.84 9
-- #step 2
--
-- #outs 64.93 0.78 4
-- #step 3
--
-- #outs 27.27 0.98 8
-- #step 4
--
-- #outs 22.90 -0.87 8
-- #step 5
--
-- #outs 82.37 -1.00 10
-- #step 6
--
-- #outs 51.41 0.34 2
-- #step 7
--
-- #outs 61.45 0.78 3
-- #step 8
--
-- #outs 18.72 1.00 8
-- #step 9
--
-- #outs 93.14 -0.93 3
-- #step 10
--
-- #outs 31.45 -0.22 6
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
EXPORT int rand_up_to(int min, int max){
// uniformly draws an integer between O and max.
// Not the most useful function for Lucky...
double r = ((double) random ());
int res = min + ((int) ((r * (((double) (max-min+1)) / ((double) RAND_MAX)))));
return res;
}
EXPORT double msin(double x){
double res = sin(x);
return res;
};
EXPORT double msqrt(double x) {
double res = sqrt(x);
return res ;
};
-include Makefile.foo
export LURETTE_PATH=../../..
go:
../../../bin/luc2c --luciole foo.luc
test: go
make -f Makefile.foo && make clean
--
inputs {
a:int;
b:bool;
c:float
}
outputs {
x:int;
y:bool;
z:float
}
states { 0:stable }
start_state { 0 }
transitions { 0 -> 0
~cond
b=>y and abs(x - a) < 5
and abs(z - c) < 5.0
}
CC = gcc -g
LD = gcc -g
EXE=
CFLAGS = \
-L../../../lib \
-I../../../include
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl -lstdc++
LUC2C=../../../bin/luc2c
ifeq ($(HOSTTYPE),win32)
EXE=.exe
CFLAGS = \
-L../../../lib -L/cygdrive/c/TEMP/MinGW/lib \
-I../../../include \
-Winline -Wimplicit-function-declaration
LIBS = -lluc4c_nc -llucky_nc -lgmp -lws2_32 -lm -lstdc++
LUC2C=../../../bin/luc2c$(EXE)
endif
ifeq ($(HOSTTYPE),mac)
LD = g++ -g
LIBS = -lluc4c_nc -llucky_nc -lgmp -lm -ldl
endif
################################################################
# Calling lucky from Lustre
# SOURCE_FILES = call_foo.lus foo.luc
foo.c: foo.luc
$(LUC2C) --lustre "call_foo" --seed 42 foo.luc
foo.o : foo.c
$(CC) -c $(CFLAGS) foo.c
call_foo.ec:
lus2ec call_foo.lus call_foo
call_foo.c: call_foo.ec
ec2c -loop call_foo.ec
call_foo.o: call_foo.c
$(CC) -c $(CFLAGS) call_foo.c
call_foo_loop.o: call_foo_loop.c
$(CC) -c $(CFLAGS) call_foo_loop.c
call_foo_ext_func.o: call_foo_ext_func.c
$(CC) -c $(CFLAGS) call_foo_ext_func.c
foo: foo.o call_foo.o call_foo_ext_func.o call_foo_loop.o
$(LD) $(CFLAGS) -o $@ $^ $(LIBS)
################################################################
clean:
rm -f run *.o *~ call_foo_ext* call_foo.c call_foo.h call_foo_loop.c call_foo_loop.h foo.h foo.c *.gp *.plot *.rif *.ec foo$(EXE) #*
test : clean foo
ifeq ($(HOSTTYPE),win32)
foo$(EXE)
else
touch test.rif ; rm test.rif
echo "1 1 1 1 1 1 1 1 1 1 1" | ./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
-- Time-stamp: <modified the 07/12/2006 (at 16:06) by Erwan Jahier>
function foo ( x:int; y:bool; z:real )
returns( a:int; b:bool; c:real );
node call_foo (dummy : int )
returns( a:int; b:bool; c:real );
let
a, b, c = foo(1 -> pre a, true -> pre b, 10.0 -> pre c);
tel;
--
inputs { a:int; b:bool; c:float }
outputs { x:int; y:bool; z:float }
states { 0:stable }
start_state { 0 }
transitions { 0 -> 0
~cond b=>y and abs(x - a) < 5 and abs(z - c) < 5.0 }
EXE=
ifeq ($(HOSTTYPE),win32)
EXE=.exe
endif
LUCKY=../../../bin/lucky$(EXE) -seed 1
test1 :
$(LUCKY) -l 1000 \
losange-3d2.luc | sed -e "s/^M//" | grep -v " Lucky Version" > test1.rif
rm -f test1.res && diff -u -i test1.rif.exp test1.rif > test1.res
[ ! -s test1.res ] && make clean
test2:
rm -f test2.rif0 && \
$(LUCKY) \
infinite_weight.luc | sed -e "s/^M//" | grep -v " Lucky Version" > test2.rif
rm -f test2.res && diff -u -i test2.rif.exp test2.rif > test2.res
[ ! -s test2.res ] && make clean
test3 :
rm -f test3.rif0 && \
$(LUCKY) -l 20 \
dynamic_weight.luc | sed -e "s/^M//" | grep -v " Lucky Version" > test3.rif
rm -f test3.res && diff -u -i test3.rif.exp test3.rif > test3.res
[ ! -s test3.res ] && make clean
test4 :
rm -f test4.rif0 && \
$(LUCKY) -l 10 \
structured_type.luc | sed -e "s/^M//" | grep -v " Lucky Version" > test4.rif
rm -f test4.res && diff -u -i test4.rif.exp test4.rif > test4.res
[ ! -s test4.res ] && make clean
test5 :
rm -f test5.rif0 && \
$(LUCKY) -l 10 \
bj.luc | sed -e "s/^M//" | grep -v " Lucky Version" > test5.rif
rm -f test5.res && diff -u -i test5.rif$(EXP) test5.rif > test5.res
[ ! -s test5.res ] && make clean
test : test1 test2 test3 test4 test5
utest1:
cp test1.rif test1.rif.exp
utest2:
cp test2.rif test2.rif.exp
utest3:
cp test3.rif test3.rif.exp
utest4:
cp test4.rif test4.rif.exp