Added contract example.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5375 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-11-23 12:55:53 +00:00
commit 2e96036cdb
4 changed files with 59 additions and 0 deletions

View file

@ -5,3 +5,4 @@ std_vector
stl
argout_ref
shapes
contract

View file

@ -0,0 +1,33 @@
TOP = ../..
SWIG = $(TOP)/../swig
SRCS =
TARGET = example
INTERFACE = example.i
MLFILE = example.ml
PROGFILE = example_prog.ml
OBJS =
all:: static
dynamic::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
ocaml_dynamic
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
ocaml_static
toplevel::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
ocaml_static_toplevel
clean::
$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
check: all

View file

@ -0,0 +1,18 @@
%module example
%{
#include <math.h>
%}
/* File : example.i */
%module example
%contract cos(double d) {
require:
d >= -3.14159265358979323845254338327950;
d < 3.14159265358979323846264338327950;
ensure:
cos >= -1.0;
cos <= 1.0;
}
double cos(double d);

View file

@ -0,0 +1,7 @@
open Swig
open Example
let _ = print_endline "This won't throw."
let _ = Printf.printf "Cos 1.0 is %f\n" (_cos '(1.0) as float)
let _ = print_endline "This will throw."
let _ = Printf.printf "Cos 5.0 is %f\n" (_cos '(5.0) as float)