From 43bdffcbc1b99aa73243fd7d346cd4a5a19cf274 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 6 Feb 2019 22:13:10 +0000 Subject: [PATCH 01/14] Skip failing MzScheme tests --- Examples/test-suite/mzscheme/Makefile.in | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Examples/test-suite/mzscheme/Makefile.in b/Examples/test-suite/mzscheme/Makefile.in index 3e15f8610..edd99a050 100644 --- a/Examples/test-suite/mzscheme/Makefile.in +++ b/Examples/test-suite/mzscheme/Makefile.in @@ -10,6 +10,88 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ +FAILING_CPP_TESTS = \ +allowexcept \ +allprotected \ +apply_strings \ +arrays_dimensionless \ +arrays_global \ +char_strings \ +class_scope_weird \ +constant_pointers \ +cpp_basic \ +cpp_enum \ +cpp_namespace \ +cpp_static \ +curiously_recurring_template_pattern \ +default_arg_expressions \ +default_args \ +default_constructor \ +derived_nested \ +director_ignore \ +enum_thorough \ +enum_var \ +exception_order \ +extend \ +extend_constructor_destructor \ +extern_c \ +friends \ +global_scope_types \ +global_vars \ +grouping \ +inherit_member \ +li_attribute \ +li_attribute_template \ +li_boost_shared_ptr \ +li_boost_shared_ptr_bits \ +li_std_combinations \ +li_std_map \ +li_std_pair \ +li_std_pair_using \ +li_std_string \ +li_std_vector \ +li_swigtype_inout \ +li_windows \ +member_funcptr_galore \ +member_pointer \ +member_pointer_const \ +memberin_extend \ +namespace_class \ +namespace_spaces \ +naturalvar \ +naturalvar_more \ +nested_class \ +nested_template_base \ +ordering \ +preproc_constants \ +rename_predicates \ +rename_simple \ +samename \ +smart_pointer_const_overload \ +smart_pointer_member \ +smart_pointer_template_const_overload \ +static_const_member_2 \ +swig_exception \ +template_default2 \ +template_specialization_defarg \ +template_static \ +template_typemaps \ +typemap_variables \ +valuewrapper_opaque \ + +FAILING_C_TESTS = \ +c_delete \ +enum_missing \ +enums \ +integers \ +name \ +preproc_constants_c \ +preproc_line_file \ +unions \ + +FAILING_MULTI_CPP_TESTS = \ +multi_import \ + include $(srcdir)/../common.mk # Overridden variables here From 80e9034425e7d249f3acec213b2414308ca89472 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 6 Feb 2019 22:52:24 +0000 Subject: [PATCH 02/14] Fix mzscheme multimap example --- Examples/mzscheme/multimap/Makefile | 1 + Examples/mzscheme/multimap/example.c | 2 +- Examples/mzscheme/multimap/example.i | 6 +++--- Examples/mzscheme/multimap/runme.scm | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile index 713ee43a7..eccd59d82 100644 --- a/Examples/mzscheme/multimap/Makefile +++ b/Examples/mzscheme/multimap/Makefile @@ -13,5 +13,6 @@ build: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme + clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/multimap/example.c b/Examples/mzscheme/multimap/example.c index b8360fa8a..e945042ab 100644 --- a/Examples/mzscheme/multimap/example.c +++ b/Examples/mzscheme/multimap/example.c @@ -27,7 +27,7 @@ int gcdmain(int argc, char *argv[]) { return 0; } -int count(char *bytes, int len, char c) { +int charcount(char *bytes, int len, char c) { int i; int count = 0; for (i = 0; i < len; i++) { diff --git a/Examples/mzscheme/multimap/example.i b/Examples/mzscheme/multimap/example.i index 515948abc..db4be3d16 100644 --- a/Examples/mzscheme/multimap/example.i +++ b/Examples/mzscheme/multimap/example.i @@ -4,7 +4,7 @@ %{ extern int gcd(int x, int y); extern int gcdmain(int argc, char *argv[]); -extern int count(char *bytes, int len, char c); +extern int charcount(char *bytes, int len, char c); extern void capitalize (char *str, int len); extern void circle (double cx, double cy); extern int squareCubed (int n, int *OUTPUT); @@ -50,7 +50,7 @@ extern int gcdmain(int argc, char *argv[]); $2 = SCHEME_STRLEN_VAL($input); } -extern int count(char *bytes, int len, char c); +extern int charcount(char *bytes, int len, char c); /* This example shows how to wrap a function that mutates a string */ @@ -68,7 +68,7 @@ extern int count(char *bytes, int len, char c); %typemap(argout) (char *str, int len) { Scheme_Object *s; - s = scheme_make_sized_string($1,$2,1); + s = scheme_make_sized_string($1,$2); SWIG_APPEND_VALUE(s); free($1); } diff --git a/Examples/mzscheme/multimap/runme.scm b/Examples/mzscheme/multimap/runme.scm index f1e626f43..6d2c9cce3 100644 --- a/Examples/mzscheme/multimap/runme.scm +++ b/Examples/mzscheme/multimap/runme.scm @@ -20,7 +20,7 @@ (gcdmain #("gcdmain" "42" "105")) -(display (count "Hello World" #\l)) +(display (charcount "Hello World" #\l)) (newline) (display (capitalize "hello world")) From f6da155fda1d86660dc65e3ea65e8e88da0c5a6c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 6 Feb 2019 22:55:15 +0000 Subject: [PATCH 03/14] Fix mzscheme simple example --- Examples/mzscheme/simple/Makefile | 1 + Examples/mzscheme/simple/runme.scm | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile index 713ee43a7..eccd59d82 100644 --- a/Examples/mzscheme/simple/Makefile +++ b/Examples/mzscheme/simple/Makefile @@ -13,5 +13,6 @@ build: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme + clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/simple/runme.scm b/Examples/mzscheme/simple/runme.scm index a98e31fd5..181635078 100644 --- a/Examples/mzscheme/simple/runme.scm +++ b/Examples/mzscheme/simple/runme.scm @@ -4,7 +4,7 @@ (display (get-time)) -(printf "My-variable = ~a~n" (my-variable)) +(printf "My-variable = ~a~n" (My-variable)) (let loop ((i 0)) (when (< i 14) (begin (display i) @@ -17,8 +17,8 @@ (when (< i 250) (begin (let loopi ((j 1)) - (when (< j 250) (begin (my-variable (+ (my-variable) (mod i j))) + (when (< j 250) (begin (My-variable (+ (My-variable) (mod i j))) (loopi (+ j 1))))) (loop (+ i 1))))) -(printf "My-variable = ~a~n" (my-variable)) +(printf "My-variable = ~a~n" (My-variable)) From b21a28f26ae178ee59f857ab4e0e498dff509ad7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 7 Feb 2019 07:45:49 +0000 Subject: [PATCH 04/14] MzScheme missing destructor added in, std_vector example fixed --- Examples/mzscheme/std_vector/Makefile | 11 ++++------ Examples/mzscheme/std_vector/runme.scm | 30 +++++++++++++------------- Source/Modules/mzscheme.cxx | 3 +-- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile index 96f5e80cf..4cf839a08 100644 --- a/Examples/mzscheme/std_vector/Makefile +++ b/Examples/mzscheme/std_vector/Makefile @@ -1,21 +1,18 @@ TOP = ../.. SWIGEXE = $(TOP)/../swig SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib -SRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = -GPP = `which g++` -MZC = test -n "/usr/bin/mzc" && /usr/bin/mzc - check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(SWIGEXE) -mzscheme -c++ $(SWIGOPT) $(INTERFACE) - $(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx - $(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(CXXSRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp clean: $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/std_vector/runme.scm b/Examples/mzscheme/std_vector/runme.scm index 67351f128..7af9d168e 100644 --- a/Examples/mzscheme/std_vector/runme.scm +++ b/Examples/mzscheme/std_vector/runme.scm @@ -9,16 +9,17 @@ (if (< i size) (begin (proc v i) - (with-vector-item v (+ i 1))))) + (with-vector-item v (+ i 1))) + (void))) (with-vector-item v 0))) -(define (with-intvector v proc) - (with-vector v proc intvector-length)) -(define (with-doublevector v proc) - (with-vector v proc doublevector-length)) +(define (with-IntVector v proc) + (with-vector v proc IntVector-length)) +(define (with-DoubleVector v proc) + (with-vector v proc DoubleVector-length)) -(define (print-doublevector v) - (with-doublevector v (lambda (v i) (display (doublevector-ref v i)) +(define (print-DoubleVector v) + (with-DoubleVector v (lambda (v i) (display (DoubleVector-ref v i)) (display " "))) (newline)) @@ -29,11 +30,11 @@ (newline) ; ... or a wrapped std::vector -(define v (new-intvector 4)) -(with-intvector v (lambda (v i) (intvector-set! v i (+ i 1)))) +(define v (new-IntVector 4)) +(with-IntVector v (lambda (v i) (IntVector-set! v i (+ i 1)))) (display (average v)) (newline) -(delete-intvector v) +(delete-IntVector v) ; half will return a Scheme vector. ; Call it with a Scheme vector... @@ -42,13 +43,12 @@ (newline) ; ... or a wrapped std::vector -(define v (new-doublevector)) -(map (lambda (i) (doublevector-push! v i)) '(1 2 3 4)) +(define v (new-DoubleVector)) +(map (lambda (i) (DoubleVector-push! v i)) '(1 2 3 4)) (display (half v)) (newline) ; now halve a wrapped std::vector in place (halve-in-place v) -(print-doublevector v) -(delete-doublevector v) - +(print-DoubleVector v) +(delete-DoubleVector v) diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index e826e6b3c..316b66678 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -439,9 +439,8 @@ public: sprintf(temp, "%d", numargs); if (exporting_destructor) { Printf(init_func_def, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); - } else { - Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", proc_name, wname, proc_name, numreq, numargs); } + Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", proc_name, wname, proc_name, numreq, numargs); } else { if (!Getattr(n, "sym:nextSibling")) { /* Emit overloading dispatch function */ From 20344093efc8acc9da4fe77ce6b3601e10cc747d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 13:15:32 +0000 Subject: [PATCH 05/14] Fix mzscheme static variable wrappers $argnum needs to be expanded in the 'varin' typemap which shares code used by the 'in' typemap. Setting the static variable is also a function call (argnum=1). Added class examples - needs static variables to work Test newly working test cases with this fix --- Examples/mzscheme/check.list | 1 + Examples/mzscheme/class/Makefile | 18 +++++++ Examples/mzscheme/class/example.cxx | 28 +++++++++++ Examples/mzscheme/class/example.h | 34 ++++++++++++++ Examples/mzscheme/class/example.i | 9 ++++ Examples/mzscheme/class/runme.scm | 60 ++++++++++++++++++++++++ Examples/test-suite/mzscheme/Makefile.in | 23 --------- Source/Modules/mzscheme.cxx | 2 +- 8 files changed, 151 insertions(+), 24 deletions(-) create mode 100644 Examples/mzscheme/class/Makefile create mode 100644 Examples/mzscheme/class/example.cxx create mode 100644 Examples/mzscheme/class/example.h create mode 100644 Examples/mzscheme/class/example.i create mode 100644 Examples/mzscheme/class/runme.scm diff --git a/Examples/mzscheme/check.list b/Examples/mzscheme/check.list index f9e4f11c7..d2554c41c 100644 --- a/Examples/mzscheme/check.list +++ b/Examples/mzscheme/check.list @@ -1,4 +1,5 @@ # see top-level Makefile.in +class multimap simple std_vector diff --git a/Examples/mzscheme/class/Makefile b/Examples/mzscheme/class/Makefile new file mode 100644 index 000000000..ee92aa9f1 --- /dev/null +++ b/Examples/mzscheme/class/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIGEXE = $(TOP)/../swig +SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(CXXSRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/class/example.cxx b/Examples/mzscheme/class/example.cxx new file mode 100644 index 000000000..046304519 --- /dev/null +++ b/Examples/mzscheme/class/example.cxx @@ -0,0 +1,28 @@ +/* File : example.cxx */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area() { + return M_PI*radius*radius; +} + +double Circle::perimeter() { + return 2*M_PI*radius; +} + +double Square::area() { + return width*width; +} + +double Square::perimeter() { + return 4*width; +} diff --git a/Examples/mzscheme/class/example.h b/Examples/mzscheme/class/example.h new file mode 100644 index 000000000..0dff185b2 --- /dev/null +++ b/Examples/mzscheme/class/example.h @@ -0,0 +1,34 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + } + double x, y; + void move(double dx, double dy); + virtual double area() = 0; + virtual double perimeter() = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); +}; diff --git a/Examples/mzscheme/class/example.i b/Examples/mzscheme/class/example.i new file mode 100644 index 000000000..fbdf7249f --- /dev/null +++ b/Examples/mzscheme/class/example.i @@ -0,0 +1,9 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" diff --git a/Examples/mzscheme/class/runme.scm b/Examples/mzscheme/class/runme.scm new file mode 100644 index 000000000..dea0b75bc --- /dev/null +++ b/Examples/mzscheme/class/runme.scm @@ -0,0 +1,60 @@ +; file: runme.scm + +; This file illustrates the proxy class C++ interface generated +; by SWIG. + +(load-extension "example.so") + +; Convenience wrapper around the display function +; (which only accepts one argument at the time) + +(define (mdisplay-newline . args) + (for-each display args) + (newline)) + +; ----- Object creation ----- + +(mdisplay-newline "Creating some objects:") +(define c (new-Circle 10)) +(mdisplay-newline " Created circle " c) +(define s (new-Square 10)) +(mdisplay-newline " Created square " s) + +; ----- Access a static member ----- + +(mdisplay-newline "\nA total of " (Shape-nshapes) " shapes were created") + +; ----- Member data access ----- + +; Set the location of the object + +(Shape-x-set c 20) +(Shape-y-set c 30) + +(Shape-x-set s -10) +(Shape-y-set s 5) + +(mdisplay-newline "\nHere is their current position:") +(mdisplay-newline " Circle = (" (Shape-x-get c) "," (Shape-y-get c) ")") +(mdisplay-newline " Square = (" (Shape-x-get s) "," (Shape-y-get s) ")") + +; ----- Call some methods ----- + +(mdisplay-newline "\nHere are some properties of the shapes:") +(define (shape-props o) + (mdisplay-newline " " o) + (mdisplay-newline " area = " (Shape-area o)) + (mdisplay-newline " perimeter = " (Shape-perimeter o))) +(for-each shape-props (list c s)) + +(mdisplay-newline "\nGuess I'll clean up now") + +; Note: this invokes the virtual destructor +(delete-Shape c) +(delete-Shape s) + +(define s 3) +(mdisplay-newline (Shape-nshapes) " shapes remain") +(mdisplay-newline "Goodbye") + +(exit 0) diff --git a/Examples/test-suite/mzscheme/Makefile.in b/Examples/test-suite/mzscheme/Makefile.in index edd99a050..5eacb10e3 100644 --- a/Examples/test-suite/mzscheme/Makefile.in +++ b/Examples/test-suite/mzscheme/Makefile.in @@ -12,7 +12,6 @@ top_builddir = @top_builddir@ FAILING_CPP_TESTS = \ allowexcept \ -allprotected \ apply_strings \ arrays_dimensionless \ arrays_global \ @@ -21,42 +20,30 @@ class_scope_weird \ constant_pointers \ cpp_basic \ cpp_enum \ -cpp_namespace \ -cpp_static \ curiously_recurring_template_pattern \ default_arg_expressions \ -default_args \ default_constructor \ derived_nested \ director_ignore \ enum_thorough \ -enum_var \ -exception_order \ extend \ -extend_constructor_destructor \ -extern_c \ friends \ global_scope_types \ -global_vars \ -grouping \ inherit_member \ li_attribute \ li_attribute_template \ li_boost_shared_ptr \ -li_boost_shared_ptr_bits \ li_std_combinations \ li_std_map \ li_std_pair \ li_std_pair_using \ li_std_string \ li_std_vector \ -li_swigtype_inout \ li_windows \ member_funcptr_galore \ member_pointer \ member_pointer_const \ memberin_extend \ -namespace_class \ namespace_spaces \ naturalvar \ naturalvar_more \ @@ -64,24 +51,14 @@ nested_class \ nested_template_base \ ordering \ preproc_constants \ -rename_predicates \ -rename_simple \ samename \ -smart_pointer_const_overload \ -smart_pointer_member \ -smart_pointer_template_const_overload \ -static_const_member_2 \ -swig_exception \ template_default2 \ template_specialization_defarg \ -template_static \ template_typemaps \ typemap_variables \ valuewrapper_opaque \ FAILING_C_TESTS = \ -c_delete \ -enum_missing \ enums \ integers \ name \ diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index 316b66678..1df5ae0fb 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -527,7 +527,7 @@ public: Replaceall(tm, "$source", "argv[0]"); Replaceall(tm, "$target", name); Replaceall(tm, "$input", "argv[0]"); - /* Printv(f->code, tm, "\n",NIL); */ + Replaceall(tm, "$argnum", "1"); emit_action_code(n, f->code, tm); } else { throw_unhandled_mzscheme_type_error(t); From de23343739a79331883cfd2bede0afc0504657c0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 14:29:34 +0000 Subject: [PATCH 06/14] Standardise Guile simple example Changes so that it works the same as other language modules --- Examples/guile/simple/example.c | 27 ++++++++++++--------------- Examples/guile/simple/example.i | 6 ++---- Examples/guile/simple/runme.scm | 28 ++++++++++++---------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/Examples/guile/simple/example.c b/Examples/guile/simple/example.c index dcafc4dc4..1c2af789c 100644 --- a/Examples/guile/simple/example.c +++ b/Examples/guile/simple/example.c @@ -1,21 +1,18 @@ -/* Simple example from documentation */ /* File : example.c */ -#include +/* A global variable */ +double Foo = 3.0; -double My_variable = 3.0; - -int fact(int n) { - if (n <= 1) return 1; - else return n*fact(n-1); +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; } -int mod(int n, int m) { - return (n % m); -} -char *get_time() { - long ltime; - time(<ime); - return ctime(<ime); -} diff --git a/Examples/guile/simple/example.i b/Examples/guile/simple/example.i index 1a9930a14..4fcea98b2 100644 --- a/Examples/guile/simple/example.i +++ b/Examples/guile/simple/example.i @@ -5,10 +5,8 @@ %} %inline %{ -extern double My_variable; -extern int fact(int); -extern int mod(int n, int m); -extern char *get_time(); +extern int gcd(int x, int y); +extern double Foo; %} %include guile/guilemain.i diff --git a/Examples/guile/simple/runme.scm b/Examples/guile/simple/runme.scm index c3fd0b41f..ccd755701 100644 --- a/Examples/guile/simple/runme.scm +++ b/Examples/guile/simple/runme.scm @@ -3,24 +3,20 @@ (for-each display args) (newline)) -(mdisplay-newline (get-time) "My variable = " (My-variable)) +; Call our gcd() function -(do ((i 0 (1+ i))) - ((= 14 i)) - (mdisplay-newline i " factorial is " (fact i))) +(define x 42) +(define y 105) +(define g (gcd x y)) +(mdisplay-newline "The gcd of " x " and " y " is " g) -(define (mods i imax j jmax) - (if (< i imax) - (if (< j jmax) - (begin - (My-variable (+ (My-variable) (mod i j))) - (mods i imax (+ j 1) jmax)) - (mods (+ i 1) imax 1 jmax)))) +; Manipulate the Foo global variable -(mods 1 150 1 150) +; Output its current value +(mdisplay-newline "Foo = " (Foo)) -(mdisplay-newline "My-variable = " (My-variable)) - -(exit (and (= 1932053504 (fact 13)) - (= 745470.0 (My-variable)))) +; Change its value +(Foo 3.1415926) +; See if the change took effect +(mdisplay-newline "Foo = " (Foo)) From 30d0c16ac0935fdc343c1e646ff6cae3bf03bcd8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 14:43:27 +0000 Subject: [PATCH 07/14] Standardise Mzscheme simple example Changes so that it works the same as other language modules --- Examples/mzscheme/simple/README | 1 - Examples/mzscheme/simple/example.c | 30 +++++++++-------------- Examples/mzscheme/simple/example.i | 13 ++-------- Examples/mzscheme/simple/runme.scm | 39 ++++++++++++++++++------------ 4 files changed, 37 insertions(+), 46 deletions(-) delete mode 100644 Examples/mzscheme/simple/README diff --git a/Examples/mzscheme/simple/README b/Examples/mzscheme/simple/README deleted file mode 100644 index 07e8da069..000000000 --- a/Examples/mzscheme/simple/README +++ /dev/null @@ -1 +0,0 @@ -Simple example from users manual. diff --git a/Examples/mzscheme/simple/example.c b/Examples/mzscheme/simple/example.c index f2b074781..1c2af789c 100644 --- a/Examples/mzscheme/simple/example.c +++ b/Examples/mzscheme/simple/example.c @@ -1,24 +1,18 @@ -/* Simple example from documentation */ /* File : example.c */ -#include +/* A global variable */ +double Foo = 3.0; -double My_variable = 3.0; - -/* Compute factorial of n */ -int fact(int n) { - if (n <= 1) return 1; - else return n*fact(n-1); -} - -/* Compute n mod m */ -int my_mod(int n, int m) { - return (n % m); +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; } -char *get_time() { - long ltime; - time(<ime); - return ctime(<ime); -} diff --git a/Examples/mzscheme/simple/example.i b/Examples/mzscheme/simple/example.i index 5b3e95580..24093b9bf 100644 --- a/Examples/mzscheme/simple/example.i +++ b/Examples/mzscheme/simple/example.i @@ -1,16 +1,7 @@ /* File : example.i */ %module example -%{ -/* Put headers and other declarations here */ -%} - -%include typemaps.i - -%rename(mod) my_mod; %inline %{ -extern double My_variable; -extern int fact(int); -extern int my_mod(int n, int m); -extern char *get_time(); +extern int gcd(int x, int y); +extern double Foo; %} diff --git a/Examples/mzscheme/simple/runme.scm b/Examples/mzscheme/simple/runme.scm index 181635078..88d32d6fc 100644 --- a/Examples/mzscheme/simple/runme.scm +++ b/Examples/mzscheme/simple/runme.scm @@ -2,23 +2,30 @@ (load-extension "example.so") -(display (get-time)) +; Call our gcd() function -(printf "My-variable = ~a~n" (My-variable)) +(define x 42) +(define y 105) +(define g (gcd x y)) +(display "The gcd of ") +(display x) +(display " and ") +(display y) +(display " is ") +(display g) +(newline) -(let loop ((i 0)) - (when (< i 14) (begin (display i) - (display " factorial is ") - (display (fact i)) - (newline) - (loop (+ i 1))))) +; Manipulate the Foo global variable -(let loop ((i 1)) - (when (< i 250) - (begin - (let loopi ((j 1)) - (when (< j 250) (begin (My-variable (+ (My-variable) (mod i j))) - (loopi (+ j 1))))) - (loop (+ i 1))))) +; Output its current value +(display "Foo = ") +(display (Foo)) +(newline) -(printf "My-variable = ~a~n" (My-variable)) +; Change its value +(Foo 3.1415926) + +; See if the change took effect +(display "Foo = ") +(display (Foo)) +(newline) From 4bb0b974c0e23c22e0882104b661ab97450ce171 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 17:14:46 +0000 Subject: [PATCH 08/14] Mzscheme out of source examples fixes --- Examples/Makefile.in | 6 +++--- Examples/mzscheme/class/Makefile | 2 +- Examples/mzscheme/std_vector/Makefile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 450824400..c5dcb1ee1 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -813,7 +813,7 @@ MZSCHEME = mzscheme MZC = @MZC@ MZDYNOBJ = @MZDYNOBJ@ MZSCHEME_SO = @MZSCHEME_SO@ -MZSCHEME_SCRIPT = $(RUNME).scm +MZSCHEME_SCRIPT = $(SRCDIR)$(RUNME).scm # ---------------------------------------------------------------- # Build a C/C++ dynamically loadable module @@ -821,12 +821,12 @@ MZSCHEME_SCRIPT = $(RUNME).scm mzscheme: $(SRCDIR_SRCS) $(SWIG) -mzscheme $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) - $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ISRCS) $(SRCDIR_SRCS) + $(COMPILETOOL) $(MZC) `echo $(CPPFLAGS) $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ISRCS) $(SRCDIR_SRCS) $(COMPILETOOL) $(MZC) --ld $(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) mzscheme_cpp: $(SRCDIR_SRCS) $(SWIG) -mzscheme -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) - $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) + $(COMPILETOOL) $(MZC) `echo $(CPPFLAGS) $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(CXXSHARED) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) # ----------------------------------------------------------------- diff --git a/Examples/mzscheme/class/Makefile b/Examples/mzscheme/class/Makefile index ee92aa9f1..0b36a60d7 100644 --- a/Examples/mzscheme/class/Makefile +++ b/Examples/mzscheme/class/Makefile @@ -10,7 +10,7 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(CXXSRCDIR)' CXXSRCS='$(CXXSRCS)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile index 4cf839a08..8057465b3 100644 --- a/Examples/mzscheme/std_vector/Makefile +++ b/Examples/mzscheme/std_vector/Makefile @@ -10,7 +10,7 @@ check: build $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCDIR='$(CXXSRCDIR)' CXXSRCS='$(CXXSRCS)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp From a2db2a6e27d87534db26addca330c769a10de1a3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 17:34:02 +0000 Subject: [PATCH 09/14] Format mzscheme help output Also simplify -dynamic-load option help as it does more than not emit scheme_initialize, scheme_reload, scheme_module_name. --- Source/Modules/mzscheme.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index 1df5ae0fb..23be87d0f 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -17,12 +17,10 @@ static const char *usage = "\ Mzscheme Options (available with -mzscheme)\n\ - -declaremodule - Create extension that declares a module\n\ - -dynamic-load ,[library,...] - Do not link with these libraries, dynamic load\n\ - them\n\ - -noinit - Do not emit scheme_initialize, scheme_reload,\n\ - scheme_module_name functions\n\ - -prefix - Set a prefix to be prepended to all names\n\ + -declaremodule - Create extension that declares a module\n\ + -dynamic-load ,[lib,...] - Do not link with these libraries, dynamic load them\n\ + -noinit - Do not emit module initialization code\n\ + -prefix - Set a prefix to be prepended to all names\n\ "; static String *fieldnames_tab = 0; From f7648051fd608c9fb5756e01ef5215673c34a1c5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 17:45:59 +0000 Subject: [PATCH 10/14] Add mzscheme to Travis testing This is an experimental language so needs to go under allow_failures. --- .travis.yml | 11 +++++++++++ Tools/travis-linux-install.sh | 3 +++ 2 files changed, 14 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3368493ad..c669f0b05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -94,6 +94,11 @@ matrix: env: SWIGLANG=lua VER=5.3 sudo: required dist: trusty + - compiler: gcc + os: linux + env: SWIGLANG=mzscheme + sudo: required + dist: trusty - compiler: gcc os: linux env: SWIGLANG=ocaml @@ -384,6 +389,12 @@ matrix: env: SWIGLANG=octave SWIGJOBS=-j2 VER=4.4 CPP11=1 sudo: required dist: trusty + # Experimental languages + - compiler: gcc + os: linux + env: SWIGLANG=mzscheme + sudo: required + dist: trusty before_install: - date -u diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index caf53dbc1..dc8526546 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -72,6 +72,9 @@ case "$SWIGLANG" in travis_retry sudo apt-get -qq install lua${VER} liblua${VER}-dev fi ;; + "mzscheme") + travis_retry sudo apt-get -qq install racket + ;; "ocaml") # configure also looks for ocamldlgen, but this isn't packaged. But it isn't used by default so this doesn't matter. travis_retry sudo apt-get -qq install ocaml ocaml-findlib From b4257fb1f2dbbc609df031944d704b5ad6bb1a6c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 17:58:06 +0000 Subject: [PATCH 11/14] Mark MzScheme as an experimental language --- Doc/Manual/SWIG.html | 2 +- Source/Modules/swigmain.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 365cd2940..be6eda739 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -125,7 +125,6 @@ Supported Target Language Options -java - Generate Java wrappers -javascript - Generate Javascript wrappers -lua - Generate Lua wrappers - -mzscheme - Generate Mzscheme wrappers -ocaml - Generate Ocaml wrappers -octave - Generate Octave wrappers -perl5 - Generate Perl 5 wrappers @@ -138,6 +137,7 @@ Supported Target Language Options -xml - Generate XML wrappers Experimental Target Language Options + -mzscheme - Generate MzScheme/Racket wrappers General Options -addextern - Add extra extern declarations diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx index 472264c26..a9916ad9a 100644 --- a/Source/Modules/swigmain.cxx +++ b/Source/Modules/swigmain.cxx @@ -63,7 +63,7 @@ static TargetLanguageModule modules[] = { {"-javascript", swig_javascript, "Javascript", Supported}, {"-lua", swig_lua, "Lua", Supported}, {"-modula3", NULL, "Modula 3", Disabled}, - {"-mzscheme", swig_mzscheme, "Mzscheme", Supported}, + {"-mzscheme", swig_mzscheme, "MzScheme/Racket", Experimental}, {"-ocaml", swig_ocaml, "Ocaml", Supported}, {"-octave", swig_octave, "Octave", Supported}, {"-perl", swig_perl5, NULL, Supported}, From c06dba6b582e748b2be8065469b82c4e2a6e7b02 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 20:31:27 +0000 Subject: [PATCH 12/14] Suppress experimental language warning when running the test-suite --- Examples/test-suite/mzscheme/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/mzscheme/Makefile.in b/Examples/test-suite/mzscheme/Makefile.in index 5eacb10e3..e6e5662b3 100644 --- a/Examples/test-suite/mzscheme/Makefile.in +++ b/Examples/test-suite/mzscheme/Makefile.in @@ -72,7 +72,7 @@ multi_import \ include $(srcdir)/../common.mk # Overridden variables here -# none! +SWIGOPT += -w524 # Suppress SWIGWARN_LANG_EXPERIMENTAL warning # Custom tests - tests with additional commandline options # none! From 3e4b0aace888af989e390cf5d6b81788583de7de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 18:02:55 +0000 Subject: [PATCH 13/14] Terminology correction in html docs --- Doc/Manual/Extending.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 53c2e68ae..7b2e61e21 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3626,7 +3626,7 @@ A target language is given the 'Experimental' status when
  • - It is of sub-standard quality, failing to meet the above 'Standard' status. + It is of sub-standard quality, failing to meet the above 'Supported' status.
  • It is somewhere between the mid to mature stage of development. @@ -3652,7 +3652,7 @@ Some minimum requirements and notes about languages with the 'Experimental' stat Have fully functional examples of basic functionality (the simple and class examples).
  • - The test-suite must be implemented and include some runtime tests for wrapped C and C++ tests. + The test-suite must be implemented and include a few runtime tests for both C and C++ test cases.
  • Failing tests must be put into one of the FAILING_CPP_TESTS or FAILING_C_TESTS lists in the test-suite. @@ -3668,7 +3668,7 @@ Some minimum requirements and notes about languages with the 'Experimental' stat Any new failed tests will be fixed on a 'best effort' basis by core developers with no promises made.
  • - If a language module has an official maintainer, then the maintainer will be requested to focus on fixing test-suite regressions and commit to migrating the module to become a 'Standard' module. + If a language module has an official maintainer, then the maintainer will be requested to focus on fixing test-suite regressions and commit to migrating the module to become a 'Supported' module.
  • If a module does not have an official maintainer, then, as maintenance will be on a 'best efforts' basis by the core maintainers, no guarantees will be provided from one release to the next and regressions may creep in. From 454c1f1aa4237265fa8d59b68c3b6aa31f180626 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 9 Feb 2019 18:46:38 +0000 Subject: [PATCH 14/14] Fix mzscheme name and unions testcases --- Examples/test-suite/mzscheme/Makefile.in | 2 -- Examples/test-suite/mzscheme/name_runme.scm | 2 +- Examples/test-suite/mzscheme/unions_runme.scm | 6 ++++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/mzscheme/Makefile.in b/Examples/test-suite/mzscheme/Makefile.in index e6e5662b3..4338b9b1f 100644 --- a/Examples/test-suite/mzscheme/Makefile.in +++ b/Examples/test-suite/mzscheme/Makefile.in @@ -61,10 +61,8 @@ valuewrapper_opaque \ FAILING_C_TESTS = \ enums \ integers \ -name \ preproc_constants_c \ preproc_line_file \ -unions \ FAILING_MULTI_CPP_TESTS = \ multi_import \ diff --git a/Examples/test-suite/mzscheme/name_runme.scm b/Examples/test-suite/mzscheme/name_runme.scm index 1782c6481..94df9131d 100644 --- a/Examples/test-suite/mzscheme/name_runme.scm +++ b/Examples/test-suite/mzscheme/name_runme.scm @@ -1,7 +1,7 @@ ;; The SWIG modules have "passive" Linkage, i.e., they don't generate ;; Guile modules (namespaces) but simply put all the bindings into the ;; current module. That's enough for such a simple test. -(load-extension "./name.so") +(load-extension "name.so") (foo-2) bar-2 diff --git a/Examples/test-suite/mzscheme/unions_runme.scm b/Examples/test-suite/mzscheme/unions_runme.scm index c44847cfc..1c39cb94c 100644 --- a/Examples/test-suite/mzscheme/unions_runme.scm +++ b/Examples/test-suite/mzscheme/unions_runme.scm @@ -25,13 +25,15 @@ (if (not (= Jill1 200)) (begin (display "Runtime test 1 failed.") - (exit 1)))) + (exit 1)) + (void))) (let ((Num1 (EmbeddedUnionTest-number-get eut))) (if (not (= Num1 1)) (begin (display "Runtime test 2 failed.") - (exit 1)))) + (exit 1)) + (void))) ;; that should do