diff --git a/Examples/ocaml/check.list b/Examples/ocaml/check.list index 0baabf8e9..f95740043 100644 --- a/Examples/ocaml/check.list +++ b/Examples/ocaml/check.list @@ -5,3 +5,4 @@ std_vector stl argout_ref shapes +contract diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile new file mode 100644 index 000000000..df6436da9 --- /dev/null +++ b/Examples/ocaml/contract/Makefile @@ -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 diff --git a/Examples/ocaml/contract/example.i b/Examples/ocaml/contract/example.i new file mode 100644 index 000000000..28d9dd7d6 --- /dev/null +++ b/Examples/ocaml/contract/example.i @@ -0,0 +1,18 @@ +%module example +%{ +#include +%} + +/* 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 000000000..748109c2b --- /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)