diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
|---|---|---|
| committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
| commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
| tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/ocaml/contract | |
| download | swig-tarball-master.tar.gz | |
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/ocaml/contract')
| -rw-r--r-- | Examples/ocaml/contract/Makefile | 33 | ||||
| -rw-r--r-- | Examples/ocaml/contract/example.i | 18 | ||||
| -rw-r--r-- | Examples/ocaml/contract/example_prog.ml | 7 |
3 files changed, 58 insertions, 0 deletions
diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile new file mode 100644 index 0000000..8e0f2a4 --- /dev/null +++ b/Examples/ocaml/contract/Makefile @@ -0,0 +1,33 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-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 diff --git a/Examples/ocaml/contract/example.i b/Examples/ocaml/contract/example.i new file mode 100644 index 0000000..28d9dd7 --- /dev/null +++ b/Examples/ocaml/contract/example.i @@ -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);
\ No newline at end of file diff --git a/Examples/ocaml/contract/example_prog.ml b/Examples/ocaml/contract/example_prog.ml new file mode 100644 index 0000000..748109c --- /dev/null +++ b/Examples/ocaml/contract/example_prog.ml @@ -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) |
