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 @@
example_wrap.c

View file

@ -0,0 +1,59 @@
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
SOURCE_DIR = $(top_srcdir)/Examples/chicken/simple
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.c
TARGET = simple$(EXEEXT)
INCLUDE = -I$(SOURCE_DIR)
SWIGOPT =
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
example_wrap.c example.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_c
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_static
clean::
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
rm -f $(CHICKGEN) $(CHICKSRC)
rm -f example.scm
rm -f $(TARGET)
check: all

View file

@ -0,0 +1 @@
Simple example from users manual.

View file

@ -0,0 +1,24 @@
/* Simple example from documentation */
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
/* Compute factorial of n */
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
/* Compute n mod m */
int my_mod(int n, int m) {
return (n % m);
}
char *get_time() {
long ltime;
time(&ltime);
return ctime(&ltime);
}

View file

@ -0,0 +1,13 @@
/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
%}
%include typemaps.i
extern double My_variable;
extern int fact(int);
%name(mod) extern int my_mod(int n, int m);
extern int my_mod(int n, int m);
extern char *get_time();

View file

@ -0,0 +1,25 @@
(declare (unit precsi))
(declare (uses example))
;; display prelude to csi
(display "simple\n\n")
(display " A SWIG example for the CHICKEN compiler\n")
(display " Author: Jonah Beckford, December 2002\n\n")
(display "C Procedures:\n")
(display " double My_variable;\n")
(display " int fact(int);\n")
(display " %name(mod) int my_mod(int n, int m);\n")
(display " int my_mod(int n, int m);\n")
(display " char *get_time();\n")
(display "\n")
(display "Scheme Procedures:\n")
(display " (example-My-variable) or (example-My-variable %x)\n");
(display " (example-fact %n)\n")
(display " (example-mod %n %m)\n")
(display " (example-my-mod %n %m)\n")
(display " (example-get-time)\n")
(display "\n")

View file

@ -0,0 +1,43 @@
;; run with './simple test-simple.scm'
;; feel free to uncomment and comment sections
(display "(example-My-variable): ")
(display (example-My-variable))
(display "\n")
(display "(example-My-variable 3.141259): ")
(display (example-My-variable 3.141259))
(display "\n")
(display "(example-My-variable): ")
(display (example-My-variable))
(display "\n")
(display "(example-My-variable 'a): ")
;;(display (example-My-variable 'a))
(display "\n")
(display "(example-My-variable 1.5 'b): ")
(display (example-My-variable 1.5 'b))
(display "\n")
(display "(example-fact 5): ")
(display (example-fact 5))
(display "\n")
(display "(example-fact 'a): ")
;;(display (example-fact 'a))
(display "\n")
(display "(example-mod 75 7): ")
(display (example-mod 75 7))
(display "\n")
(display "(example-my-mod 75 7): ")
(display (example-my-mod 75 7))
(display "\n")
(display "(example-get-time): ")
(display (example-get-time))
(display "\n")