Initial addition.

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

View file

@ -0,0 +1,4 @@
gifguile
image.gif
simple-guile
simple_wrap.c

View file

@ -0,0 +1,61 @@
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
SOURCE_DIR = $(top_srcdir)/Examples/GIFPlot/Chicken/simple
TOP = ../../..
CC = @CC@
CXX = @CXX@
OBJEXT = @OBJEXT@
EXEEXT = @EXEEXT@
SWIG = $(TOP)/../swig$(EXEEXT)
CHICKGEN = simple_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
osimple.$(OBJEXT)
CHICKSRC = csi.c precsi.c osimple.c
SRCS = $(CHICKGEN)
TARGET = simple$(EXEEXT)
INCLUDE = -I$(SOURCE_DIR) -I../../Include
LIBS = -L../.. -lgifplot -lm
SWIGOPT = -I../../Include
all:: $(TARGET)
.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
simple_wrap.c simple.scm: $(SOURCE_DIR)/simple.i
(test $< -nt simple.i && cp -p $< simple.i) || echo simple.i is up-to-date
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
INCLUDE='$(INCLUDE)' INTERFACE='simple.i' chicken_c
osimple.c: simple.scm
$(MAKE) -f $(TOP)/Makefile TARGET='osimple.c' \
INTERFACE='$<' chicken
$(TARGET): $(SRCS)
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_static
clean::
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
rm -f $(CHICKGEN) $(CHICKSRC)
rm -f simple.scm
rm -f $(TARGET)
rm -f *.gif
check: all

View file

@ -0,0 +1,6 @@
This is a very minimalistic example in which just a few functions
and constants from library are wrapped and used to draw some simple
shapes.
`make' will build a version of CHICKEN which defines an additional
unit (simple). Run `./simple runme.scm' to test it.

View file

@ -0,0 +1,33 @@
...more...
/usr/local/share/chicken/src/csi.scm: 887 string-split
##sys#map
/usr/local/share/chicken/src/csi.scm: 914 load-verbose
/usr/local/share/chicken/src/csi.scm: 915 ##csi#print-banner
/usr/local/share/chicken/src/csi.scm: 113 printf
/usr/local/share/chicken/src/csi.scm: 920 collect-options
##sys#for-each
/usr/local/share/chicken/src/csi.scm: 921 collect-options
##sys#for-each
/usr/local/share/chicken/src/csi.scm: 924 collect-options
##sys#map
/usr/local/share/chicken/src/csi.scm: 924 append
/usr/local/share/chicken/src/csi.scm: 923 delete-duplicates
/usr/local/share/chicken/src/csi.scm: 929 provide
/usr/local/share/chicken/src/csi.scm: 899 getenv
/usr/local/share/chicken/src/csi.scm: 899 ##csi#chop-separator
/usr/local/share/chicken/src/csi.scm: 138 sub1
/usr/local/share/chicken/src/csi.scm: 900 string
/usr/local/share/chicken/src/csi.scm: 900 string-append
/usr/local/share/chicken/src/csi.scm: 901 file-exists?
/usr/local/share/chicken/src/csi.scm: 959 ##csi#make-transcript-port
/usr/local/share/chicken/src/csi.scm: 360 ##sys#make-port
/usr/local/share/chicken/src/csi.scm: 984 substring
/usr/local/share/chicken/src/csi.scm: 991 load
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
/usr/local/share/chicken/src/csi.scm: 129 old-hook
new-ColorMap
new-FrameBuffer
BLACK

View file

@ -0,0 +1,8 @@
(declare (unit precsi))
(declare (uses simple))
;; display prelude to csi
(display "simple\n\n")
(display " A SWIG GIFPlot example for the CHICKEN compiler\n")
(display " Author: Jonah Beckford, December 2002\n\n")

View file

@ -0,0 +1,34 @@
/* This example shows a very simple interface wrapping a few
primitive declarations */
%module simple
%{
#include "gifplot.h"
%}
typedef unsigned int Pixel;
/* Here are a few useful functions */
ColorMap *new_ColorMap(char *filename = 0);
void delete_ColorMap(ColorMap *cmap);
FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height);
void delete_FrameBuffer(FrameBuffer *frame);
void FrameBuffer_clear(FrameBuffer *frame, Pixel color);
void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color);
int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename);
/* And some useful constants, which we redefine (from gifplot.h) so
that SWIG sees them */
#define BLACK 0
#define WHITE 1
#define RED 2
#define GREEN 3
#define BLUE 4
#define YELLOW 5
#define CYAN 6
#define MAGENTA 7

View file

@ -0,0 +1,49 @@
;; -*- buffer-read-only: t -*- vi: set ro:
;; This file was created automatically by SWIG.
;; Don't modify this file, modify the SWIG interface instead.
(cond-expand ((or chicken-compile-shared shared)) (else (declare (unit simple))))
(declare
(hide swig-init)
(foreign-declare "C_extern void simple_swig_init(int,C_word,C_word) C_noret;"))
(define swig-init (##core#primitive "simple_swig_init"))
(swig-init)
(declare
(foreign-declare "C_extern int simple_swig_num_types (void);")
(foreign-declare "C_extern char* simple_swig_type_name (int);")
(foreign-declare "C_extern void* simple_swig_type_ptr (int);")
(foreign-declare "C_extern char* simple_swig_type_str (int);")
(foreign-declare "C_extern void simple_swig_type_tag (int, C_word);"))
(define-record swig-simple-tag class name ptr str)
(define-record-printer (swig-simple-tag tag out)
(fprintf out "#<tag ~S>(~A)" (swig-simple-tag-str tag)
(swig-simple-tag-ptr tag)))
(define swig-simple-tag-num
((foreign-lambda int "simple_swig_num_types")))
(define swig-simple-tags (make-vector swig-simple-tag-num #f))
(letrec
((gen
(lambda (l i)
(if (= i 0) (cons 0 l) (gen (cons i l) (- i 1))))))
(let ((indices (if (<= swig-simple-tag-num 0) (quote ())
(gen (quote ()) (- swig-simple-tag-num 1)))))
(for-each
(lambda (index)
(let
((tag
(make-swig-simple-tag
1000
((foreign-lambda
c-string "simple_swig_type_name" int) index)
((foreign-lambda
c-pointer "simple_swig_type_ptr" int) index)
((foreign-lambda
c-string "simple_swig_type_str" int) index))))
(vector-set! swig-simple-tags index tag)
((foreign-lambda void "simple_swig_type_tag"
int scheme-object) index tag)))
indices)))

View file

@ -0,0 +1,27 @@
;;; Draw some simple shapes
(display "Drawing some basic shapes\n")
(define cmap (simple-new-ColorMap #f))
(define f (simple-new-FrameBuffer 400 400))
;; Clear the picture
(simple-FrameBuffer-clear f (simple-BLACK))
;; Make a red box
(simple-FrameBuffer-box f 40 40 200 200 (simple-RED))
;; Make a blue circle
(simple-FrameBuffer-circle f 200 200 40 (simple-BLUE))
;; Make green line
(simple-FrameBuffer-line f 10 390 390 200 (simple-GREEN))
;; Write an image out to disk
(simple-FrameBuffer-writeGIF f cmap "image.gif")
(display "Wrote image.gif\n")
(simple-delete-FrameBuffer f)
(simple-delete-ColorMap cmap)