guile/libguile/modules.c

723 lines
18 KiB
C
Raw Normal View History

/* Copyright (C) 1998, 2000 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
*
* As a special exception, the Free Software Foundation gives permission
* for additional uses of the text contained in its release of GUILE.
*
* The exception is that, if you link the GUILE library with other files
* to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the GUILE library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the
* Free Software Foundation under the name GUILE. If you copy
* code from other Free Software Foundation releases into a copy of
* GUILE, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for GUILE, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice. */
/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
#include <stdarg.h>
#include "libguile/_scm.h"
#include "libguile/eval.h"
#include "libguile/smob.h"
#include "libguile/procprop.h"
#include "libguile/vectors.h"
#include "libguile/hashtab.h"
#include "libguile/struct.h"
#include "libguile/variable.h"
#include "libguile/fluids.h"
#include "libguile/deprecation.h"
#include "libguile/modules.h"
2001-05-15 14:57:22 +00:00
int scm_module_system_booted_p = 0;
SCM scm_module_tag;
static SCM the_module;
SCM_DEFINE (scm_current_module, "current-module", 0, 0, 0,
(),
"Return the current module.")
#define FUNC_NAME s_scm_current_module
{
return scm_fluid_ref (the_module);
}
#undef FUNC_NAME
2001-05-15 14:57:22 +00:00
static void scm_post_boot_init_modules (void);
SCM_DEFINE (scm_set_current_module, "set-current-module", 1, 0, 0,
(SCM module),
"Set the current module to @var{module} and return"
"the previous current module.")
#define FUNC_NAME s_scm_set_current_module
{
SCM old;
2001-05-15 14:57:22 +00:00
if (!scm_module_system_booted_p)
scm_post_boot_init_modules ();
SCM_VALIDATE_MODULE (SCM_ARG1, module);
old = scm_current_module ();
scm_fluid_set_x (the_module, module);
#if SCM_DEBUG_DEPRECATED == 0
2001-05-15 14:57:22 +00:00
scm_fluid_set_x (SCM_VARIABLE_REF (scm_top_level_lookup_closure_var),
scm_current_module_lookup_closure ());
2001-05-15 14:57:22 +00:00
scm_fluid_set_x (SCM_VARIABLE_REF (scm_system_transformer),
scm_current_module_transformer ());
#endif
return old;
}
#undef FUNC_NAME
SCM_DEFINE (scm_interaction_environment, "interaction-environment", 0, 0, 0,
(),
"Return a specifier for the environment that contains\n"
"implementation--defined bindings, typically a superset of those\n"
"listed in the report. The intent is that this procedure will\n"
"return the environment in which the implementation would\n"
"evaluate expressions dynamically typed by the user.")
#define FUNC_NAME s_scm_interaction_environment
{
return scm_current_module ();
}
#undef FUNC_NAME
SCM
scm_c_call_with_current_module (SCM module,
SCM (*func)(void *), void *data)
{
return scm_c_with_fluid (the_module, module, func, data);
}
static SCM
convert_module_name (const char *name)
{
SCM list = SCM_EOL;
SCM *tail = &list;
const char *ptr;
while (*name)
{
while (*name == ' ')
name++;
ptr = name;
while (*ptr && *ptr != ' ')
ptr++;
if (ptr > name)
{
*tail = scm_cons (scm_mem2symbol (name, ptr-name), SCM_EOL);
tail = SCM_CDRLOC (*tail);
}
name = ptr;
}
return list;
}
static SCM process_define_module_var;
static SCM process_use_modules_var;
static SCM resolve_module_var;
SCM
scm_c_resolve_module (const char *name)
{
return scm_resolve_module (convert_module_name (name));
}
SCM
scm_resolve_module (SCM name)
{
return scm_apply (SCM_VARIABLE_REF (resolve_module_var),
SCM_LIST1 (name), SCM_EOL);
}
SCM
scm_c_define_module (const char *name,
void (*init)(void *), void *data)
{
SCM module = scm_apply (SCM_VARIABLE_REF (process_define_module_var),
SCM_LIST1 (SCM_LIST1 (convert_module_name (name))),
SCM_EOL);
if (init)
scm_c_call_with_current_module (module, (SCM (*)(void*))init, data);
return module;
}
void
scm_c_use_module (const char *name)
{
scm_apply (SCM_VARIABLE_REF (process_use_modules_var),
SCM_LIST1 (SCM_LIST1 (convert_module_name (name))),
SCM_EOL);
}
static SCM module_export_x_var;
void
scm_c_export (const char *name, ...)
{
va_list ap;
SCM names = scm_cons (scm_str2symbol (name), SCM_EOL);
SCM *tail = SCM_CDRLOC (names);
va_start (ap, name);
while (1)
{
const char *n = va_arg (ap, const char *);
if (n == NULL)
break;
*tail = scm_cons (scm_str2symbol (n), SCM_EOL);
tail = SCM_CDRLOC (*tail);
}
scm_apply (SCM_VARIABLE_REF (module_export_x_var),
SCM_LIST2 (scm_current_module (),
names),
SCM_EOL);
}
/* Environments */
SCM
scm_top_level_env (SCM thunk)
{
if (SCM_IMP (thunk))
return SCM_EOL;
else
return scm_cons (thunk, SCM_EOL);
}
SCM
scm_env_top_level (SCM env)
{
while (SCM_NIMP (env))
{
if (!SCM_CONSP (SCM_CAR (env))
&& SCM_NFALSEP (scm_procedure_p (SCM_CAR (env))))
return SCM_CAR (env);
env = SCM_CDR (env);
}
return SCM_BOOL_F;
}
2001-05-15 14:57:22 +00:00
SCM_SYMBOL (sym_module, "module");
static SCM the_root_module_var;
static SCM
the_root_module ()
{
if (scm_module_system_booted_p)
return SCM_VARIABLE_REF (the_root_module_var);
else
return SCM_BOOL_F;
}
2001-05-15 14:57:22 +00:00
SCM
scm_lookup_closure_module (SCM proc)
{
if (SCM_FALSEP (proc))
return the_root_module ();
2001-05-15 14:57:22 +00:00
else if (SCM_EVAL_CLOSURE_P (proc))
return SCM_PACK (SCM_SMOB_DATA (proc));
else
{
SCM mod = scm_procedure_property (proc, sym_module);
if (mod == SCM_BOOL_F)
mod = the_root_module ();
2001-05-15 14:57:22 +00:00
return mod;
}
}
2001-05-25 13:15:57 +00:00
SCM_DEFINE (scm_env_module, "env-module", 1, 0, 0,
(SCM env),
"Return the module of @var{ENV}, a lexical environment.")
#define FUNC_NAME s_scm_env_module
2001-05-15 14:57:22 +00:00
{
return scm_lookup_closure_module (scm_env_top_level (env));
}
2001-05-25 13:15:57 +00:00
#undef FUNC_NAME
2001-05-15 14:57:22 +00:00
/*
* C level implementation of the standard eval closure
*
* This increases loading speed substantially.
* The code will be replaced by the low-level environments in next release.
*/
2001-05-15 14:57:22 +00:00
static SCM module_make_local_var_x_var;
static SCM
module_variable (SCM module, SCM sym)
{
/* 1. Check module obarray */
SCM b = scm_hashq_ref (SCM_MODULE_OBARRAY (module), sym, SCM_UNDEFINED);
if (SCM_VARIABLEP (b))
return b;
{
SCM binder = SCM_MODULE_BINDER (module);
if (SCM_NFALSEP (binder))
/* 2. Custom binder */
{
b = scm_apply (binder,
SCM_LIST3 (module, sym, SCM_BOOL_F),
SCM_EOL);
if (SCM_NFALSEP (b))
return b;
}
}
{
/* 3. Search the use list */
SCM uses = SCM_MODULE_USES (module);
while (SCM_CONSP (uses))
{
b = module_variable (SCM_CAR (uses), sym);
if (SCM_NFALSEP (b))
return b;
uses = SCM_CDR (uses);
}
return SCM_BOOL_F;
}
}
2000-12-08 17:32:56 +00:00
scm_bits_t scm_tc16_eval_closure;
2001-05-15 14:57:22 +00:00
#define SCM_F_EVAL_CLOSURE_INTERFACE (1<<16)
#define SCM_EVAL_CLOSURE_INTERFACE_P(e) \
(SCM_CELL_WORD_0 (e) & SCM_F_EVAL_CLOSURE_INTERFACE)
/* NOTE: This function may be called by a smob application
or from another C function directly. */
SCM
scm_eval_closure_lookup (SCM eclo, SCM sym, SCM definep)
{
SCM module = SCM_PACK (SCM_SMOB_DATA (eclo));
if (SCM_NFALSEP (definep))
2001-05-15 14:57:22 +00:00
{
if (SCM_EVAL_CLOSURE_INTERFACE_P (eclo))
return SCM_BOOL_F;
return scm_apply (SCM_VARIABLE_REF (module_make_local_var_x_var),
SCM_LIST2 (module, sym),
SCM_EOL);
}
else
return module_variable (module, sym);
}
SCM_DEFINE (scm_standard_eval_closure, "standard-eval-closure", 1, 0, 0,
(SCM module),
"Return an eval closure for the module @var{module}.")
#define FUNC_NAME s_scm_standard_eval_closure
{
2000-12-08 17:32:56 +00:00
SCM_RETURN_NEWSMOB (scm_tc16_eval_closure, SCM_UNPACK (module));
}
#undef FUNC_NAME
2001-05-15 14:57:22 +00:00
SCM_DEFINE (scm_standard_interface_eval_closure,
"standard-interface-eval-closure", 1, 0, 0,
(SCM module),
"Return a interface eval closure for the module @var{module}. "
"Such a closure does not allow new bindings to be added.")
#define FUNC_NAME s_scm_standard_interface_eval_closure
{
SCM_RETURN_NEWSMOB (scm_tc16_eval_closure | SCM_F_EVAL_CLOSURE_INTERFACE,
SCM_UNPACK (module));
}
#undef FUNC_NAME
SCM
scm_module_lookup_closure (SCM module)
{
if (module == SCM_BOOL_F)
return SCM_BOOL_F;
else
return SCM_MODULE_EVAL_CLOSURE (module);
}
SCM
scm_current_module_lookup_closure ()
{
if (scm_module_system_booted_p)
return scm_module_lookup_closure (scm_current_module ());
else
return SCM_BOOL_F;
}
SCM
scm_module_transformer (SCM module)
{
if (module == SCM_BOOL_F)
return SCM_BOOL_F;
else
return SCM_MODULE_TRANSFORMER (module);
}
SCM
scm_current_module_transformer ()
{
if (scm_module_system_booted_p)
return scm_module_transformer (scm_current_module ());
else
return SCM_BOOL_F;
}
2001-05-15 14:57:22 +00:00
/* scm_sym2var
*
* looks up the variable bound to SYM according to PROC. PROC should be
* a `eval closure' of some module.
*
* When no binding exists, and DEFINEP is true, create a new binding
* with a initial value of SCM_UNDEFINED. Return `#f' when DEFINEP as
* false and no binding exists.
*
* When PROC is `#f', it is ignored and the binding is searched for in
* the scm_pre_modules_obarray (a `eq' hash table).
*/
SCM scm_pre_modules_obarray;
SCM
scm_sym2var (SCM sym, SCM proc, SCM definep)
#define FUNC_NAME "scm_sym2var"
{
SCM var;
if (SCM_NIMP (proc))
{
if (SCM_EVAL_CLOSURE_P (proc))
{
/* Bypass evaluator in the standard case. */
var = scm_eval_closure_lookup (proc, sym, definep);
}
else
var = scm_apply (proc, sym, scm_cons (definep, scm_listofnull));
}
else
{
SCM handle;
if (definep == SCM_BOOL_F)
var = scm_hashq_ref (scm_pre_modules_obarray, sym, SCM_BOOL_F);
else
{
handle = scm_hashq_create_handle_x (scm_pre_modules_obarray,
sym, SCM_BOOL_F);
var = SCM_CDR (handle);
if (var == SCM_BOOL_F)
{
var = scm_make_variable (SCM_UNDEFINED);
#if SCM_ENABLE_VCELLS
scm_variable_set_name_hint (var, sym);
#endif
SCM_SETCDR (handle, var);
}
}
}
if (var != SCM_BOOL_F && !SCM_VARIABLEP (var))
SCM_MISC_ERROR ("~S is not bound to a variable", SCM_LIST1 (sym));
return var;
}
#undef FUNC_NAME
SCM
scm_c_module_lookup (SCM module, const char *name)
{
return scm_module_lookup (module, scm_str2symbol (name));
}
SCM
scm_module_lookup (SCM module, SCM sym)
#define FUNC_NAME "module-lookup"
{
SCM var;
SCM_VALIDATE_MODULE (1, module);
var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
if (SCM_FALSEP (var))
SCM_MISC_ERROR ("unbound variable: ~S", SCM_LIST1 (sym));
return var;
}
#undef FUNC_NAME
SCM
scm_c_lookup (const char *name)
{
return scm_lookup (scm_str2symbol (name));
}
SCM
scm_lookup (SCM sym)
{
SCM var =
scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_F);
if (SCM_FALSEP (var))
scm_misc_error ("scm_lookup", "unbound variable: ~S", SCM_LIST1 (sym));
return var;
}
SCM
scm_c_module_define (SCM module, const char *name, SCM value)
{
return scm_module_define (module, scm_str2symbol (name), value);
}
SCM
scm_module_define (SCM module, SCM sym, SCM value)
#define FUNC_NAME "module-define"
{
SCM var;
SCM_VALIDATE_MODULE (1, module);
var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_T);
SCM_VARIABLE_SET (var, value);
return var;
}
#undef FUNC_NAME
SCM
scm_c_define (const char *name, SCM value)
{
return scm_define (scm_str2symbol (name), value);
}
SCM
scm_define (SCM sym, SCM value)
{
SCM var =
scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_T);
SCM_VARIABLE_SET (var, value);
return var;
}
SCM
scm_module_reverse_lookup (SCM module, SCM variable)
#define FUNC_NAME "module-reverse-lookup"
{
SCM obarray;
* validate.h (SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,BITS,UBITS,INT,UINT}[_DEF]): new macros. * unif.h: type renaming: scm_array -> scm_array_t scm_array_dim -> scm_array_dim_t the old names are deprecated, all in-Guile uses changed. * tags.h (scm_ubits_t): new typedef, representing unsigned scm_bits_t. * stacks.h: type renaming: scm_info_frame -> scm_info_frame_t scm_stack -> scm_stack_t the old names are deprecated, all in-Guile uses changed. * srcprop.h: type renaming: scm_srcprops -> scm_srcprops_t scm_srcprops_chunk -> scm_srcprops_chunk_t the old names are deprecated, all in-Guile uses changed. * gsubr.c, procs.c, print.c, ports.c, read.c, rdelim.c, ramap.c, rw.c, smob.c, sort.c, srcprop.c, stacks.c, strings.c, strop.c, strorder.c, strports.c, struct.c, symbols.c, unif.c, values.c, vectors.c, vports.c, weaks.c: various int/size_t -> size_t/scm_bits_t changes. * random.h: type renaming: scm_rstate -> scm_rstate_t scm_rng -> scm_rng_t scm_i_rstate -> scm_i_rstate_t the old names are deprecated, all in-Guile uses changed. * procs.h: type renaming: scm_subr_entry -> scm_subr_entry_t the old name is deprecated, all in-Guile uses changed. * options.h (scm_option_t.val): unsigned long -> scm_bits_t. type renaming: scm_option -> scm_option_t the old name is deprecated, all in-Guile uses changed. * objects.c: various long -> scm_bits_t changes. (scm_i_make_class_object): flags: unsigned long -> scm_ubits_t * numbers.h (SCM_FIXNUM_BIT): deprecated, renamed to SCM_I_FIXNUM_BIT. * num2integral.i.c: new file, multiply included by numbers.c, used to "templatize" the various integral <-> num conversion routines. * numbers.c (scm_mkbig, scm_big2num, scm_adjbig, scm_normbig, scm_copybig, scm_2ulong2big, scm_dbl2big, scm_big2dbl): deprecated. (scm_i_mkbig, scm_i_big2inum, scm_i_adjbig, scm_i_normbig, scm_i_copybig, scm_i_short2big, scm_i_ushort2big, scm_i_int2big, scm_i_uint2big, scm_i_long2big, scm_i_ulong2big, scm_i_bits2big, scm_i_ubits2big, scm_i_size2big, scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big, scm_i_dbl2big, scm_i_big2dbl, scm_short2num, scm_ushort2num, scm_int2num, scm_uint2num, scm_bits2num, scm_ubits2num, scm_size2num, scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int, scm_num2uint, scm_num2bits, scm_num2ubits, scm_num2ptrdiff, scm_num2size): new functions. * modules.c (scm_module_reverse_lookup): i, n: int -> scm_bits_t.x * load.c: change int -> size_t in various places (where the variable is used to store a string length). (search-path): call scm_done_free, not scm_done_malloc. * list.c (scm_ilength): return a scm_bits_t, not long. some other {int,long} -> scm_bits_t changes. * hashtab.c: various [u]int -> scm_bits_t changes. scm_ihashx_closure -> scm_ihashx_closure_t (and made a typedef). (scm_ihashx): n: uint -> scm_bits_t use scm_bits2num instead of scm_ulong2num. * gsubr.c: various int -> scm_bits_t changes. * gh_data.c (gh_scm2double): no loss of precision any more. * gh.h (gh_str2scm): len: int -> size_t (gh_{get,set}_substr): start: int -> scm_bits_t, len: int -> size_t (gh_<num>2scm): n: int -> scm_bits_t (gh_*vector_length): return scm_[u]size_t, not unsigned long. (gh_length): return scm_bits_t, not unsigned long. * fports.h: type renaming: scm_fport -> scm_fport_t the old name is deprecated, all in-Guile uses changed. * fports.c (fport_fill_input): count: int -> scm_bits_t (fport_flush): init_size, remaining, count: int -> scm_bits_t * debug.h (scm_lookup_cstr, scm_lookup_soft, scm_evstr): removed those prototypes, as the functions they prototype don't exist. * fports.c (default_buffer_size): int -> size_t (scm_fport_buffer_add): read_size, write_size: int -> scm_bits_t default_size: int -> size_t (scm_setvbuf): csize: int -> scm_bits_t * fluids.c (n_fluids): int -> scm_bits_t (grow_fluids): old_length, i: int -> scm_bits_t (next_fluid_num, scm_fluid_ref, scm_fluid_set_x): n: int -> scm_bits_t (scm_c_with_fluids): flen, vlen: int -> scm_bits_t * filesys.c (s_scm_open_fdes): changed calls to SCM_NUM2LONG to the new and shiny SCM_NUM2INT. * extensions.c: extension -> extension_t (and made a typedef). * eval.h (SCM_IFRAME): cast to scm_bits_t, not int. just so there are no nasty surprises if/when the various deeply magic tag bits move somewhere else. * eval.c: changed the locals used to store results of SCM_IFRAME, scm_ilength and such to be of type scm_bits_t (and not int/long). (iqq): depth, edepth: int -> scm_bits_t (scm_eval_stack): int -> scm_bits_t (SCM_CEVAL): various vars are not scm_bits_t instead of int. (check_map_args, scm_map, scm_for_each): len: long -> scm_bits_t i: int -> scm_bits_t * environments.c: changed the many calls to scm_ulong2num to scm_ubits2num. (import_environment_fold): proc_as_ul: ulong -> scm_ubits_t * dynwind.c (scm_dowinds): delta: long -> scm_bits_t * debug.h: type renaming: scm_debug_info -> scm_debug_info_t scm_debug_frame -> scm_debug_frame_t the old names are deprecated, all in-Guile uses changed. (scm_debug_eframe_size): int -> scm_bits_t * debug.c (scm_init_debug): use scm_c_define instead of the deprecated scm_define. * continuations.h: type renaming: scm_contregs -> scm_contregs_t the old name is deprecated, all in-Guile uses changed. (scm_contregs_t.num_stack_items): size_t -> scm_bits_t (scm_contregs_t.num_stack_items): ulong -> scm_ubits_t * continuations.c (scm_make_continuation): change the type of stack_size form long to scm_bits_t. * ports.h: type renaming: scm_port_rw_active -> scm_port_rw_active_t (and made a typedef) scm_port -> scm_port_t scm_ptob_descriptor -> scm_ptob_descriptor_t the old names are deprecated, all in-Guile uses changed. (scm_port_t.entry): int -> scm_bits_t. (scm_port_t.line_number): int -> long. (scm_port_t.putback_buf_size): int -> size_t. * __scm.h (long_long, ulong_long): deprecated (they pollute the global namespace and have little value besides that). (SCM_BITS_LENGTH): new, is the bit size of scm_bits_t (i.e. of an SCM handle). (ifdef spaghetti): include sys/types.h and sys/stdtypes.h, if they exist (for size_t & ptrdiff_t) (scm_sizet): deprecated. * Makefile.am (noinst_HEADERS): add num2integral.i.c
2001-05-24 00:50:51 +00:00
scm_bits_t i, n;
2001-05-15 14:57:22 +00:00
if (module == SCM_BOOL_F)
obarray = scm_pre_modules_obarray;
else
{
SCM_VALIDATE_MODULE (1, module);
obarray = SCM_MODULE_OBARRAY (module);
}
/* XXX - We do not use scm_hash_fold here to avoid searching the
whole obarray. We should have a scm_hash_find procedure. */
n = SCM_VECTOR_LENGTH (obarray);
for (i = 0; i < n; ++i)
{
SCM ls = SCM_VELTS (obarray)[i], handle;
while (!SCM_NULLP (ls))
{
handle = SCM_CAR (ls);
if (SCM_CDR (handle) == variable)
return SCM_CAR (handle);
ls = SCM_CDR (ls);
}
}
/* Try the `uses' list.
*/
{
SCM uses = SCM_MODULE_USES (module);
while (SCM_CONSP (uses))
{
SCM sym = scm_module_reverse_lookup (SCM_CAR (uses), variable);
if (sym != SCM_BOOL_F)
return sym;
uses = SCM_CDR (uses);
}
}
return SCM_BOOL_F;
}
#undef FUNC_NAME
SCM_DEFINE (scm_get_pre_modules_obarray, "%get-pre-modules-obarray", 0, 0, 0,
(),
"Return the obarray that is used for all new bindings before "
"the module system is booted. The first call to "
"@code{set-current-module} will boot the module system.")
#define FUNC_NAME s_scm_get_pre_modules_obarray
{
return scm_pre_modules_obarray;
}
#undef FUNC_NAME
#if SCM_DEBUG_DEPRECATED == 0
static SCM root_module_lookup_closure;
SCM_SYMBOL (scm_sym_app, "app");
SCM_SYMBOL (scm_sym_modules, "modules");
static SCM module_prefix;
static SCM make_modules_in_var;
static SCM beautify_user_module_x_var;
static SCM try_module_autoload_var;
#endif
SCM_SYMBOL (scm_sym_system_module, "system-module");
SCM
scm_system_module_env_p (SCM env)
{
SCM proc = scm_env_top_level (env);
if (SCM_FALSEP (proc))
return SCM_BOOL_T;
return ((SCM_NFALSEP (scm_procedure_property (proc,
scm_sym_system_module)))
? SCM_BOOL_T
: SCM_BOOL_F);
}
2001-05-15 14:57:22 +00:00
void
scm_modules_prehistory ()
{
scm_pre_modules_obarray
= scm_permanent_object (scm_c_make_hash_table (2001));
}
void
scm_init_modules ()
{
#ifndef SCM_MAGIC_SNARFER
#include "libguile/modules.x"
#endif
2001-05-15 14:57:22 +00:00
module_make_local_var_x_var = scm_c_define ("module-make-local-var!",
SCM_UNDEFINED);
2000-12-08 17:32:56 +00:00
scm_tc16_eval_closure = scm_make_smob_type ("eval-closure", 0);
scm_set_smob_mark (scm_tc16_eval_closure, scm_markcdr);
scm_set_smob_apply (scm_tc16_eval_closure, scm_eval_closure_lookup, 2, 0, 0);
the_module = scm_permanent_object (scm_make_fluid ());
}
2001-05-15 14:57:22 +00:00
static void
scm_post_boot_init_modules ()
{
2001-05-15 14:57:22 +00:00
#define PERM(x) scm_permanent_object(x)
SCM module_type = SCM_VARIABLE_REF (scm_c_lookup ("module-type"));
scm_module_tag = (SCM_CELL_WORD_1 (module_type) + scm_tc3_cons_gloc);
resolve_module_var = PERM (scm_c_lookup ("resolve-module"));
process_define_module_var = PERM (scm_c_lookup ("process-define-module"));
process_use_modules_var = PERM (scm_c_lookup ("process-use-modules"));
module_export_x_var = PERM (scm_c_lookup ("module-export!"));
the_root_module_var = PERM (scm_c_lookup ("the-root-module"));
#if SCM_DEBUG_DEPRECATED == 0
2001-05-15 14:57:22 +00:00
module_prefix = PERM (SCM_LIST2 (scm_sym_app, scm_sym_modules));
make_modules_in_var = PERM (scm_c_lookup ("make-modules-in"));
root_module_lookup_closure =
PERM (scm_module_lookup_closure (SCM_VARIABLE_REF (the_root_module_var)));
beautify_user_module_x_var = PERM (scm_c_lookup ("beautify-user-module!"));
2001-05-15 14:57:22 +00:00
try_module_autoload_var = PERM (scm_c_lookup ("try-module-autoload"));
#endif
scm_module_system_booted_p = 1;
}
#if SCM_DEBUG_DEPRECATED == 0
SCM
scm_the_root_module ()
{
scm_c_issue_deprecation_warning ("`scm_the_root_module' is deprecated. "
"Use `scm_c_resolve_module (\"guile\") "
"instead.");
return the_root_module ();
}
static SCM
scm_module_full_name (SCM name)
{
if (SCM_EQ_P (SCM_CAR (name), scm_sym_app))
return name;
else
return scm_append (SCM_LIST2 (module_prefix, name));
}
SCM
scm_make_module (SCM name)
{
scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
"Use `scm_c_define_module instead.");
return scm_apply (SCM_VARIABLE_REF (make_modules_in_var),
SCM_LIST2 (scm_the_root_module (),
scm_module_full_name (name)),
SCM_EOL);
}
SCM
scm_ensure_user_module (SCM module)
{
scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
"Use `scm_c_define_module instead.");
scm_apply (SCM_VARIABLE_REF (beautify_user_module_x_var),
SCM_LIST1 (module), SCM_EOL);
return SCM_UNSPECIFIED;
}
SCM
scm_load_scheme_module (SCM name)
{
scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
"Use `scm_c_resolve_module instead.");
return scm_apply (SCM_VARIABLE_REF (try_module_autoload_var),
SCM_LIST1 (name), SCM_EOL);
}
#endif
/*
Local Variables:
c-file-style: "gnu"
End:
*/