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);