Commit 98380cec authored by Erwan Jahier's avatar Erwan Jahier

lurette 1.41 Mon, 26 Sep 2005 13:51:19 +0200 by jahier

Parent-Version:      1.40
Version-Log:

source/luc_exe.ml
source/lurette.ml
source/util.ml
source/formula_to_bdd.ml
source/bddd.ml
source/solver.ml
source/store.ml
source/parse_luc.mli
source/parse_luc.ml
source/env_state.mli
source/env_state.ml
source/run_aut.ml
source/gne.mli
source/gne.ml
source/lurettetop.ml
source/gen_stubs_poc.ml
source/ne.ml
source/ne.mli
share/lucky.el
share/configure.in
Makefile.common.source
OcamlMakefile
user-rules
source/Makefile.show_luc
source/Makefile.lucky
source/Makefile.gen_stubs
source/Makefile.lurette_lib
source/Makefile
test/time-joly.res
test/temp_int.luc
ihm/xlurette/xlurette.glade
ihm/xlurette/makefile
source/Makefile.gen_fake_lucky
source/lustreExp.ml
source/lustreExp.mli
source/exp.ml
source/exp.mli
source/parser.mly
doc/lucky-man/lucky-man.tex
source/gnuplot-socket.ml
source/gnuplot-rif.ml
source/luckyDraw.mli
source/luckyDraw.ml
source/essai-maitre.ml
source/essai-esclave.ml
source/Makefile.ocaml
source/Makefile.luckyDraw

Add the possibility to call external code via dyn lib.

The generation of default lucky files from Lurette was broken.

Fix warning generated by gcc4.

Fix a bug where variables with default values were generated twice
(bug only visible in assert mode ; in the other mode, one of the value
was taken, but I am not sure which one...)

