From 2e96036cdb070e33507bccb6a4556bc5bfe994cd Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Sun, 23 Nov 2003 12:55:53 +0000 Subject: [PATCH] Added contract example. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5375 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/ocaml/check.list | 1 + Examples/ocaml/contract/Makefile | 33 +++++++++++++++++++++++++ Examples/ocaml/contract/example.i | 18 ++++++++++++++ Examples/ocaml/contract/example_prog.ml | 7 ++++++ 4 files changed, 59 insertions(+) create mode 100644 Examples/ocaml/contract/Makefile create mode 100644 Examples/ocaml/contract/example.i create mode 100644 Examples/ocaml/contract/example_prog.ml 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)