mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
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.
This commit is contained in:
parent
52fd9639fd
commit
ab4779ffcf
5 changed files with 64 additions and 3 deletions
|
@ -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
|
static void
|
||||||
foreign_finalizer_trampoline (GC_PTR ptr, GC_PTR data)
|
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)
|
scm_init_foreign (void)
|
||||||
{
|
{
|
||||||
#ifndef SCM_MAGIC_SNARFER
|
#ifndef SCM_MAGIC_SNARFER
|
||||||
#include "libguile/foreign.x"
|
#include "libguile/foreign.x"
|
||||||
#endif
|
#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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -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_INTERNAL void scm_i_foreign_print (SCM foreign, SCM port,
|
||||||
scm_print_state *pstate);
|
scm_print_state *pstate);
|
||||||
SCM_INTERNAL void scm_init_foreign (void);
|
SCM_INTERNAL void scm_register_foreign (void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* SCM_FOREIGN_H */
|
#endif /* SCM_FOREIGN_H */
|
||||||
|
|
|
@ -452,6 +452,7 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
scm_bootstrap_objcodes ();
|
scm_bootstrap_objcodes ();
|
||||||
scm_bootstrap_programs ();
|
scm_bootstrap_programs ();
|
||||||
scm_bootstrap_vm ();
|
scm_bootstrap_vm ();
|
||||||
|
scm_register_foreign ();
|
||||||
|
|
||||||
scm_init_strings (); /* Requires array-handle */
|
scm_init_strings (); /* Requires array-handle */
|
||||||
scm_init_struct (); /* Requires strings */
|
scm_init_struct (); /* Requires strings */
|
||||||
|
@ -482,7 +483,6 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
scm_init_ports ();
|
scm_init_ports ();
|
||||||
scm_init_hash ();
|
scm_init_hash ();
|
||||||
scm_init_hashtab ();
|
scm_init_hashtab ();
|
||||||
scm_init_foreign ();
|
|
||||||
scm_init_deprecation ();
|
scm_init_deprecation ();
|
||||||
scm_init_objprop ();
|
scm_init_objprop ();
|
||||||
scm_init_promises (); /* requires smob_prehistory */
|
scm_init_promises (); /* requires smob_prehistory */
|
||||||
|
|
|
@ -284,6 +284,7 @@ SYSTEM_SOURCES = \
|
||||||
system/vm/program.scm \
|
system/vm/program.scm \
|
||||||
system/vm/trace.scm \
|
system/vm/trace.scm \
|
||||||
system/vm/vm.scm \
|
system/vm/vm.scm \
|
||||||
|
system/foreign.scm \
|
||||||
system/xref.scm \
|
system/xref.scm \
|
||||||
system/repl/repl.scm \
|
system/repl/repl.scm \
|
||||||
system/repl/common.scm \
|
system/repl/common.scm \
|
||||||
|
|
29
module/system/foreign.scm
Normal file
29
module/system/foreign.scm
Normal file
|
@ -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")
|
Loading…
Add table
Add a link
Reference in a new issue