Initial addition.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4313 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Jonah Beckford 2003-02-15 01:56:34 +00:00
commit 6901abdf17
70 changed files with 9710 additions and 0 deletions

View file

@ -0,0 +1,9 @@
*_wrap.c
*_wrap.cxx
*.dll
*.dsw
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -0,0 +1,59 @@
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
SOURCE_DIR = $(top_srcdir)/Examples/chicken/class
TOP = ../..
CC = @CC@
CXX = @CXX@
OBJEXT = @OBJEXT@
EXEEXT = @EXEEXT@
SWIG = $(TOP)/../swig$(EXEEXT)
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
oexample.$(OBJEXT)
CHICKSRC = csi.c precsi.c oexample.c
SRCS = $(CHICKGEN) $(SOURCE_DIR)/example.cxx
TARGET = class$(EXEEXT)
INCLUDE = -I$(SOURCE_DIR)
SWIGOPT =
all:: $(TARGET) example_generic.scm example_clos.scm
.SUFFIXES: .cxx
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
.cxx.o:
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
csi.c:
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
INTERFACE='precsi' chicken_csi
precsi.c: $(SOURCE_DIR)/precsi.scm
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
INTERFACE='$<' chicken
example_wrap.cxx example.scm example_generic.scm example_clos.scm: $(SOURCE_DIR)/example.i
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_cpp
oexample.c: example.scm
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
INTERFACE='$<' chicken
$(TARGET): $(SRCS)
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
INTERFACE='$(INTERFACE)' chicken_cpp_static
clean::
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
rm -f $(CHICKGEN) $(CHICKSRC)
rm -f example.scm example_generic.scm example_clos.scm
rm -f $(TARGET)
check: all

View file

@ -0,0 +1,28 @@
/* File : example.c */
#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(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}

View file

