diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
|---|---|---|
| committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
| commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
| tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/guile/simple | |
| download | swig-tarball-master.tar.gz | |
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/guile/simple')
| -rw-r--r-- | Examples/guile/simple/Makefile | 19 | ||||
| -rw-r--r-- | Examples/guile/simple/README | 9 | ||||
| -rw-r--r-- | Examples/guile/simple/example.c | 21 | ||||
| -rw-r--r-- | Examples/guile/simple/example.i | 14 | ||||
| -rw-r--r-- | Examples/guile/simple/example.scm | 28 |
5 files changed, 91 insertions, 0 deletions
diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile new file mode 100644 index 0000000..702b5bb --- /dev/null +++ b/Examples/guile/simple/Makefile @@ -0,0 +1,19 @@ +SRCS = example.c +TARGET = my-guile +IFILE = example.i +MKDIR = .. + +all: $(TARGET) + +$(TARGET): + $(MAKE) -f $(MKDIR)/Makefile \ + SRCS='$(SRCS)' \ + TARGET=$(TARGET) \ + IFILE=$(IFILE) \ + sub-all + +clean:: + $(MAKE) -f $(MKDIR)/Makefile TARGET='$(TARGET)' guile_clean + +check: $(TARGET) + ./$(TARGET) -s example.scm > /dev/null diff --git a/Examples/guile/simple/README b/Examples/guile/simple/README new file mode 100644 index 0000000..982216e --- /dev/null +++ b/Examples/guile/simple/README @@ -0,0 +1,9 @@ +A very simple example. + +To run it, start the program 'my-guile' and type: + + (load "example.scm") + +Alternatively, you can use the shell command: + + ./my-guile -s example.scm diff --git a/Examples/guile/simple/example.c b/Examples/guile/simple/example.c new file mode 100644 index 0000000..dcafc4d --- /dev/null +++ b/Examples/guile/simple/example.c @@ -0,0 +1,21 @@ +/* Simple example from documentation */ +/* File : example.c */ + +#include <time.h> + +double My_variable = 3.0; + +int fact(int n) { + if (n <= 1) return 1; + else return n*fact(n-1); +} + +int mod(int n, int m) { + return (n % m); +} + +char *get_time() { + long ltime; + time(<ime); + return ctime(<ime); +} diff --git a/Examples/guile/simple/example.i b/Examples/guile/simple/example.i new file mode 100644 index 0000000..1a9930a --- /dev/null +++ b/Examples/guile/simple/example.i @@ -0,0 +1,14 @@ +/* File : example.i */ +%module Example +%{ +/* Put headers and other declarations here */ +%} + +%inline %{ +extern double My_variable; +extern int fact(int); +extern int mod(int n, int m); +extern char *get_time(); +%} + +%include guile/guilemain.i diff --git a/Examples/guile/simple/example.scm b/Examples/guile/simple/example.scm new file mode 100644 index 0000000..9408b1a --- /dev/null +++ b/Examples/guile/simple/example.scm @@ -0,0 +1,28 @@ +;;; example.scm + +(define (mdisplay-newline . args) ; does guile-1.3.4 have `format #t'? + (for-each display args) + (newline)) + +(mdisplay-newline (get-time) "My variable = " (My-variable)) + +(do ((i 0 (1+ i))) + ((= 14 i)) + (mdisplay-newline i " factorial is " (fact i))) + +(define (mods i imax j jmax) + (if (< i imax) + (if (< j jmax) + (begin + (My-variable (+ (My-variable) (mod i j))) + (mods i imax (+ j 1) jmax)) + (mods (+ i 1) imax 1 jmax)))) + +(mods 1 150 1 150) + +(mdisplay-newline "My-variable = " (My-variable)) + +(exit (and (= 1932053504 (fact 13)) + (= 745470.0 (My-variable)))) + +;;; example.scm ends here |
