[OCaml] Rename example_prog.ml to runme.ml in the OCaml examples
Name the output executable "runme" in the examples. Replace use of "foolib" in the string_from_ptr example. Fix a warning in the std_vector example. Add strings_test to Examples/ocaml/check.list. Disable two tests that were causing the OCaml test suite to fail.
This commit is contained in:
parent
1be9f5fec3
commit
8f7bc4cc10
18 changed files with 27 additions and 26 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -164,8 +164,8 @@ Examples/test-suite/ocaml/*.cm*
|
|||
Examples/test-suite/ocaml/runme
|
||||
!Examples/test-suite/ocaml/*runme.ml
|
||||
Examples/ocaml/**/example.ml*
|
||||
Examples/ocaml/**/example
|
||||
Examples/ocaml/**/example_top
|
||||
Examples/ocaml/**/runme
|
||||
Examples/ocaml/**/runme_top
|
||||
Examples/ocaml/**/*.cm*
|
||||
Examples/ocaml/**/swig.ml*
|
||||
Examples/ocaml/**/swigp4.ml
|
||||
|
|
|
|||
|
|
@ -919,7 +919,7 @@ ocaml_static: $(SRCDIR_SRCS)
|
|||
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
|
||||
$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(TARGET) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"
|
||||
$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"
|
||||
|
||||
ocaml_dynamic: $(SRCDIR_SRCS)
|
||||
$(OCAMLCORE)
|
||||
|
|
@ -931,7 +931,7 @@ ocaml_dynamic: $(SRCDIR_SRCS)
|
|||
rm $(INTERFACE:%.i=%.mli)
|
||||
$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCAMLFIND) $(OCC) -g -ccopt -g -cclib -g -custom -o $(TARGET) swig.cmo -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo)
|
||||
$(NOLINK) || $(OCAMLFIND) $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo)
|
||||
|
||||
ocaml_static_toplevel: $(SRCDIR_SRCS)
|
||||
$(OCAMLCORE)
|
||||
|
|
@ -940,7 +940,7 @@ ocaml_static_toplevel: $(SRCDIR_SRCS)
|
|||
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
|
||||
$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCAMLMKTOP) swig.cmo -I $(OCAMLP4WHERE) camlp4o.cma swigp4.cmo -g -ccopt -g -cclib -g -custom -o $(TARGET)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"
|
||||
$(NOLINK) || $(OCAMLMKTOP) swig.cmo -I $(OCAMLP4WHERE) camlp4o.cma swigp4.cmo -g -ccopt -g -cclib -g -custom -o $(RUNME)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)"
|
||||
|
||||
ocaml_static_cpp: $(SRCDIR_SRCS)
|
||||
$(OCAMLCORE)
|
||||
|
|
@ -950,7 +950,7 @@ ocaml_static_cpp: $(SRCDIR_SRCS)
|
|||
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
|
||||
$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(TARGET) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
|
||||
$(NOLINK) || $(OCC) -g -ccopt -g -cclib -g -custom -o $(RUNME) swig.cmo $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
|
||||
|
||||
ocaml_static_cpp_toplevel: $(SRCDIR_SRCS)
|
||||
$(OCAMLCORE)
|
||||
|
|
@ -960,7 +960,7 @@ ocaml_static_cpp_toplevel: $(SRCDIR_SRCS)
|
|||
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
|
||||
$(OCC) -w -U -g -c $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCAMLMKTOP) swig.cmo -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo -g -ccopt -g -cclib -g -custom -o $(TARGET)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
|
||||
$(NOLINK) || $(OCAMLMKTOP) swig.cmo -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo -g -ccopt -g -cclib -g -custom -o $(RUNME)_top $(INTERFACE:%.i=%.cmo) $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
|
||||
|
||||
ocaml_dynamic_cpp: $(SRCDIR_SRCS)
|
||||
$(OCAMLCORE)
|
||||
|
|
@ -973,14 +973,14 @@ ocaml_dynamic_cpp: $(SRCDIR_SRCS)
|
|||
rm $(INTERFACE:%.i=%.mli)
|
||||
$(OCAMLFIND) $(OCC) -g -c -package dl $(INTERFACE:%.i=%.ml)
|
||||
test -z "$(PROGFILE)" || $(OCC) -o $(PROGFILE:%.ml=%) $(OCAMLPP) -c $(SRCDIR)$(PROGFILE)
|
||||
$(NOLINK) || $(OCAMLFIND) swig.cmo $(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom -o $(TARGET) -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings'
|
||||
$(NOLINK) || $(OCAMLFIND) swig.cmo $(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom -o $(RUNME) -package dl -linkpkg $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings'
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Run ocaml example
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
ocaml_run:
|
||||
$(RUNTOOL) ./$(TARGET) $(RUNPIPE)
|
||||
$(RUNTOOL) ./$(RUNME) $(RUNPIPE)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Version display
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ SRCS = example.c
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
|
|
|
|||
17
Examples/ocaml/argout_ref/runme.ml
Normal file
17
Examples/ocaml/argout_ref/runme.ml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(* runme.ml *)
|
||||
|
||||
open Swig
|
||||
open Example
|
||||
|
||||
exception BadReturn
|
||||
|
||||
let x = if Array.length Sys.argv > 1 then int_of_string Sys.argv.(1) else 16
|
||||
let y = if Array.length Sys.argv > 2 then int_of_string Sys.argv.(2) else 12
|
||||
let (xf,yf) = match _factor '((x to int),(y to int)) with
|
||||
C_list [ C_int a ; C_int b ] -> a,b
|
||||
| _ -> raise BadReturn
|
||||
let _ = print_endline
|
||||
("Factorization of " ^ (string_of_int x) ^
|
||||
" and " ^ (string_of_int y) ^
|
||||
" is " ^ (string_of_int xf) ^
|
||||
" and " ^ (string_of_int yf))
|
||||
|
|
@ -8,3 +8,4 @@ shapes
|
|||
contract
|
||||
scoped_enum
|
||||
string_from_ptr
|
||||
strings_test
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ SRCS =
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS =
|
||||
|
||||
check: build
|
||||
|
|
|
|||
12
Examples/ocaml/contract/runme.ml
Normal file
12
Examples/ocaml/contract/runme.ml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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 _ =
|
||||
try
|
||||
Printf.printf "Cos 5.0 is %f\n" (_cos '(5.0) as float)
|
||||
with Failure s ->
|
||||
print_endline s ;
|
||||
print_endline "Exception thrown."
|
||||
|
|
@ -5,7 +5,7 @@ SRCS =
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS =
|
||||
|
||||
check: build
|
||||
|
|
|
|||
5
Examples/ocaml/scoped_enum/runme.ml
Normal file
5
Examples/ocaml/scoped_enum/runme.ml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
open Swig
|
||||
open Example
|
||||
|
||||
let arg = if Array.length Sys.argv > 1 then Sys.argv.(1) else "Tag1"
|
||||
let _ = _f (match arg with "Tag1" -> ``Tag1 | _ -> ``Tag2)
|
||||
|
|
@ -6,7 +6,7 @@ SRCS = example.c
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
|
|
|
|||
76
Examples/ocaml/shapes/runme.ml
Normal file
76
Examples/ocaml/shapes/runme.ml
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
(* runme.ml *)
|
||||
|
||||
open Swig ;;
|
||||
open Example ;;
|
||||
|
||||
let side_length (ax,ay) (bx,by) =
|
||||
sqrt (((bx -. ax) ** 2.0) +. ((by -. ay) ** 2.0)) ;;
|
||||
|
||||
let triangle_area a_pt b_pt c_pt =
|
||||
let a = (side_length a_pt b_pt)
|
||||
and b = (side_length b_pt c_pt)
|
||||
and c = (side_length c_pt a_pt) in
|
||||
let s = (a +. b +. c) /. 2.0 in
|
||||
sqrt (s *. (s -. a) *. (s -. b) *. (s -. c)) ;;
|
||||
|
||||
let point_in_triangle (pta,ptb,ptc) x y =
|
||||
let delta = 0.0000001 in (* Error *)
|
||||
let ptx = (x,y) in
|
||||
begin
|
||||
let a_area = triangle_area pta ptb ptx
|
||||
and b_area = triangle_area ptb ptc ptx
|
||||
and c_area = triangle_area ptc pta ptx
|
||||
and x_area = triangle_area pta ptb ptc in
|
||||
let result = (abs_float (a_area +. b_area +. c_area -. x_area)) < delta
|
||||
in
|
||||
result
|
||||
end ;;
|
||||
|
||||
let triangle_class pts ob meth args =
|
||||
match meth with
|
||||
"cover" ->
|
||||
(match args with
|
||||
C_list [ x_arg ; y_arg ] ->
|
||||
let xa = x_arg as float
|
||||
and ya = y_arg as float in
|
||||
(point_in_triangle pts xa ya) to bool
|
||||
| _ -> raise (Failure "cover needs two double arguments."))
|
||||
| _ -> (invoke ob) meth args ;;
|
||||
|
||||
let dist (ax,ay) (bx,by) =
|
||||
let dx = ax -. bx and dy = ay -. by in
|
||||
sqrt ((dx *. dx) +. (dy *. dy))
|
||||
|
||||
let waveplot_depth events distance pt =
|
||||
(List.fold_left (+.) 0.0
|
||||
(List.map
|
||||
(fun (x,y,d) ->
|
||||
let t = dist pt (x,y) in
|
||||
((sin t) /. t) *. d)
|
||||
events)) +. distance
|
||||
|
||||
let waveplot_class events distance ob meth args =
|
||||
match meth with
|
||||
"depth" ->
|
||||
(match args with
|
||||
C_list [ x_arg ; y_arg ] ->
|
||||
let xa = x_arg as float
|
||||
and ya = y_arg as float in
|
||||
(waveplot_depth events distance (xa,ya)) to float
|
||||
| _ -> raise (Failure "cover needs two double arguments."))
|
||||
| _ -> (invoke ob) meth args ;;
|
||||
|
||||
let triangle =
|
||||
new_derived_object
|
||||
new_shape
|
||||
(triangle_class ((0.0,0.0),(0.5,1.0),(1.0,0.6)))
|
||||
'() ;;
|
||||
|
||||
let waveplot =
|
||||
new_derived_object
|
||||
new_volume
|
||||
(waveplot_class [ 0.01,0.01,3.0 ; 1.01,-2.01,1.5 ] 5.0)
|
||||
'() ;;
|
||||
|
||||
let _ = _draw_shape_coverage '(triangle, 60, 20) ;;
|
||||
let _ = _draw_depth_map '(waveplot, 60, 20) ;;
|
||||
|
|
@ -5,7 +5,7 @@ SRCS = example.c
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
|
|
|
|||
33
Examples/ocaml/simple/runme.ml
Normal file
33
Examples/ocaml/simple/runme.ml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(* runme.ml *)
|
||||
|
||||
open Swig
|
||||
open Example
|
||||
|
||||
(* Call our gcd() function *)
|
||||
|
||||
exception NoReturn
|
||||
|
||||
let x = 42 to int
|
||||
let y = 105 to int
|
||||
let g = _gcd '(x,y) as int
|
||||
let _ = Printf.printf "The gcd of %d and %d is %d\n" (x as int) (y as int) g
|
||||
|
||||
(* Manipulate the Foo global variable *)
|
||||
|
||||
(* Output its current value *)
|
||||
let _ = Printf.printf "Foo = %f\n" (_Foo '() as float)
|
||||
|
||||
(* Change its value *)
|
||||
let _ = _Foo '(3.1415926)
|
||||
|
||||
(* See if the change took effect *)
|
||||
let _ = Printf.printf "Foo = %f\n" (_Foo '() as float)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ let print_DoubleVector v =
|
|||
(fun v i ->
|
||||
print_float ((v '[i to int]) as float) ;
|
||||
print_string " ") ;
|
||||
print_endline
|
||||
print_endline ""
|
||||
end
|
||||
|
||||
(* Call average with a Ocaml array... *)
|
||||
|
|
@ -27,7 +27,7 @@ let rec fill_dv v x =
|
|||
fill_dv v (x *. x)
|
||||
end
|
||||
let _ = fill_dv v 0.999
|
||||
let _ = print_DoubleVector v ; print_endline ""
|
||||
let _ = print_DoubleVector v
|
||||
let u = new_IntVector '()
|
||||
let _ = for i = 1 to 4 do
|
||||
u -> push_back ((i to int))
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
|||
SWIGOPT = -c++
|
||||
SRCS =
|
||||
TARGET = example
|
||||
INTERFACE = foolib.i
|
||||
MLFILE = foolib.ml
|
||||
PROGFILE = example_prog.ml
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS =
|
||||
|
||||
check: build
|
||||
|
|
|
|||
16
Examples/ocaml/string_from_ptr/example.i
Normal file
16
Examples/ocaml/string_from_ptr/example.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
%module example
|
||||
%{
|
||||
static int foo( char **buf ) {
|
||||
*buf = "string from c";
|
||||
return 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(in,numinputs=0) char **buf (char *temp) {
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(argout) char **buf {
|
||||
swig_result = caml_list_append(swig_result,caml_val_string((char *)*$1));
|
||||
}
|
||||
|
||||
int foo( char **buf );
|
||||
21
Examples/ocaml/string_from_ptr/runme.ml
Normal file
21
Examples/ocaml/string_from_ptr/runme.ml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
open Swig (* Give access to the swig library *)
|
||||
open Example (* This is the name of your swig output *)
|
||||
|
||||
let results = _foo '() (* Function names are prefixed with _ in order to make
|
||||
them lex as identifiers in ocaml. Consider that
|
||||
uppercase identifiers are module names in ocaml.
|
||||
NOTE: the '() syntax is part of swigp4. You can do:
|
||||
let results = _foo C_void *)
|
||||
|
||||
(* Since your function has a return value in addition to the string output,
|
||||
you'll need to match them as a list *)
|
||||
|
||||
let result_string =
|
||||
match results with
|
||||
C_list [ C_string result_string ; C_int 0 ] -> (* The return value is
|
||||
last when out arguments appear, but this too can be customized.
|
||||
We're also checking that the function succeeded. *)
|
||||
result_string
|
||||
| _ -> raise (Failure "Expected string, int reply from _foo")
|
||||
|
||||
let _ = print_endline result_string
|
||||
|
|
@ -21,6 +21,7 @@ default_constructor \
|
|||
director_binary_string \
|
||||
director_enum \
|
||||
director_exception \
|
||||
director_exception_nothrow \
|
||||
director_ignore \
|
||||
director_nested \
|
||||
director_pass_by_value \
|
||||
|
|
@ -30,6 +31,7 @@ director_redefined \
|
|||
director_string \
|
||||
director_using \
|
||||
enum_thorough \
|
||||
li_windows \
|
||||
member_pointer_const \
|
||||
minherit \
|
||||
nested_directors \
|
||||
|
|
|
|||
Loading…
Reference in a new issue