Rewrite chicken example and test-suite building code

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5948 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2004-05-30 07:11:26 +00:00
commit acd0b021b1
35 changed files with 315 additions and 844 deletions

View file

@ -1,49 +1,31 @@
TOP = ../..
SWIG = $(TOP)/../swig
INTERFACE = example.i
CHICKSRCS = precsi.c oexample.c
SRCS =
CXXSRCS = example_wrap.cxx example.cxx
CHICKGEN = $(CHICKSRCS) csi.c example_wrap.cxx
TARGET = class
INCLUDE =
SWIGOPT =
CFLAGS =
TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS =
CXXSRCS = example.cxx
TARGET = class
INCLUDE =
SWIGOPT =
CFLAGS =
VARIANT =
all:: $(TARGET) example-generic.scm example-clos.scm
# uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines)
#CHICKEN_MAIN = test-lowlevel-class.scm
#CHICKEN_MAIN = test-tinyclos-class.scm
#VARIANT = _static
csi.c:
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
INTERFACE='precsi' chicken_csi
all:: $(TARGET)
precsi.c: precsi.scm
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
INTERFACE='$<' chicken_chicken
example_wrap.cxx example.scm example-generic.scm example-clos.scm: example.i
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_swig_cpp
oexample.c: example.scm
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
INTERFACE='$<' chicken_chicken
$(TARGET): csi.c $(CHICKSRCS) $(SRCS) $(CXXSRCS)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
CHICKSRCS='$(CHICKSRCS)' SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' chicken_static_cpp
module:: $(CHICKSRCS) $(SRCS) $(CXXSRCS)
$(MAKE) -f $(TOP)/Makefile \
CHICKSRCS='$(CHICKSRCS)' SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='module' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' chicken_module_cpp
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f $(CHICKGEN)
rm -f example.scm example-generic.scm example-clos.scm
rm -f $(TARGET)
check:: module
check::
csi -batch $(TARGET).so test-lowlevel-class.scm test-tinyclos-class.scm

View file

@ -1,105 +0,0 @@
(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

@ -1,6 +1,8 @@
;; This file illustrates the low-level C++ interface generated
;; by SWIG.
(declare (uses example))
;; ----- Object creation -----
(display "Creating some objects:\n")

View file

@ -1,6 +1,9 @@
;; This file illustrates the shadow C++ interface generated
;; by SWIG.
(declare (uses example))
(declare (uses tinyclos))
;; All generic methods must be included first
(include "example-generic")