move foreign function interface to its own module
authorAndy Wingo <wingo@pobox.com>
Mon, 18 Jan 2010 11:16:13 +0000 (12:16 +0100)
committerAndy Wingo <wingo@pobox.com>
Tue, 26 Jan 2010 21:56:41 +0000 (22:56 +0100)
* libguile/foreign.h:
* libguile/init.c: Change so that init just registers an extension,
  later called by foreign.scm.

* libguile/foreign.c (scm_init_foreign): Define constants for the
  various foreign types.

* module/Makefile.am:
* module/system/foreign.scm: New module, for the foreign function
  interface.

libguile/foreign.c
libguile/foreign.h
libguile/init.c
module/Makefile.am
module/system/foreign.scm [new file with mode: 0644]

index ec76a00..224f06c 100644 (file)
 
 \f
 
+SCM_SYMBOL (sym_void, "void");
+SCM_SYMBOL (sym_float, "float");
+SCM_SYMBOL (sym_double, "double");
+SCM_SYMBOL (sym_uint8, "uint8");
+SCM_SYMBOL (sym_int8, "int8");
+SCM_SYMBOL (sym_uint16, "uint16");
+SCM_SYMBOL (sym_int16, "int16");
+SCM_SYMBOL (sym_uint32, "uint32");
+SCM_SYMBOL (sym_int32, "int32");
+SCM_SYMBOL (sym_uint64, "uint64");
+SCM_SYMBOL (sym_int64, "int64");
+
 static void
 foreign_finalizer_trampoline (GC_PTR ptr, GC_PTR data)
 {
@@ -308,12 +320,31 @@ scm_i_foreign_print (SCM foreign, SCM port, scm_print_state *pstate)
 
 \f
 
-void
+static void
 scm_init_foreign (void)
 {
 #ifndef SCM_MAGIC_SNARFER
 #include "libguile/foreign.x"
 #endif
+  scm_define (sym_void, scm_from_uint8 (SCM_FOREIGN_TYPE_VOID));
+  scm_define (sym_float, scm_from_uint8 (SCM_FOREIGN_TYPE_FLOAT));
+  scm_define (sym_double, scm_from_uint8 (SCM_FOREIGN_TYPE_DOUBLE));
+  scm_define (sym_uint8, scm_from_uint8 (SCM_FOREIGN_TYPE_UINT8));
+  scm_define (sym_int8, scm_from_uint8 (SCM_FOREIGN_TYPE_INT8));
+  scm_define (sym_uint16, scm_from_uint8 (SCM_FOREIGN_TYPE_UINT16));
+  scm_define (sym_int16, scm_from_uint8 (SCM_FOREIGN_TYPE_INT16));
+  scm_define (sym_uint32, scm_from_uint8 (SCM_FOREIGN_TYPE_UINT32));
+  scm_define (sym_int32, scm_from_uint8 (SCM_FOREIGN_TYPE_INT32));
+  scm_define (sym_uint64, scm_from_uint8 (SCM_FOREIGN_TYPE_UINT64));
+  scm_define (sym_int64, scm_from_uint8 (SCM_FOREIGN_TYPE_INT64));
+}
+
+void
+scm_register_foreign (void)
+{
+  scm_c_register_extension ("libguile", "scm_init_foreign",
+                            (scm_t_extension_init_func)scm_init_foreign,
+                            NULL);
 }
 
 /*
index d480277..522916d 100644 (file)
@@ -95,7 +95,7 @@ SCM_API SCM scm_foreign_set_x (SCM foreign, SCM val, SCM type, SCM offset);
 
 SCM_INTERNAL void scm_i_foreign_print (SCM foreign, SCM port,
                                        scm_print_state *pstate);
-SCM_INTERNAL void scm_init_foreign (void);
+SCM_INTERNAL void scm_register_foreign (void);
 
 
 #endif /* SCM_FOREIGN_H */
index abca490..57fda40 100644 (file)
@@ -452,6 +452,7 @@ scm_i_init_guile (SCM_STACKITEM *base)
   scm_bootstrap_objcodes ();
   scm_bootstrap_programs ();
   scm_bootstrap_vm ();
+  scm_register_foreign ();
 
   scm_init_strings ();            /* Requires array-handle */
   scm_init_struct ();             /* Requires strings */
@@ -482,7 +483,6 @@ scm_i_init_guile (SCM_STACKITEM *base)
   scm_init_ports ();
   scm_init_hash ();
   scm_init_hashtab ();
-  scm_init_foreign ();
   scm_init_deprecation ();
   scm_init_objprop ();
   scm_init_promises ();         /* requires smob_prehistory */
index b43cf2e..7b1bbea 100644 (file)
@@ -284,6 +284,7 @@ SYSTEM_SOURCES =                            \
   system/vm/program.scm                                \
   system/vm/trace.scm                          \
   system/vm/vm.scm                             \
+  system/foreign.scm                           \
   system/xref.scm                              \
   system/repl/repl.scm                         \
   system/repl/common.scm                       \
diff --git a/module/system/foreign.scm b/module/system/foreign.scm
new file mode 100644 (file)
index 0000000..5db6b93
--- /dev/null
@@ -0,0 +1,29 @@
+;;;;   Copyright (C) 2010 Free Software Foundation, Inc.
+;;;;
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 2.1 of the License, or (at your option) any later version.
+;;;;
+;;;; This library 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
+;;;; Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this library; if not, write to the Free Software
+;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;;
+\f
+
+(define-module (system foreign)
+  #:export (void
+            float double
+            int8 uint8
+            uint16 int16
+            uint32 int32
+            uint64 int64
+
+            foreign-ref foreign-set!))
+
+(load-extension "libguile" "scm_init_foreign")