@ -0,0 +1,46 @@
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
enum SomeEnum {
First = 0,
Second,
Third,
Last = 1000
};
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -0,0 +1,16 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let "Shape" objects be converted back and forth from TinyCLOS into
low-level CHICKEN SWIG procedures */
%typemap(clos_in) Shape * = SIMPLE_CLOS_OBJECT *;
%typemap(clos_out) Shape * = SIMPLE_CLOS_OBJECT *;
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,105 @@
(declare (unit precsi))
(declare (uses example))
(if (not (member "-quiet" (cdr (argv))))
(begin
;; display prelude to csi
(display "class\n\n")
(display " A SWIG example for the CHICKEN compiler\n")
(display " Author: Jonah Beckford, December 2002\n\n")
(display "C++ Interface\n")
(display "-------------\n")
(display "
class Shape {
public:
Shape();
virtual ~Shape();
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
enum SomeEnum {
First = 0,
Second,
Third,
Last = 1000
};
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r);
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w);
virtual double area(void);
virtual double perimeter(void);
};
")
(display "\n")
(display "CHICKEN Low-Level Procedures\n")
(display "----------------------------\n")
(display "
(define A-CIRCLE-SHAPE (example-new-Circle %radius))
(example-Circle-area %circle)
(example-Circle-perimeter %circle)
(example-delete-Circle %circle)
(define A-SQUARE-SHAPE (example-new-Square %width))
(example-Square-area %square)
(example-Square-perimeter %square)
(example-delete-Square %square)
(example-delete-Shape %shape)
(example-Shape-x-set %shape %x)
(example-Shape-x-get %shape)
(example-Shape-y-set %shape %y)
(example-Shape-y-get %shape)
(example-Shape-move %shape %dx %dy)
(example-Shape-area %shape)
(example-Shape-perimeter %shape)
(example-Shape-nshapes)
(example-Shape-nshapes %nshapes-int)
(example-Shape-First)
(example-Shape-Second)
(example-Shape-Third)
(example-Shape-Last)
")
(display "\n")
(display "TinyCLOS Classes\n")
(display "----------------\n")
(display "
;; ALL generic methods must be included first
(include \"example_generic\")
;; After generic methods are defined, can include TinyCLOS code
(include \"example_clos\")
(define A-CIRCLE-SHAPE (make <example-Circle> %radius))
(-get-x- %shapeObject)
(-set-x!- %shapeObject %x)
(-get-y- %shapeObject)
(-set-y!- %shapeObject %y)
(-move!- %shapeObject %dx %dy)
(-area- %shapeObject)
(-perimeter- %shapeObject)
(+example-Shape-nshapes+)
(+example-Shape-nshapes+ %nshapes-int)
;; do not use (example-delete-Shape (slot-ref %shapeObject 'this))
;; as %shapeObject is always garbage-collected
")
(display "\n")))

View file

@ -0,0 +1,70 @@
;; This file illustrates the low-level C++ interface generated
;; by SWIG.
;; ----- Object creation -----
(display "Creating some objects:\n")
(define c (example-new-Circle 10.0))
(display " Created circle ")
(display c)
(display "\n")
(define s (example-new-Square 10.0))
(display " Created square ")
(display s)
(display "\n")
;; ----- Access a static member -----
(display "\nA total of ")
(display (example-Shape-nshapes))
(display " shapes were created\n")
;; ----- Member data access -----
;; Set the location of the object
(example-Shape-x-set c 20.0)
(example-Shape-y-set c 30.0)
(example-Shape-x-set s -10.0)
(example-Shape-y-set s 5.0)
(display "\nHere is their current position:\n")
(display " Circle = (")
(display (example-Shape-x-get c))
(display ", ")
(display (example-Shape-y-get c))
(display ")\n")
(display " Square = (")
(display (example-Shape-x-get s))
(display ", ")
(display (example-Shape-y-get s))
(display ")\n")
;; ----- Call some methods -----
(display "\nHere are some properties of the shapes:\n")
(let
((disp (lambda (o)
(display " ")
(display o)
(display "\n")
(display " area = ")
(display (example-Shape-area o))
(display "\n")
(display " perimeter = ")
(display (example-Shape-perimeter o))
(display "\n"))))
(disp c)
(disp s))
(display "\nGuess I'll clean up now\n")
;; Note: this invokes the virtual destructor
(example-delete-Shape c)
(example-delete-Shape s)
(set! s 3)
(display (example-Shape-nshapes))
(display " shapes remain\n")
(display "Goodbye\n")

View file

@ -0,0 +1,76 @@
;; This file illustrates the shadow C++ interface generated
;; by SWIG.
;; All generic methods must be included first
(include "example_generic")
;; After generic are defined, can include TinyCLOS code
(include "example_clos")
;; ----- Object creation -----
(display "Creating some objects:\n")
(define c (make <example-Circle> 10.0))
(display " Created circle ")
(display c)
(display "\n")
(define s (make <example-Square> 10.0))
(display " Created square ")
(display s)
(display "\n")
;; ----- Access a static member -----
(display "\nA total of ")
(display (+example-Shape-nshapes+))
(display " shapes were created\n")
;; ----- Member data access -----
;; Set the location of the object
(-set-x!- c 20.0)
(-set-y!- c 30.0)
(-set-x!- s -10.0)
(-set-y!- s 5.0)
(display "\nHere is their current position:\n")
(display " Circle = (")
(display (-get-x- c))
(display ", ")
(display (-get-y- c))
(display ")\n")
(display " Square = (")
(display (-get-x- s))
(display ", ")
(display (-get-y- s))
(display ")\n")
;; ----- Call some methods -----
(display "\nHere are some properties of the shapes:\n")
(let
((disp (lambda (o)
(display " ")
(display o)
(display "\n")
(display " area = ")
(display (-area- o))
(display "\n")
(display " perimeter = ")
(display (-perimeter- o))
(display "\n"))))
(disp c)
(disp s))
(display "\nGuess I'll clean up now\n")
;; Note: Invoke the virtual destructors by forcing garbage collection
(set! c 77)
(set! s 88)
(gc #t)
(display (+example-Shape-nshapes+))
(display " shapes remain\n")
(display "Goodbye\n")