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:
parent
b21a28f26a
commit
20344093ef
8 changed files with 151 additions and 24 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
# see top-level Makefile.in
|
# see top-level Makefile.in
|
||||||
|
class
|
||||||
multimap
|
multimap
|
||||||
simple
|
simple
|
||||||
std_vector
|
std_vector
|
||||||
|
|
|
||||||
18
Examples/mzscheme/class/Makefile
Normal file
18
Examples/mzscheme/class/Makefile
Normal 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
|
||||||
28
Examples/mzscheme/class/example.cxx
Normal file
28
Examples/mzscheme/class/example.cxx
Normal 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;
|
||||||
|
}
|
||||||
34
Examples/mzscheme/class/example.h
Normal file
34
Examples/mzscheme/class/example.h
Normal 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();
|
||||||
|
};
|
||||||
9
Examples/mzscheme/class/example.i
Normal file
9
Examples/mzscheme/class/example.i
Normal 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"
|
||||||
60
Examples/mzscheme/class/runme.scm
Normal file
60
Examples/mzscheme/class/runme.scm
Normal 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)
|
||||||
|
|
@ -12,7 +12,6 @@ top_builddir = @top_builddir@
|
||||||
|
|
||||||
FAILING_CPP_TESTS = \
|
FAILING_CPP_TESTS = \
|
||||||
allowexcept \
|
allowexcept \
|
||||||
allprotected \
|
|
||||||
apply_strings \
|
apply_strings \
|
||||||
arrays_dimensionless \
|
arrays_dimensionless \
|
||||||
arrays_global \
|
arrays_global \
|
||||||
|
|
@ -21,42 +20,30 @@ class_scope_weird \
|
||||||
constant_pointers \
|
constant_pointers \
|
||||||
cpp_basic \
|
cpp_basic \
|
||||||
cpp_enum \
|
cpp_enum \
|
||||||
cpp_namespace \
|
|
||||||
cpp_static \
|
|
||||||
curiously_recurring_template_pattern \
|
curiously_recurring_template_pattern \
|
||||||
default_arg_expressions \
|
default_arg_expressions \
|
||||||
default_args \
|
|
||||||
default_constructor \
|
default_constructor \
|
||||||
derived_nested \
|
derived_nested \
|
||||||
director_ignore \
|
director_ignore \
|
||||||
enum_thorough \
|
enum_thorough \
|
||||||
enum_var \
|
|
||||||
exception_order \
|
|
||||||
extend \
|
extend \
|
||||||
extend_constructor_destructor \
|
|
||||||
extern_c \
|
|
||||||
friends \
|
friends \
|
||||||
global_scope_types \
|
global_scope_types \
|
||||||
global_vars \
|
|
||||||
grouping \
|
|
||||||
inherit_member \
|
inherit_member \
|
||||||
li_attribute \
|
li_attribute \
|
||||||
li_attribute_template \
|
li_attribute_template \
|
||||||
li_boost_shared_ptr \
|
li_boost_shared_ptr \
|
||||||
li_boost_shared_ptr_bits \
|
|
||||||
li_std_combinations \
|
li_std_combinations \
|
||||||
li_std_map \
|
li_std_map \
|
||||||
li_std_pair \
|
li_std_pair \
|
||||||
li_std_pair_using \
|
li_std_pair_using \
|
||||||
li_std_string \
|
li_std_string \
|
||||||
li_std_vector \
|
li_std_vector \
|
||||||
li_swigtype_inout \
|
|
||||||
li_windows \
|
li_windows \
|
||||||
member_funcptr_galore \
|
member_funcptr_galore \
|
||||||
member_pointer \
|
member_pointer \
|
||||||
member_pointer_const \
|
member_pointer_const \
|
||||||
memberin_extend \
|
memberin_extend \
|
||||||
namespace_class \
|
|
||||||
namespace_spaces \
|
namespace_spaces \
|
||||||
naturalvar \
|
naturalvar \
|
||||||
naturalvar_more \
|
naturalvar_more \
|
||||||
|
|
@ -64,24 +51,14 @@ nested_class \
|
||||||
nested_template_base \
|
nested_template_base \
|
||||||
ordering \
|
ordering \
|
||||||
preproc_constants \
|
preproc_constants \
|
||||||
rename_predicates \
|
|
||||||
rename_simple \
|
|
||||||
samename \
|
samename \
|
||||||
smart_pointer_const_overload \
|
|
||||||
smart_pointer_member \
|
|
||||||
smart_pointer_template_const_overload \
|
|
||||||
static_const_member_2 \
|
|
||||||
swig_exception \
|
|
||||||
template_default2 \
|
template_default2 \
|
||||||
template_specialization_defarg \
|
template_specialization_defarg \
|
||||||
template_static \
|
|
||||||
template_typemaps \
|
template_typemaps \
|
||||||
typemap_variables \
|
typemap_variables \
|
||||||
valuewrapper_opaque \
|
valuewrapper_opaque \
|
||||||
|
|
||||||
FAILING_C_TESTS = \
|
FAILING_C_TESTS = \
|
||||||
c_delete \
|
|
||||||
enum_missing \
|
|
||||||
enums \
|
enums \
|
||||||
integers \
|
integers \
|
||||||
name \
|
name \
|
||||||
|
|
|
||||||
|
|
@ -527,7 +527,7 @@ public:
|
||||||
Replaceall(tm, "$source", "argv[0]");
|
Replaceall(tm, "$source", "argv[0]");
|
||||||
Replaceall(tm, "$target", name);
|
Replaceall(tm, "$target", name);
|
||||||
Replaceall(tm, "$input", "argv[0]");
|
Replaceall(tm, "$input", "argv[0]");
|
||||||
/* Printv(f->code, tm, "\n",NIL); */
|
Replaceall(tm, "$argnum", "1");
|
||||||
emit_action_code(n, f->code, tm);
|
emit_action_code(n, f->code, tm);
|
||||||
} else {
|
} else {
|
||||||
throw_unhandled_mzscheme_type_error(t);
|
throw_unhandled_mzscheme_type_error(t);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue