More work on the chicken module. The test suite, zlib, and overload examples are still broken.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6610 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2004-11-02 02:50:30 +00:00
commit 2cdf91de5d
17 changed files with 305 additions and 181 deletions

View file

@ -5,16 +5,16 @@ SRCS =
CXXSRCS = example.cxx
TARGET = class
INCLUDE =
SWIGOPT =
SWIGOPT =
CFLAGS =
VARIANT =
VARIANT = _csc
# 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
all:: $(TARGET)
all:: $(TARGET) $(TARGET)_proxy
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
@ -22,10 +22,17 @@ $(TARGET): $(INTERFACE) $(SRCS)
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
$(TARGET)_proxy: $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f example.scm
rm -f $(TARGET)
check::
csi -batch $(TARGET).so test-lowlevel-class.scm test-tinyclos-class.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-lowlevel-class.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-tinyclos-class.scm

View file

@ -5,12 +5,6 @@
#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

@ -1,16 +1,17 @@
;; This file illustrates the low-level C++ interface generated
;; by SWIG.
(load-library 'example "class.so")
(declare (uses example))
;; ----- Object creation -----
(display "Creating some objects:\n")
(define c (example:new-Circle 10.0))
(define c (new-Circle 10.0))
(display " Created circle ")
(display c)
(display "\n")
(define s (example:new-Square 10.0))
(define s (new-Square 10.0))
(display " Created square ")
(display s)
(display "\n")
@ -18,29 +19,29 @@
;; ----- Access a static member -----
(display "\nA total of ")
(display (example:Shape-nshapes))
(display (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)
(Shape-x-set c 20.0)
(Shape-y-set c 30.0)
(example:Shape-x-set s -10.0)
(example:Shape-y-set s 5.0)
(Shape-x-set s -10.0)
(Shape-y-set s 5.0)
(display "\nHere is their current position:\n")
(display " Circle = (")
(display (example:Shape-x-get c))
(display (Shape-x-get c))
(display ", ")
(display (example:Shape-y-get c))
(display (Shape-y-get c))
(display ")\n")
(display " Square = (")
(display (example:Shape-x-get s))
(display (Shape-x-get s))
(display ", ")
(display (example:Shape-y-get s))
(display (Shape-y-get s))
(display ")\n")
;; ----- Call some methods -----
@ -52,10 +53,10 @@
(display o)
(display "\n")
(display " area = ")
(display (example:Shape-area o))
(display (Shape-area o))
(display "\n")
(display " perimeter = ")
(display (example:Shape-perimeter o))
(display (Shape-perimeter o))
(display "\n"))))
(disp c)
(disp s))
@ -63,10 +64,12 @@
(display "\nGuess I'll clean up now\n")
;; Note: this invokes the virtual destructor
(example:delete-Shape c)
(example:delete-Shape s)
(delete-Shape c)
(delete-Shape s)
(set! s 3)
(display (example:Shape-nshapes))
(display (Shape-nshapes))
(display " shapes remain\n")
(display "Goodbye\n")
(exit)

View file

