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:
parent
5969a1c272
commit
2e96036cdb
4 changed files with 59 additions and 0 deletions
|
|
@ -5,3 +5,4 @@ std_vector
|
|||
stl
|
||||
argout_ref
|
||||
shapes
|
||||
contract
|
||||
|
|
|
|||
33
Examples/ocaml/contract/Makefile
Normal file
33
Examples/ocaml/contract/Makefile
Normal 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
|
||||
18
Examples/ocaml/contract/example.i
Normal file
18
Examples/ocaml/contract/example.i
Normal 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);
|
||||
7
Examples/ocaml/contract/example_prog.ml
Normal file
7
Examples/ocaml/contract/example_prog.ml
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue