From: Andy Wingo Date: Mon, 18 Jan 2010 11:16:13 +0000 (+0100) Subject: move foreign function interface to its own module X-Git-Url: https://git.hcoop.net/bpt/guile.git/commitdiff_plain/ab4779ffcfb463201d46459e06b9188dd5f1cbda move foreign function interface to its own module * 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. --- diff --git a/libguile/foreign.c b/libguile/foreign.c index ec76a00aa..224f06ce3 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -26,6 +26,18 @@ +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) -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); } /* diff --git a/libguile/foreign.h b/libguile/foreign.h index d48027799..522916d8a 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -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 */ diff --git a/libguile/init.c b/libguile/init.c index abca49048..57fda40e8 100644 --- a/libguile/init.c +++ b/libguile/init.c @@ -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 */ diff --git a/module/Makefile.am b/module/Makefile.am index b43cf2ed6..7b1bbeac4 100644 --- a/module/Makefile.am +++ b/module/Makefile.am @@ -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 index 000000000..5db6b9349 --- /dev/null +++ b/module/system/foreign.scm @@ -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 +;;;; + + +(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")