update swig on windows
This commit is contained in:
5
winx64/bin/swigwin-4.0.0/Examples/mzscheme/check.list
Normal file
5
winx64/bin/swigwin-4.0.0/Examples/mzscheme/check.list
Normal file
@@ -0,0 +1,5 @@
|
||||
# see top-level Makefile.in
|
||||
class
|
||||
multimap
|
||||
simple
|
||||
std_vector
|
||||
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/class/Makefile
Normal file
18
winx64/bin/swigwin-4.0.0/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='$(SRCDIR)' 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
winx64/bin/swigwin-4.0.0/Examples/mzscheme/class/example.cxx
Normal file
28
winx64/bin/swigwin-4.0.0/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
winx64/bin/swigwin-4.0.0/Examples/mzscheme/class/example.h
Normal file
34
winx64/bin/swigwin-4.0.0/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();
|
||||
};
|
||||
@@ -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
winx64/bin/swigwin-4.0.0/Examples/mzscheme/class/runme.scm
Normal file
60
winx64/bin/swigwin-4.0.0/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)
|
||||
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/multimap/Makefile
Normal file
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/multimap/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
|
||||
|
||||
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
|
||||
@@ -0,0 +1,53 @@
|
||||
/* File : example.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* 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 gcdmain(int argc, char *argv[]) {
|
||||
int x,y;
|
||||
if (argc != 3) {
|
||||
printf("usage: gcd x y\n");
|
||||
return -1;
|
||||
}
|
||||
x = atoi(argv[1]);
|
||||
y = atoi(argv[2]);
|
||||
printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int charcount(char *bytes, int len, char c) {
|
||||
int i;
|
||||
int count = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (bytes[i] == c) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void capitalize(char *str, int len) {
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i] = (char)toupper(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void circle(double x, double y) {
|
||||
double a = x*x + y*y;
|
||||
if (a > 1.0) {
|
||||
printf("Bad points %g, %g\n", x,y);
|
||||
} else {
|
||||
printf("Good points %g, %g\n", x,y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
extern int gcd(int x, int y);
|
||||
extern int gcdmain(int argc, char *argv[]);
|
||||
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);
|
||||
%}
|
||||
|
||||
%include exception.i
|
||||
%include typemaps.i
|
||||
|
||||
extern int gcd(int x, int y);
|
||||
|
||||
%typemap(in) (int argc, char *argv[]) {
|
||||
int i;
|
||||
Scheme_Object **elms;
|
||||
if (!SCHEME_VECTORP($input)) {
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$1 = SCHEME_VEC_SIZE($input);
|
||||
elms = SCHEME_VEC_ELS($input);
|
||||
if ($1 == 0) {
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
||||
for (i = 0; i < $1; i++) {
|
||||
if (!SCHEME_STRINGP(elms[i])) {
|
||||
free($2);
|
||||
scheme_wrong_type("$name","vector",$argnum,argc,argv);
|
||||
}
|
||||
$2[i] = SCHEME_STR_VAL(elms[i]);
|
||||
}
|
||||
$2[i] = 0;
|
||||
}
|
||||
|
||||
%typemap(freearg) (int argc, char *argv[]) {
|
||||
free($2);
|
||||
}
|
||||
extern int gcdmain(int argc, char *argv[]);
|
||||
|
||||
%typemap(in) (char *bytes, int len) {
|
||||
if (!SCHEME_STRINGP($input)) {
|
||||
scheme_wrong_type("$name","string",1,argc,argv);
|
||||
}
|
||||
$1 = SCHEME_STR_VAL($input);
|
||||
$2 = SCHEME_STRLEN_VAL($input);
|
||||
}
|
||||
|
||||
extern int charcount(char *bytes, int len, char c);
|
||||
|
||||
|
||||
/* This example shows how to wrap a function that mutates a string */
|
||||
|
||||
%typemap(in) (char *str, int len) {
|
||||
if (!SCHEME_STRINGP($input)) {
|
||||
scheme_wrong_type("$name","string",1,argc,argv);
|
||||
}
|
||||
$2 = SCHEME_STRLEN_VAL($input);
|
||||
$1 = (char *) malloc($2+1);
|
||||
memmove($1,SCHEME_STR_VAL($input),$2);
|
||||
}
|
||||
|
||||
/* Return the mutated string as a new object. */
|
||||
|
||||
%typemap(argout) (char *str, int len) {
|
||||
Scheme_Object *s;
|
||||
s = scheme_make_sized_string($1,$2);
|
||||
SWIG_APPEND_VALUE(s);
|
||||
free($1);
|
||||
}
|
||||
|
||||
extern void capitalize(char *str, int len);
|
||||
|
||||
/* A multi-valued constraint. Force two arguments to lie
|
||||
inside the unit circle */
|
||||
|
||||
%typemap(check) (double cx, double cy) {
|
||||
double a = $1*$1 + $2*$2;
|
||||
if (a > 1.0) {
|
||||
SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern void circle(double cx, double cy);
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
;; run with mzscheme -r runme.scm
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
; Call the GCD function
|
||||
|
||||
(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)
|
||||
|
||||
; Call the gcdmain() function
|
||||
(gcdmain #("gcdmain" "42" "105"))
|
||||
|
||||
|
||||
(display (charcount "Hello World" #\l))
|
||||
(newline)
|
||||
|
||||
(display (capitalize "hello world"))
|
||||
(newline)
|
||||
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/Makefile
Normal file
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
|
||||
|
||||
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
|
||||
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/example.c
Normal file
18
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/example.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
31
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/runme.scm
Normal file
31
winx64/bin/swigwin-4.0.0/Examples/mzscheme/simple/runme.scm
Normal file
@@ -0,0 +1,31 @@
|
||||
;; run with mzscheme -r runme.scm
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
; Call our gcd() function
|
||||
|
||||
(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)
|
||||
|
||||
; Manipulate the Foo global variable
|
||||
|
||||
; Output its current value
|
||||
(display "Foo = ")
|
||||
(display (Foo))
|
||||
(newline)
|
||||
|
||||
; Change its value
|
||||
(Foo 3.1415926)
|
||||
|
||||
; See if the change took effect
|
||||
(display "Foo = ")
|
||||
(display (Foo))
|
||||
(newline)
|
||||
@@ -0,0 +1,18 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' 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
|
||||
@@ -0,0 +1,25 @@
|
||||
/* File : example.h */
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
double average(std::vector<int> v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<double> half(const std::vector<double>& v) {
|
||||
std::vector<double> w(v);
|
||||
for (unsigned int i=0; i<w.size(); i++)
|
||||
w[i] /= 2.0;
|
||||
return w;
|
||||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
// would you believe this is the same as the above?
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include stl.i
|
||||
/* instantiate the required template specializations */
|
||||
namespace std {
|
||||
%template(IntVector) vector<int>;
|
||||
%template(DoubleVector) vector<double>;
|
||||
}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
;; run with mzscheme -r runme.scm
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
; repeatedly invoke a procedure with v and an index as arguments
|
||||
(define (with-vector v proc size-proc)
|
||||
(let ((size (size-proc v)))
|
||||
(define (with-vector-item v i)
|
||||
(if (< i size)
|
||||
(begin
|
||||
(proc v i)
|
||||
(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 (print-DoubleVector v)
|
||||
(with-DoubleVector v (lambda (v i) (display (DoubleVector-ref v i))
|
||||
(display " ")))
|
||||
(newline))
|
||||
|
||||
|
||||
; Call average with a Scheme list...
|
||||
|
||||
(display (average '(1 2 3 4)))
|
||||
(newline)
|
||||
|
||||
; ... or a wrapped std::vector<int>
|
||||
(define v (new-IntVector 4))
|
||||
(with-IntVector v (lambda (v i) (IntVector-set! v i (+ i 1))))
|
||||
(display (average v))
|
||||
(newline)
|
||||
(delete-IntVector v)
|
||||
|
||||
; half will return a Scheme vector.
|
||||
; Call it with a Scheme vector...
|
||||
|
||||
(display (half #(1 1.5 2 2.5 3)))
|
||||
(newline)
|
||||
|
||||
; ... or a wrapped std::vector<double>
|
||||
(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<double> in place
|
||||
(halve-in-place v)
|
||||
(print-DoubleVector v)
|
||||
(delete-DoubleVector v)
|
||||
Reference in New Issue
Block a user