diff options
Diffstat (limited to 'examples/box-dynamic')
-rw-r--r-- | examples/box-dynamic/.cvsignore | 2 | ||||
-rw-r--r-- | examples/box-dynamic/Makefile.am | 36 | ||||
-rw-r--r-- | examples/box-dynamic/README | 58 | ||||
-rw-r--r-- | examples/box-dynamic/box.c | 128 | ||||
-rwxr-xr-x | examples/box-dynamic/check.test | 38 |
5 files changed, 0 insertions, 262 deletions
diff --git a/examples/box-dynamic/.cvsignore b/examples/box-dynamic/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/box-dynamic/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/box-dynamic/Makefile.am b/examples/box-dynamic/Makefile.am deleted file mode 100644 index 574eadb85..000000000 --- a/examples/box-dynamic/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as -## published by the Free Software Foundation; either version 2, or -## (at your option) any later version. -## -## GUILE is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public -## License along with GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README box.c check.test - -CFLAGS=`$(bindir)/guile-config compile` -LIBS=`$(bindir)/guile-config link` - -libbox: box.lo - sh ../../libtool --mode=link $(CC) $< $(LIBS) -rpath $(libdir) -o libbox.la - -box.lo: box.c - sh ../../libtool --mode=compile $(CC) $(CFLAGS) -c $< - -installcheck: libbox - LTDL_LIBRARY_PATH=.libs GUILE_LOAD_PATH=$(top_srcdir):$(srcdir) $(srcdir)/check.test - -CLEANFILES=libbox.la box.lo box.o diff --git a/examples/box-dynamic/README b/examples/box-dynamic/README deleted file mode 100644 index 7acc9f432..000000000 --- a/examples/box-dynamic/README +++ /dev/null @@ -1,58 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes an example program for extending Guile with a -new (and even useful) data type, putting it into a shared library, so it -can be called from an unmodified guile interpreter. - - -* Build Instructions - -To build the example, simply type - - make libbox - -in this directory. - - -* The Box Data Type - -A box is simply an object for storing one other object in. It can be -used for passing parameters by reference, for example. You simply -store an object into a box, pass it to another procedure which can -store a new object into it and thus return a value via the box. - - -** Usage - -Box objects are created with `make-box', set with `box-set!' and -examined with `box-ref'. Note that these procedures are placed in a -module called (box-module) and can thus only be accessed after using -this module. See the following example session for usage details: - -Extend your LD_LIBRARY_PATH variable (or equivalent) to include . and -.libs - - -** Example Session - -$ guile -guile> (load-extension "libbox" "scm_init_box") -guile> (define b (make-box)) -guile> b -#<box #f> -guile> (box-set! b '(list of values)) -guile> b -#<box (list of values)> -guile> (box-ref b) -(list of values) -guile> (quit) -$ - - -* Module Installation - -If you like this example so much that you want to have it available -for normal usage, install the dynamic libraries in the .libs directory -to the directory $(prefix)/lib diff --git a/examples/box-dynamic/box.c b/examples/box-dynamic/box.c deleted file mode 100644 index 9379b86a5..000000000 --- a/examples/box-dynamic/box.c +++ /dev/null @@ -1,128 +0,0 @@ -/* examples/box-dynamic/box.c - * - * Copyright (C) 1998,2001 Free Software Foundation, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - */ - -/* Include all needed declarations. */ -#include <libguile.h> - - -/* The type code for the newly created smob type will be stored into - this variable. It has the prefix `scm_tc16_' to make it usable - with the SCM_VALIDATE_SMOB macro below. */ -static scm_t_bits scm_tc16_box; - - -/* This function is responsible for marking all SCM objects included - in the smob. */ -static SCM -mark_box (SCM b) -{ - /* Since we have only one SCM object to protect, we simply return it - and the caller will mark it. */ - return SCM_CELL_OBJECT_1 (b); -} - - -/* Print a textual represenation of the smob to a given port. */ -static int -print_box (SCM b, SCM port, scm_print_state *pstate) -{ - SCM value = SCM_CELL_OBJECT_1 (b); - - scm_puts ("#<box ", port); - scm_write (value, port); - scm_puts (">", port); - - /* Non-zero means success. */ - return 1; -} - - -/* This defines the primitve `make-box', which returns a new smob of - type `box', initialized to `#f'. */ -static SCM -#define FUNC_NAME "make-box" -make_box (void) -{ - /* This macro creates the new objects, stores the value `#f' into it - and returns it to the caller. */ - SCM_RETURN_NEWSMOB (scm_tc16_box, SCM_BOOL_F); -} -#undef FUNC_NAME - - -/* This is the primitive `box-ref' which returns the object stored in - the box. */ -static SCM -box_ref (SCM b) -#define FUNC_NAME "box-ref" -{ - /* First, we have to ensure that the user really gave us a box - objects. The macro SCM_VALIDATE_SMOB will do all what is needed. - The parameters are interpreted as follows: - - 1: The position of the checked variable in the parameter list. - b: The passed parameter. - box: Concatenated with the fixed prefix scm_tc16_, names the type - code for the expected smob type. */ - SCM_VALIDATE_SMOB (1, b, box); - - /* Fetch the object from the box and return it. */ - return SCM_CELL_OBJECT_1 (b); -} -#undef FUNC_NAME - - -/* Primitive which stores an arbitrary value into a box. */ -static SCM -box_set_x (SCM b, SCM value) -#define FUNC_NAME "box-set!" -{ - SCM_VALIDATE_SMOB (1, b, box); - - /* Set the cell number 1 of the smob to the given value. */ - SCM_SET_CELL_OBJECT_1 (b, value); - - /* When this constant is returned, the REPL will not print the - returned value. All procedures in Guile which are documented as - returning `and unspecified value' actually return this value. */ - return SCM_UNSPECIFIED; -} -#undef FUNC_NAME - - -/* Create and initialize the new smob type, and register the - primitives with the interpreter library. - - To be called with (load-extension "libbox" "scm_init_box") - from a script. -*/ -void -scm_init_box () -{ - scm_tc16_box = scm_make_smob_type ("box", 0); - scm_set_smob_mark (scm_tc16_box, mark_box); - scm_set_smob_print (scm_tc16_box, print_box); - - scm_c_define_gsubr ("make-box", 0, 0, 0, make_box); - scm_c_define_gsubr ("box-set!", 2, 0, 0, box_set_x); - scm_c_define_gsubr ("box-ref", 1, 0, 0, box_ref); -} - -/* End of file. */ diff --git a/examples/box-dynamic/check.test b/examples/box-dynamic/check.test deleted file mode 100755 index c0923365c..000000000 --- a/examples/box-dynamic/check.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -set -e - -# -# ./box test #1 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -EOF -rm -f TMP - -# -# ./box test #2 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -EOF -rm -f TMP - -# -# ./box test #3 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline) (display (box-ref b)) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -1 -EOF -rm -f TMP - -# check.test ends here |