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
This commit is contained in:
William S Fulton 2019-02-09 13:15:32 +00:00
commit 20344093ef
8 changed files with 151 additions and 24 deletions

View file

@ -1,4 +1,5 @@
# see top-level Makefile.in
class
multimap
simple
std_vector

View file

@ -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

View file

@ -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;
}

View file

@ -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();
};

View file

@ -0,0 +1,9 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

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

View file

@ -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 \

View file

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