Project-Description: Lurette
parent b1a40b56
This diff is collapsed.
......@@ -10,7 +10,6 @@
ifeq ($(HOST_TYPE),cygwin)
EXE :=
OCAMLLIB = "c:\TEMP\ocaml\lib"
INCDIRS = u:\\cygwin\\lib c:\\TEMP\\ocaml\\lib
LIBDIRS = u:\\cygwin\\lib c:\\TEMP\\ocaml\\lib c:\\cygwin\\lib\\mingw
......@@ -19,12 +18,12 @@ ifeq ($(HOST_TYPE),cygwin)
SYNCHRONE_LURETTE_DIR=//ARPONT/www-verimag/SYNCHRONE/lurette/
EXE := .exe
HOSTTYPE32=win32
DWIN32 = -DWIN32
else
ifeq ($(HOST_TYPE),sparc-sun)
EXE :=
INCDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
LIBDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
INCDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib /usr/local/soft/ocaml/3.08/lib/ocaml
LIBDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib /usr/local/soft/ocaml/3.08/lib/ocaml
OCAMLLIB = /usr/local/soft/ocaml/3.08/lib/ocaml
CAML_INSTALL_DIR=/usr/local/soft/ocaml/3.08/
......@@ -32,10 +31,11 @@ ifeq ($(HOST_TYPE),sparc-sun)
SYNCHRONE_LURETTE_DIR=/usr/local/www/SYNCHRONE/lurette/
EXE := #
HOSTTYPE32=$(HOST_TYPE)
DWIN32 =
else
EXE :=
INCDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
LIBDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
INCDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
LIBDIRS = $(HOME)/$(HOSTTYPE)/lib $(SCADE_INSTALL_DIR)/lib
OCAMLLIB = /usr/local/soft/ocaml/3.08.3/lib/ocaml
CAML_INSTALL_DIR=/import/linux/soft/ocaml/3.08.3/
......@@ -43,6 +43,7 @@ else
SYNCHRONE_LURETTE_DIR=/usr/local/www/SYNCHRONE/lurette/
EXE := #
HOSTTYPE32=$(HOST_TYPE)
DWIN32 =
endif
endif
......
......@@ -5,14 +5,14 @@
# For updates see:
# http://www.oefai.at/~markus/ocaml_sources
#
# $Id: OcamlMakefile 1.53 Fri, 22 Jul 2005 17:06:41 +0200 jahier $
# $Id: OcamlMakefile 1.54 Mon, 26 Sep 2005 13:51:19 +0200 jahier $
#
###########################################################################
# Set these variables to the names of the sources to be processed and
# the result variable. Order matters during linkage!
-include $(LURETTE_PATH)/Makefile.common.source
-include ./Makefile.common.source
......@@ -34,7 +34,7 @@ endif
export RESULT
ifndef DOC_FILES
DOC_FILES := $(filter %.mli, $(ALL_SOURCES))
DOC_FILES := $(filter %.mli, $(SOURCES))
endif
export DOC_FILES
......@@ -733,14 +733,14 @@ endif
$(QUIET)pp=`sed -n -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
if [ -z "$$pp" ]; then \
echo $(INTF_OCAMLC) -c $(THREAD_FLAG) \
$(OCAMLFLAGS) $(INCFLAGS) "$<"; \
$(OCAMLFLAGS) $(INCFLAGS) $<; \
$(INTF_OCAMLC) -c $(THREAD_FLAG) $(OCAMLFLAGS) \
$(INCFLAGS) "$<"; \
$(INCFLAGS) $<; \
else \
echo $(INTF_OCAMLC) -c -pp \"$$pp\" $(THREAD_FLAG) \
$(OCAMLFLAGS) $(INCFLAGS) "$<"; \
$(OCAMLFLAGS) $(INCFLAGS) $<; \
$(INTF_OCAMLC) -c -pp "$$pp" $(THREAD_FLAG) \
$(OCAMLFLAGS) $(INCFLAGS) "$<"; \
$(OCAMLFLAGS) $(INCFLAGS) $<; \
fi
.ml.cmi .ml.$(EXT_OBJ) .ml.cmx .ml.cmo: $(EXTRADEPS)
......
V1.41
* Add External function call from Lucky.
* The generation of default lucky files from Lurette was broken.
* In some cases (for polyhedron of dim greater that 2 for integers), false
solutions were generated. Now, we double check that the drawn solution
is valid. If not, a few other tries are performed. Il all fails, we
claim that there is no solution, altough is migth not be true. But
this is safer than returning wrong solutions. This the price to pay
for not having a native integer solver (which may be added in future).
* Fix warnings generated by gcc4
V1.40
* Add a reactive mode where the output of the previous cycle is returned
when the Lucky environment is blocked (because no transition from
the current node(s) is labelled by a satisfiable constraint.
* Add a reactive mode where the output of the previous cycle is
returned when the Lucky environment is blocked (because no
transition from the current node(s) is labelled by a satisfiable
constraint.
* First version of the integration in the Scade editor
......
......@@ -45,6 +45,12 @@ Bien sur, il manipule 10000 variables au lieu de 1000, mais tout de m
*********** A faire
* pour les declarations de fonctions externes, il faudrait plutot utiliser
t1 * t2 -> t3 plitot que t1 -> t2 -> t3, comme le dis la doc d'ailleurs...
* Ajouter une option -int32 qui utilise des Int32 pour éviter des soucis
avec des entiers trop grands.
* precision ne devrait pas vouloir dire "nombre de chiffres apres le virgule"
mais "nombre de chiffres significatifs". Ca me permettrait de plus d'implementer
un Polyhedron.rat_of_float qui soit moint délirant, ainsi que de donner
......
VERSION_DATE=22-07-05
VERSION=V2-1.40
export VERSION
export VERSION_DATE
#-----------------------------------------------------
# Dynamic linking of C code with Lucky
#
#-----------------------------------------------------
# Directories
SRCDIR=.
OBJDIR=./$(HOSTTYPE)
MAIN=foo
#settings for Linux (and other posix systems ?)
DLEXT=so
EXE=
LD=gcc
CC=gcc
MKDLLFLAGS=
LFLAGS=-ldl
#settings for WIN32
ifeq ($(HOSTTYPE),win32)
DLEXT=dll
EXE=.exe
LD=gcc -DWIN32
CC=gcc -DWIN32
MKDLLFLAGS=-Wl,--out-implib,$(OBJDIR)/$(MAIN).a
LFLAGS=
endif
all: $(OBJDIR)/$(MAIN).$(DLEXT)
$(OBJDIR):
mkdir $(OBJDIR)
$(OBJDIR)/$(MAIN).$(DLEXT) : $(OBJDIR)/$(MAIN).o
$(LD) -shared -o $(OBJDIR)/$(MAIN).$(DLEXT) \
$(OBJDIR)/$(MAIN).o \
$(MKDLLFLAGS)
$(OBJDIR)/%.o : $(OBJDIR) $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $(SRCDIR)/$*.c -o $(OBJDIR)/$*.o
test:
lucky -l 10 call_external_c_code.luc
clean:
rm -rf $(OBJDIR)/*
--
-- A simple Lucky program calling a function "bar" defined in "foo.so"
--
libraries {
foo_lib = "../demo-lucky/external_code/i386-linux-gcc3/foo.so";
math_lib = "libm.so" -- the standard C math lib (which path ougth to be in LD_LIBRARY_PATH)
}
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;
}
......@@ -24,7 +24,7 @@
\usepackage{boxedminipage}
\usepackage{amsfonts,amssymb,amsmath}
\usepackage{color,xcolor}
\usepackage{myxcolor}
%\usepackage{ocamldoc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -55,6 +55,8 @@
\W\usepackage{sequential}
\htmlrule
\newcommand{\bug}{{\bf bug}}
\newcommand{\todo}[1]{{\bf todo:} \emph{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -690,6 +692,90 @@ Section~\ref{window-concrete}.
\newpage
\input{lucky-syntax}
%---------------------------------------------------------------------
%---------------------------------------------------------------------
\newpage
\section{Calling external code}
\label{building-dynlib}
In order to use external code from Lucky, we provide a mechanism based
on dynamic libraries.
%
Such dynamic libraries should be built and used according to certain
conventions that we describe in this section.
%
Moreover, the type of imported functions should be declared in the
Lucky file (cf Section~\ref{syntax-dynlib}). And of course, the
declared types should match their definitions in the library. \\
{\bf BEWARE: } if the types you declare in the Lucky file does not
match their definitions, it might run silently returning wrong values!
% The syntax to declare external functions and use them is described
% in Section~\ref{syntax-dynlib} and~\ref{expressions}.
\subsection{Current restrictions}
\begin{itemize}
\item Imported code can only be functions over integers and doubles.
\item At least one and at most five arguments are required.
\item There is an issue with integers as Lucky manipulates integers
coded on 31 bits, not 32 bits. Therefore make sure you use only
integers between -1073741824 and 1073741823. This may be changed in
future versions.
\todo{Add \code{--int32} and \code{--int64} options.}
\end{itemize}
A example is given in the appendix~\ref{dyn_call_ex}. This exemple
(plus the Makefile) is also provided in the distribution in the
\code{demo-lucky/external\_code} directory. \\
\bug: \code{x = f(y) and z=g(x)} is not equivalent to \code{z =
g(f(y))}, because in the former case Lucky raises an error as it
believes that \code{x} is not bound.
\subsection{External code with side-effects}
Currently, external function call does not work very well if such
calls are doing side-effects.
%
For instance, the following code:
\begin{alltt}
if 5 > random_up_to(10) then ... else
if 5 > random_up_to(10) then ... else ...
\end{alltt}
is not equivalent to:
\begin{alltt}
if 5 > random_up_to(10) then ... else
if (4+1) > random_up_to(10) then ... else ...
\end{alltt}
because in the former case, the call to the function \code{rand\_up\_to} is
done once, while it is done twice in the latter case. This (buggy)
behaviour migth be fixed in future versions.
%
% pb 2 : External code with SE and thickness ...
%
% pas vraiment un pb ca en fait.
%--------------------------------------------------------------------
%--------------------------------------------------------------------
......@@ -714,20 +800,19 @@ polyhedra. This means the limitation of 15 dimensions does not lead
to a limitation of 15 variables.
\subsection{Solving integer constraints}
For the sake of efficiency, we do not use classical methods such as
linear logic for solving integer constraints: we solve those
constraints in the domain of rational numbers and then we truncate.
The problem is of course that the result may not be a solution of the
constraints. For example, consider a constraint $0<x<5$ that leads to
the drawn value $0.1$; if we truncate it to $0$, we obtain a wrong
solution.
Even worse, a non-empty polyhedron in the rational domain may have no
solution in the integer domain. We plan to ameliorate this situation
in the near future.
\subsection{Solving integer constraints in dimension $n \geq 2$}
When the dimension is greater than 2, for the sake of efficiency, we
do not use classical methods such as linear logic for solving integer
constraints: we solve those constraints in the domain of rational
numbers and then we truncate. The problem is of course that the
result may not be a solution of the constraints.
In such a case, we chose to pretend that the constraint is
unsatisfiable (after a few more tries according to various heuristics),
which can be wrong, but which is safe in some sense. The rigth solution there would
be to call an integer solver, which is very expensive, and yet to be done.
\todo{implement an {--int-solver} option that make Lucky use an integer solver when the polyhedron-based approach fails}
\subsection{Fairness versus efficiency}
......@@ -927,6 +1012,13 @@ usage: lucky [options]* (<file.luc>)+
\input{structured_type}
\end{alltt}
\newpage
\subsection{Illustration of the use of external function calls}
\label{dyn_call_ex}
\begin{alltt}
\input{call_external_c_code}
\end{alltt}
......
ifndef LURETTE_PATH
LURETTE_PATH := $(HOME)/lurette
endif
-include $(LURETTE_PATH)/Makefile.common.source
......@@ -111,7 +116,7 @@ cp:
ifeq ($(HOST_TYPE),cygwin)
cp xlurette_exe.exe $(HOME)/lurette/cygwin/bin
else
cp xlurette_exe $(BIN_INSTALL_DIR)
cp xlurette_exe $(BIN_INSTALL_DIR)/
endif
clean:
......
......@@ -3640,8 +3640,8 @@ Note that if one of the Draw All Formula (via DF) or Draw All Vertices (via DV)
<lower>666</lower>
<upper>666</upper>
<step>1</step>
<page>10</page>
<page_size>10</page_size>
<page>100</page>
<page_size>100</page_size>
<child>
<padding>0</padding>
<expand>False</expand>
......
This diff is collapsed.
/* $Id: polka_caml.c 1.2 Fri, 19 Dec 2003 15:39:58 +0100 jahier $ */
/* $Id: polka_caml.c 1.3 Mon, 26 Sep 2005 13:51:19 +0200 jahier $ */
#include <stddef.h>
#include <string.h>
......@@ -167,7 +167,7 @@ static void camlidl_polka_poly_finalize(value val)
{
poly_free(*((poly_t **)Data_custom_val(val)));
}
static struct custom_operations camlidl_polka_poly_custom = {
struct custom_operations camlidl_polka_poly_custom = {
"poly_caml_custom_operations",
&camlidl_polka_poly_finalize,
custom_compare_default,
......
......@@ -110,6 +110,12 @@ test12 :
rm -f test12.res; diff -u test12.rif.exp test12.rif > test12.res
test: test1 test2 test3 test5 test6 test7 test8 test9 test10 test11 test12
test14 :
rm -f test14.rif0 && \
../@HOST_TYPE@/bin/lucky -l 10 -seed 834966010 \
../demo-lucky/external_code/call_external_c_code.luc | sed -e "s/^M//" | grep -v "This is Lucky Version" > test14.rif
rm -f test14.res && diff -u -i test14.rif test14.rif > test14.res
test: test1 test2 test3 test5 test6 test7 test8 test9 test10 test11 test12 test14
ls -l *.res
This diff is collapsed.
......@@ -23,9 +23,17 @@ AC_SUBST(LURETTEPATH)
case `./config.guess` in
i*86-pc-linux-*)
case `gcc -dumpversion` in
5.*)
echo "HOST_TYPE=i386-linux-gcc5"
HOST_TYPE=i386-linux-gcc5 ;;
4.*)
ECHO "HOST_TYPE=i386-linux-gcc4"
HOST_TYPE=i386-linux-gcc4 ;;
3.*)
ECHO "HOST_TYPE=i386-linux-gcc3"
HOST_TYPE=i386-linux-gcc3 ;;
*)
ECHO "HOST_TYPE=i386-linux"
HOST_TYPE=i386-linux ;;
esac;;
sparc-sun-solaris2.*) HOST_TYPE=sparc-sun ;;
......@@ -343,6 +351,12 @@ chmod a+x gen_stubs.sh
chmod a+x gen_fake_lutin.sh
chmod a+x gen_fake_lucky.sh
[ test -d $LURETTEPATH/$HOST_TYPE/bin/ ] || mkdir $LURETTEPATH/$HOST_TYPE/bin/
[ test -d $LURETTEPATH/$HOST_TYPE/include/ ] || mkdir $LURETTEPATH/$HOST_TYPE/include/
[ test -d $LURETTEPATH/$HOST_TYPE/lib/ ] || mkdir $LURETTEPATH/$HOST_TYPE/lib/
[ test -d toto ] || mkdir toto
cp $LURETTEPATH/share/Makefile.test $LURETTEPATH/test/Makefile
cp $LURETTEPATH/share/lurettetop.sh $LURETTEPATH/$HOST_TYPE/bin/lurettetop
cp $LURETTEPATH/share/show_luc.sh $LURETTEPATH/$HOST_TYPE/bin/show_luc
......
call @LURETTEPATH@\@HOST_TYPE@\set_env_var.bat
gnuplot-rif_exe.exe %*
......@@ -7,7 +7,7 @@
; version of lucky-mode
(defconst lucky-mode-version "0.3")
(defconst lucky-mode-version "0.4")
(defvar lucky-mode-map nil
......@@ -23,7 +23,11 @@
(setq lucky-font-lock-keywords
'(("--.*$\\|//.*$" . font-lock-comment-face)
("\\<\\(weight\\|max\\|min\\|default\\|alias\\|init\\|cond\\|max\\)\\>" . font-lock-string-face)
("(\\*\\(.\\|\n\\)*?\\*)" . font-lock-comment-face)
("\\<\\(weight\\|max\\|min\\|default\\|alias\\|init\\|cond\\|max\\)\\>" . font-lock-type-face)
("\"\\(.\\|\n\\)*?\"" . font-lock-string-face)
("\\<\\(+\\|*\\|-\\|/\\|mod\\)\\>"
. font-lock-keyword-face)
("[][;,()|{}@^!:#*=<>&/%+~?---]\\.?\\|\\.\\." . font-lock-function-name-face)
......@@ -31,7 +35,7 @@
("\\<\\(bool\\|int\\|real\\|float\\)\\(\\^.+\\)?\\>" . font-lock-variable-name-face)
("\\<\\(define\\|include\\)\\(\\^.+\\)?\\>" 0 'font-lock-preprocessor-face nil)
("\\(\\<\\(inputs\\|outputs\\|typedef\\|start_state\\|states\\|locals\\|transitions\\|transient\\|final\\|stable\\|arcs_nb\\|nodes_nb\\|=\\)\\>\\|->\\)" .
("\\(\\<\\(inputs\\|outputs\\|libraries\\|functions\\|typedef\\|start_state\\|nodes\\|start_node\\|states\\|locals\\|transitions\\|transient\\|final\\|stable\\|arcs_nb\\|nodes_nb\\|=\\)\\>\\|->\\)" .
font-lock-function-name-face)))
......
#!/bin/sh
# Set up environment variables needed by lucky, lurettetop, and xlurette
# (sh syntax)
# to put rif file in
[ -d Data ] || mkdir Data
export LURETTE_PATH=@LURETTEPATH@
export PIXMAP_DIR=@PIXMAP_DIR@
export path=@LURETTEPATH@/@HOST_TYPE@/bin:$path
export PATH=@LURETTEPATH@/@HOST_TYPE@/bin:$PATH
export PS_VIEWER=@GV@
export DOT=@LURETTEPATH@/@HOST_TYPE@/bin/dot
export LUS2EC=@LUS2EC@
export EC2C=@EC2C@
export SIM2CHRO=@LURETTEPATH@/@HOST_TYPE@/bin/sim2chrogtk
export HOST_TYPE=@HOST_TYPE@
# scade
export SCADE2LUSTRE=@SCADE2LUSTRE@
export SCADE_CG=@SCADE_CG@
export LUSTRE2C=@LUSTRE2C@
export SCADE_INSTALL_DIR=@SCADE_INSTALL_DIR@
export SCADE_COMPIL_OPTION=" -noexp @ALL@ "
# Other options migth also work.
# e.g., " -exp @ALL@ " also works, but not " -blockexp "
@LURETTEPATH@/@HOST_TYPE@/bin/lurettetop
set PATH=%PATH%;@LURETTEPATH@\@HOST_TYPE@\bin
set LURETTE_PATH=@LURETTEPATH@
set PIXMAP_DIR=@PIXMAP_DIR@
set PS_VIEWER=@GV@
set DOT=dot
set LUS2EC=@LUS2EC@
set EC2C=@EC2C@
set SIM2CHRO=@LURETTEPATH@\@HOST_TYPE@\bin\sim2chrogtk
set HOST_TYPE=@HOST_TYPE@
set HOSTTYPE=@HOST_TYPE@
set GNUPLOTRIF=@LURETTEPATH@\bin\gnuplot-rif.bat
set SCADE2LUSTRE=@SCADE2LUSTRE@
set SCADE_CG=@SCADE_CG@
set LUSTRE2C=@LUSTRE2C@
set SCADE_INSTALL_DIR=@SCADE_INSTALL_DIR@
set SCADE_COMPIL_OPTION="-noexp @ALL@"
set EDITOR=emacs
REM Other options migth also work.
REM e.g., "-exp @ALL@" also works, but not "-blockexp"
call @LURETTEPATH@\@HOST_TYPE@\set_env_var.bat
show_luc_exe.exe %*
#!/bin/sh
arg=$@
# to put rif file in
[ -d Data ] || mkdir Data
. @LURETTEPATH@/@HOST_TYPE@/set_env_var
exec @LURETTEPATH@/@HOST_TYPE@/bin/show_luc_exe $arg
(*-----------------------------------------------------------
Interface avec la libdl C standard (POSIX)
-----------------------------------------------------------*)
type t
type cfunc
(* stub pour les fonction c :
toutes terminent normalement ou lvent Failure "explication"
*)
external dlopen : string -> t = "c_dlopen"
external dlsym : t -> string -> cfunc = "c_dlsym"
external dlclose : t -> unit = "c_dlclose"
(*-----------------------------------------------------------
Utilitaires pour l'appel des fonctions des dl
*)
type cptr
external cptr_of : 'a -> cptr = "c_cptr_of"
(* Quelques "profils" standards sont fournis *)
external f2f : cfunc -> float -> float = "c_f2f"
external ff2f : cfunc -> float -> float -> float = "c_ff2f"
external i2i : cfunc -> int -> int = "c_i2i"
external ii2i : cfunc -> int -> int -> int = "c_ii2i"
external iii2i : cfunc -> int -> int -> int -> int = "c_iii2i"
(* pour les autres profils, les arguments sont pass dans une liste *)
type carg =
Int_carg of int
| Double_carg of float
| String_carg of string
| Ptr_carg of cptr
type cargs = carg list
let (carg_to_string: carg -> string) =
fun carg ->
match carg with
| Int_carg i -> string_of_int i
| Double_carg f -> string_of_float f
| String_carg str -> str
| Ptr_carg cptr -> "<C pointer>"
(* mais il faut quand mme spcifier le type du rsultat attendu ! *)
external cargs2i : cfunc -> cargs -> int = "c_cargs2i"
external cargs2f : cfunc -> cargs -> float = "c_cargs2f"
external cargs2s : cfunc -> cargs -> string = "c_cargs2s"
(*-----------------------------------------------------------
Interface avec la libdl C standard (POSIX)
-------------------------------------------------------------
N.B. la seule libertée prise est dans la gestion des erreurs :
les fonctions lèvent une exception Failure avec le résultat
de la fonction C "dlerror" (qui n'est donc pas fournie).
-----------------------------------------------------------*)
(* Le type "pointeur generique" void* est abstrait
on fait quand même une difference entre le handler
de la librairie (type t) et les handlers de symboles
dans la librairie (type chandler)
*)
type t
type cfunc
(* stub pour les fonction c :
toutes terminent normalement ou lèvent Failure "explication"
*)