@ -1,23 +1,18 @@
;; This file illustrates the shadow C++ interface generated
;; by SWIG.
(load-library 'example "class_proxy.so")
(declare (uses example))
(declare (uses tinyclos))
;; 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))
(define c (make <Circle> 10.0))
(display " Created circle ")
(display c)
(display "\n")
(define s (make <example:Square> 10.0))
(define s (make <Square> 10.0))
(display " Created square ")
(display s)
(display "\n")
@ -25,29 +20,29 @@
;; ----- Access a static member -----
(display "\nA total of ")
(display (+example:Shape-nshapes+))
(display (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)
(slot-set! c 'x 20.0)
(slot-set! c 'y 30.0)
(-set-x!- s -10.0)
(-set-y!- s 5.0)
(slot-set! s 'x -10.0)
(slot-set! s 'y 5.0)
(display "\nHere is their current position:\n")
(display " Circle = (")
(display (-get-x- c))
(display (slot-ref c 'x))
(display ", ")
(display (-get-y- c))
(display (slot-ref c 'y))
(display ")\n")
(display " Square = (")
(display (-get-x- s))
(display (slot-ref s 'x))
(display ", ")
(display (-get-y- s))
(display (slot-ref s 'y))
(display ")\n")
;; ----- Call some methods -----
@ -59,10 +54,10 @@
(display o)
(display "\n")
(display " area = ")
(display (-area- o))
(display (area o))
(display "\n")
(display " perimeter = ")
(display (-perimeter- o))
(display (perimeter o))
(display "\n"))))
(disp c)
(disp s))
@ -72,8 +67,10 @@
;; Note: Invoke the virtual destructors by forcing garbage collection
(set! c 77)
(set! s 88)
(gc #t)
;(gc #t)
(display (+example:Shape-nshapes+))
(display (nshapes))
(display " shapes remain\n")
(display "Goodbye\n")
(exit)

View file

@ -23,8 +23,8 @@ $(TARGET): $(INTERFACE) $(SRCS)
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f example.scm
rm -f $(TARGET)
check::
csi -batch $(TARGET).so test-constants.scm
csi test-constants.scm

View file

@ -1,17 +1,18 @@
;; run with './constants test-constants.scm'
;; feel free to uncomment and comment sections
(load-library 'example "constants.so")
(declare (uses example))
(display "starting test ... you will see 'finished' if successful.\n")
(or (= (example:ICONST) 42) (exit 1))
(or (< (abs (- (example:FCONST) 2.1828)) 0.00001) (exit 1))
(or (char=? (example:CCONST) #\x) (exit 1))
(or (char=? (example:CCONST2) #\newline) (exit 1))
(or (string=? (example:SCONST) "Hello World") (exit 1))
(or (string=? (example:SCONST2) "\"Hello World\"") (exit 1))
(or (< (abs (- (example:EXPR) (+ (example:ICONST) (* 3 (example:FCONST))))) 0.00001) (exit 1))
(or (= (example:iconstX) 37) (exit 1))
(or (< (abs (- (example:fconstX) 3.14)) 0.00001) (exit 1))
(or (= (ICONST) 42) (exit 1))
(or (< (abs (- (FCONST) 2.1828)) 0.00001) (exit 1))
(or (char=? (CCONST) #\x) (exit 1))
(or (char=? (CCONST2) #\newline) (exit 1))
(or (string=? (SCONST) "Hello World") (exit 1))
(or (string=? (SCONST2) "\"Hello World\"") (exit 1))
(or (< (abs (- (EXPR) (+ (ICONST) (* 3 (FCONST))))) 0.00001) (exit 1))
(or (= (iconstX) 37) (exit 1))
(or (< (abs (- (fconstX) 3.14)) 0.00001) (exit 1))
(display "finished test.\n")
(exit 0)

View file

@ -23,8 +23,8 @@ $(TARGET): $(INTERFACE) $(SRCS)
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f example.scm
rm -f $(TARGET)
check::
csi -batch $(TARGET).so test-multimap.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-multimap.scm

View file

@ -1,56 +1,59 @@
;; run with './multimap test-multimap.scm'
;; feel free to uncomment and comment sections
(load-library 'example "multimap.so")
(declare (uses example))
(display "(example:gcd 90 12): ")
(display (example:gcd 90 12))
(display "(gcd 90 12): ")
(display (gcd 90 12))
(display "\n")
(display "(example:gcd 90 'a): ")
;;(display (example:gcd 90 'a))
(display "(gcd 90 'a): ")
;;(display (gcd 90 'a))
(display "\n")
(display "(example:gcd 'b 12): ")
;;(display (example:gcd 'b 12))
(display "(gcd 'b 12): ")
;;(display (gcd 'b 12))
(display "\n")
(display "(example:circle 0.5 0.5): ")
(example:circle 0.5 0.5)
(display "(circle 0.5 0.5): ")
(circle 0.5 0.5)
(display "\n")
(display "(example:circle 1.0 1.0): ")
;;(example:circle 1.0 1.0)
(display "(circle 1.0 1.0): ")
;;(circle 1.0 1.0)
(display "\n")
(display "(example:circle 1 1): ")
;;(example:circle 1 1)
(display "(circle 1 1): ")
;;(circle 1 1)
(display "\n")
(display "(example:capitalize \"will this be all capital letters?\"): ")
(display (example:capitalize "will this be all capital letters?"))
(display "(capitalize \"will this be all capital letters?\"): ")
(display (capitalize "will this be all capital letters?"))
(display "\n")
(display "(example:capitalize 'a): ")
;;(display (example:capitalize 'a))
(display "(capitalize 'a): ")
;;(display (capitalize 'a))
(display "\n")
(display "(example:count \"jumpity little spider\" #\\t): ")
(display (example:count "jumpity little spider" #\t))
(display "(count \"jumpity little spider\" #\\t): ")
(display (count "jumpity little spider" #\t))
(display "\n")
(display "(example:gcdmain '#(\"hi\" \"there\")): ")
(display (example:gcdmain '#("hi" "there")))
(display "(gcdmain '#(\"hi\" \"there\")): ")
(display (gcdmain '#("hi" "there")))
(display "\n")
(display "(example:gcdmain '#(\"gcd\" \"9\" \"28\")): ")
(example:gcdmain '#("gcd" "9" "28"))
(display "(gcdmain '#(\"gcd\" \"9\" \"28\")): ")
(gcdmain '#("gcd" "9" "28"))
(display "\n")
(display "(example:gcdmain '#(\"gcd\" \"12\" \"90\")): ")
(example:gcdmain '#("gcd" "12" "90"))
(display "(gcdmain '#(\"gcd\" \"12\" \"90\")): ")
(gcdmain '#("gcd" "12" "90"))
(display "\n")
(display "(example:squarecubed 3: ")
(display (example:squareCubed 3))
(display "(squarecubed 3: ")
(display (squareCubed 3))
(display "\n")
(exit)

View file

@ -5,7 +5,7 @@ SRCS =
CXXSRCS = example.cxx
TARGET = overload
INCLUDE =
SWIGOPT =
SWIGOPT = -proxy -unhideprimitive
CFLAGS =
VARIANT =
@ -23,8 +23,8 @@ $(TARGET): $(INTERFACE) $(SRCS)
clean::
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f example.scm
rm -f $(TARGET)
check::
csi -batch $(TARGET).so test-overload.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm

View file

@ -1,5 +1,6 @@
;; This file demonstrates the overloading capabilities of SWIG
(load-library 'example "overload.so")
(declare (uses example))
(declare (uses tinyclos))
@ -8,42 +9,39 @@
(display "
Trying low level code ...
(example:foo 1)
(example:foo \"some string\")
(define A-FOO (example:new-Foo))
(define ANOTHER-FOO (example:new-Foo A-FOO)) ;; copy constructor
(example:Foo-bar A-FOO 2)
(example:Foo-bar ANOTHER-FOO \"another string\" 3)
(foo 1)
(foo \"some string\")
(define A-FOO (new-Foo))
(define ANOTHER-FOO (new-Foo A-FOO)) ;; copy constructor
(Foo-bar A-FOO 2)
(Foo-bar ANOTHER-FOO \"another string\" 3)
")
(example:foo 1)
(example:foo "some string")
(define A-FOO (example:new-Foo))
(define ANOTHER-FOO (example:new-Foo A-FOO)) ;; copy constructor
(example:Foo-bar A-FOO 2)
(example:Foo-bar ANOTHER-FOO "another string" 3)
(primitive:foo 1)
(primitive:foo "some string")
(define A-FOO (slot-ref (primitive:new-Foo) 'swig-this))
(define ANOTHER-FOO (slot-ref (primitive:new-Foo A-FOO) 'swig-this)) ;; copy constructor
(primitive:Foo-bar A-FOO 2)
(primitive:Foo-bar ANOTHER-FOO "another string" 3)
;; TinyCLOS
;; --------
(display "
Trying TinyCLOS code ...
(+example:foo+ 1)
(+example:foo+ \"some string\")
(define A-FOO (make <example:Foo>))
(define ANOTHER-FOO (make <example:Foo> A-FOO)) ;; copy constructor
(+foo+ 1)
(+foo+ \"some string\")
(define A-FOO (make <Foo>))
(define ANOTHER-FOO (make <Foo> A-FOO)) ;; copy constructor
(-bar- A-FOO 2)
(-bar- ANOTHER-FOO \"another string\" 3)
")
;; ALL generic methods must be included first
(include "example-generic")
;; After generic methods are defined, can include TinyCLOS code
(include "example-clos")
(foo 1)
(foo "some string")
(define A-FOO (make <Foo>))
(define ANOTHER-FOO (make <Foo> (slot-ref A-FOO 'swig-this))) ;; copy constructor
(bar A-FOO 2)
(bar ANOTHER-FOO "another string" 3)
(+example:foo+ 1)
(+example:foo+ "some string")
(define A-FOO (make <example:Foo>))
(define ANOTHER-FOO (make <example:Foo> A-FOO)) ;; copy constructor
(-bar- A-FOO 2)
(-bar- ANOTHER-FOO "another string" 3)
(exit)

View file

@ -27,4 +27,4 @@ clean::
rm -f $(TARGET)
check::
csi -batch simple.so test-simple.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-simple.scm

View file

@ -1,43 +1,46 @@
;; feel free to uncomment and comment sections
(load-library 'example "simple.so")
(declare (uses example))
(display "(example:My-variable): ")
(display (example:My-variable))
(display "(My-variable): ")
(display (My-variable))
(display "\n")
(display "(example:My-variable 3.141259): ")
(display (example:My-variable 3.141259))
(display "(My-variable 3.141259): ")
(display (My-variable 3.141259))
(display "\n")
(display "(example:My-variable): ")
(display (example:My-variable))
(display "(My-variable): ")
(display (My-variable))
(display "\n")
(display "(example:My-variable 'a): ")
;;(display (example:My-variable 'a))
(display "(My-variable 'a): ")
;;(display (My-variable 'a))
(display "\n")
(display "(example:My-variable 1.5 'b): ")
(display (example:My-variable 1.5 'b))
(display "(My-variable 1.5 'b): ")
(display (My-variable 1.5 'b))
(display "\n")
(display "(example:fact 5): ")
(display (example:fact 5))
(display "(fact 5): ")
(display (fact 5))
(display "\n")
(display "(example:fact 'a): ")
;;(display (example:fact 'a))
(display "(fact 'a): ")
;;(display (fact 'a))
(display "\n")
(display "(example:mod 75 7): ")
(display (example:mod 75 7))
(display "(mod 75 7): ")
(display (mod 75 7))
(display "\n")
(display "(example:my-mod 75 7): ")
(display (example:my-mod 75 7))
(display "(my-mod 75 7): ")
(display (my-mod 75 7))
(display "\n")
(display "(example:get-time): ")
(display (example:get-time))
(display "(get-time): ")
(display (get-time))
(display "\n")
(exit)

View file

@ -6,4 +6,15 @@
(if (not (= (slot-ref f 'dummy) 14))
(error "Bad dummy value"))
(define f2 (makeFoo))
(slot-set! f2 'dummy 16)
(if (not (= (slot-ref f2 'dummy) 16))
(error "Bad dummy value for f2"))
(set! f #f)
(set! f2 #f)
(gc)
(exit 0)