Use 'scm_from_utf8_{string,symbol,keyword}' for C string literals.
Partial fix for <https://bugs.gnu.org/33044>.
Reported by Tom de Vries <tdevries@suse.de>.
Fix several instances of the mistake of using 'scm_from_locale_*' for C
strings that originally came from a C string literal. Change several
uses of 'scm_from_latin1_*' as well, to promote the practice of writing
code that works for arbitrary C string literals.
Also add missing years to the copyright notices of changed files, based
on the git history.
* libguile/debug-malloc.c, libguile/deprecation.c, libguile/error.c,
libguile/eval.c, libguile/expand.c, libguile/extensions.c,
libguile/filesys.c, libguile/init.c, libguile/load.c,
libguile/modules.c, libguile/pairs.c, libguile/posix.c,
libguile/print.c, libguile/random.c, libguile/read.c,
libguile/regex-posix.c, libguile/snarf.h, libguile/srfi-13.c,
libguile/stacks.c, libguile/stime.c, libguile/strports.c,
libguile/values.c: Use 'scm_from_utf8_*' where appropriate.
2018-10-16 02:34:18 -04:00
|
|
|
|
/* Copyright 1998,2000-2004,2006-2012,2017-2019
|
2018-06-20 20:01:49 +02:00
|
|
|
|
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 Lesser General Public License as published
|
|
|
|
|
|
by the Free Software Foundation, either version 3 of the License, 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 Lesser General Public
|
|
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
License along with Guile. If not, see
|
|
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
1999-12-12 20:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
2008-09-13 15:35:27 +02:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include <config.h>
|
|
|
|
|
|
#endif
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "boolean.h"
|
2018-06-20 18:31:24 +02:00
|
|
|
|
#include "deprecation.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "eval.h"
|
2018-06-20 18:31:24 +02:00
|
|
|
|
#include "fluids.h"
|
|
|
|
|
|
#include "gsubr.h"
|
|
|
|
|
|
#include "hashtab.h"
|
|
|
|
|
|
#include "keywords.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "list.h"
|
2018-06-20 18:31:24 +02:00
|
|
|
|
#include "pairs.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "procprop.h"
|
2018-06-20 18:31:24 +02:00
|
|
|
|
#include "smob.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "struct.h"
|
|
|
|
|
|
#include "symbols.h"
|
2018-06-27 14:57:51 +02:00
|
|
|
|
#include "threads.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "variable.h"
|
2018-06-20 18:31:24 +02:00
|
|
|
|
#include "vectors.h"
|
2018-06-20 17:19:31 +02:00
|
|
|
|
|
|
|
|
|
|
#include "modules.h"
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
2018-06-20 18:31:24 +02:00
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
int scm_module_system_booted_p = 0;
|
2000-08-11 08:44:02 +00:00
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_bits scm_module_tag;
|
2000-08-11 08:44:02 +00:00
|
|
|
|
|
2010-04-27 22:04:24 +02:00
|
|
|
|
/* The current module, a fluid. */
|
1998-11-22 12:05:14 +00:00
|
|
|
|
static SCM the_module;
|
|
|
|
|
|
|
2010-04-27 22:04:24 +02:00
|
|
|
|
/* Most of the module system is implemented in Scheme. These bindings from
|
|
|
|
|
|
boot-9 are needed to provide the Scheme interface. */
|
2008-02-01 22:51:34 +00:00
|
|
|
|
static SCM the_root_module_var;
|
2010-04-27 22:04:24 +02:00
|
|
|
|
static SCM module_make_local_var_x_var;
|
2010-11-19 13:11:47 +01:00
|
|
|
|
static SCM define_module_star_var;
|
2010-04-23 17:03:34 +02:00
|
|
|
|
static SCM process_use_modules_var;
|
|
|
|
|
|
static SCM resolve_module_var;
|
|
|
|
|
|
static SCM module_public_interface_var;
|
|
|
|
|
|
static SCM module_export_x_var;
|
|
|
|
|
|
static SCM default_duplicate_binding_procedures_var;
|
|
|
|
|
|
|
2011-03-08 09:27:23 +01:00
|
|
|
|
/* The #:ensure keyword. */
|
|
|
|
|
|
static SCM k_ensure;
|
|
|
|
|
|
|
2008-02-01 22:51:34 +00:00
|
|
|
|
|
2009-10-23 15:47:08 +02:00
|
|
|
|
static SCM unbound_variable (const char *func, SCM sym)
|
|
|
|
|
|
{
|
2011-01-07 09:08:58 -08:00
|
|
|
|
scm_error (scm_from_latin1_symbol ("unbound-variable"), func,
|
2009-10-23 15:47:08 +02:00
|
|
|
|
"Unbound variable: ~S", scm_list_1 (sym), SCM_BOOL_F);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
remove some deprecated things, undeprecate scm_the_root_module()
* libguile/deprecated.h
* libguile/deprecated.c (SCM_ILOC00, SCM_IDINC, SCM_IDSTMSK)
(scm_s_expression, scm_s_test, scm_s_body, scm_s_bindings)
(scm_s_variable, scm_s_clauses, scm_s_formals, SCM_EVALIM2)
(SCM_EVALIM, SCM_XEVAL, SCM_XEVALCAR): Remove these macros and
constants, deprecated in 2003.
(scm_the_root_module): Undeprecate, it's actually a useful function,
that other parts of the code use.
* libguile/modules.h (scm_the_root_module): Undeprecated.
* libguile/modules.c (scm_the_root_module): Rename from
the_root_module. Use it in the rest of this file.
2009-11-27 17:24:12 +01:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_the_root_module (void)
|
2008-02-01 22:51:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (scm_module_system_booted_p)
|
|
|
|
|
|
return SCM_VARIABLE_REF (the_root_module_var);
|
|
|
|
|
|
else
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-27 14:57:51 +02:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_i_current_module (scm_thread *thread)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scm_module_system_booted_p)
|
|
|
|
|
|
return scm_i_fluid_ref (thread, the_module);
|
|
|
|
|
|
else
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2001-04-24 23:40:18 +00:00
|
|
|
|
SCM_DEFINE (scm_current_module, "current-module", 0, 0, 0,
|
|
|
|
|
|
(),
|
|
|
|
|
|
"Return the current module.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_current_module
|
1998-11-22 12:05:14 +00:00
|
|
|
|
{
|
2018-06-27 14:57:51 +02:00
|
|
|
|
return scm_i_current_module (SCM_I_CURRENT_THREAD);
|
1998-11-22 12:05:14 +00:00
|
|
|
|
}
|
2001-04-24 23:40:18 +00:00
|
|
|
|
#undef FUNC_NAME
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
static void scm_post_boot_init_modules (void);
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
2001-04-24 23:40:18 +00:00
|
|
|
|
SCM_DEFINE (scm_set_current_module, "set-current-module", 1, 0, 0,
|
|
|
|
|
|
(SCM module),
|
2001-11-11 15:01:52 +00:00
|
|
|
|
"Set the current module to @var{module} and return\n"
|
2001-04-24 23:40:18 +00:00
|
|
|
|
"the previous current module.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_set_current_module
|
1998-11-22 12:05:14 +00:00
|
|
|
|
{
|
2001-04-24 23:40:18 +00:00
|
|
|
|
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);
|
2001-04-24 23:40:18 +00:00
|
|
|
|
|
|
|
|
|
|
old = scm_current_module ();
|
|
|
|
|
|
scm_fluid_set_x (the_module, module);
|
|
|
|
|
|
|
1998-11-22 12:05:14 +00:00
|
|
|
|
return old;
|
|
|
|
|
|
}
|
2001-04-24 23:40:18 +00:00
|
|
|
|
#undef FUNC_NAME
|
1998-11-22 12:05:14 +00:00
|
|
|
|
|
2000-08-11 08:44:02 +00:00
|
|
|
|
SCM_DEFINE (scm_interaction_environment, "interaction-environment", 0, 0, 0,
|
|
|
|
|
|
(),
|
2001-04-03 13:19:05 +00:00
|
|
|
|
"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.")
|
2000-08-11 08:44:02 +00:00
|
|
|
|
#define FUNC_NAME s_scm_interaction_environment
|
|
|
|
|
|
{
|
2001-02-08 18:49:52 +00:00
|
|
|
|
return scm_current_module ();
|
2000-08-11 08:44:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
1998-11-22 12:05:14 +00:00
|
|
|
|
SCM
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
scm_c_call_with_current_module (SCM module,
|
|
|
|
|
|
SCM (*func)(void *), void *data)
|
1998-11-22 12:05:14 +00:00
|
|
|
|
{
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
return scm_c_with_fluid (the_module, module, func, data);
|
1998-11-22 12:05:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-03-02 20:14:59 +00:00
|
|
|
|
void
|
2006-01-29 00:23:28 +00:00
|
|
|
|
scm_dynwind_current_module (SCM module)
|
2005-03-02 20:14:59 +00:00
|
|
|
|
{
|
2006-01-29 00:23:28 +00:00
|
|
|
|
scm_dynwind_fluid (the_module, module);
|
2005-03-02 20:14:59 +00:00
|
|
|
|
}
|
2002-12-10 13:26:25 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
convert "A B C" to scheme list (A B C)
|
|
|
|
|
|
*/
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
static SCM
|
|
|
|
|
|
convert_module_name (const char *name)
|
1998-11-23 02:35:11 +00:00
|
|
|
|
{
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
SCM list = SCM_EOL;
|
|
|
|
|
|
SCM *tail = &list;
|
1998-11-23 02:35:11 +00:00
|
|
|
|
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
const char *ptr;
|
|
|
|
|
|
while (*name)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (*name == ' ')
|
|
|
|
|
|
name++;
|
|
|
|
|
|
ptr = name;
|
|
|
|
|
|
while (*ptr && *ptr != ' ')
|
|
|
|
|
|
ptr++;
|
|
|
|
|
|
if (ptr > name)
|
|
|
|
|
|
{
|
2011-10-25 17:45:29 +02:00
|
|
|
|
SCM sym = scm_from_utf8_symboln (name, ptr-name);
|
* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,
scm_i_string_writable_chars, scm_i_string_stop_writing): New, to
replace SCM_I_STRING_CHARS and SCM_I_STRING_LENGTH. Updated all
uses.
(scm_i_make_string, scm_c_make_string): New, to replace
scm_allocate_string. Updated all uses.
(SCM_STRINGP, SCM_STRING_CHARS, SCM_STRING_UCHARS,
SCM_STRING_LENGTH): Deprecated.
(scm_allocate_string, scm_take_str, scm_take0str, scm_mem2string,
scm_str2string, scm_makfrom0str, scm_makfrom0str_opt):
Discouraged. Replaced all uses with scm_from_locale_string or
similar, as appropriate.
(scm_c_string_length, scm_c_string_ref, scm_c_string_set_x,
scm_c_substring, scm_c_substring_shared, scm_c_substring_copy,
scm_substring_shared, scm_substring_copy): New.
* symbols.c, symbols.h (SCM_SYMBOLP, SCM_SYMBOL_FUNC,
SCM_SET_SYMBOL_FUNC, SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS,
SCM_SYMBOL_HASH, SCM_SYMBOL_INTERNED_P, scm_mem2symbol,
scm_str2symbol, scm_mem2uninterned_symbol): Discouraged.
(SCM_SYMBOL_LENGTH, SCM_SYMBOL_CHARS, scm_c_symbol2str):
Deprecated.
(SCM_MAKE_SYMBOL_TAG, SCM_SET_SYMBOL_LENGTH, SCM_SET_SYMBOL_CHARS,
SCM_PROP_SLOTS, SCM_SET_PROP_SLOTS): Removed.
(scm_is_symbol, scm_from_locale_symbol, scm_from_locale_symboln):
New, to replace scm_str2symbol and scm_mem2symbol, respectively.
Updated all uses.
(scm_gensym): Generate only the number suffix in the buffer, just
string-append the prefix.
2004-08-19 17:19:44 +00:00
|
|
|
|
*tail = scm_cons (sym, SCM_EOL);
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
tail = SCM_CDRLOC (*tail);
|
|
|
|
|
|
}
|
|
|
|
|
|
name = ptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
1998-11-22 12:05:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-02-11 18:14:34 +00:00
|
|
|
|
SCM
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
scm_c_resolve_module (const char *name)
|
2001-02-11 18:14:34 +00:00
|
|
|
|
{
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
return scm_resolve_module (convert_module_name (name));
|
2001-02-11 18:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-04-24 23:40:18 +00:00
|
|
|
|
SCM
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
scm_resolve_module (SCM name)
|
2001-04-24 23:40:18 +00:00
|
|
|
|
{
|
2001-06-26 15:46:40 +00:00
|
|
|
|
return scm_call_1 (SCM_VARIABLE_REF (resolve_module_var), name);
|
2001-04-24 23:40:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-14 10:38:05 +02:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_maybe_resolve_module (SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_call_3 (SCM_VARIABLE_REF (resolve_module_var), name,
|
|
|
|
|
|
k_ensure, SCM_BOOL_F);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2001-04-24 23:40:18 +00:00
|
|
|
|
SCM
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
scm_c_define_module (const char *name,
|
|
|
|
|
|
void (*init)(void *), void *data)
|
2001-04-24 23:40:18 +00:00
|
|
|
|
{
|
2010-11-19 13:11:47 +01:00
|
|
|
|
SCM module = scm_call_1 (SCM_VARIABLE_REF (define_module_star_var),
|
|
|
|
|
|
convert_module_name (name));
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
if (init)
|
|
|
|
|
|
scm_c_call_with_current_module (module, (SCM (*)(void*))init, data);
|
|
|
|
|
|
return module;
|
2001-04-24 23:40:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_c_use_module (const char *name)
|
1998-11-26 17:59:15 +00:00
|
|
|
|
{
|
2001-06-26 15:46:40 +00:00
|
|
|
|
scm_call_1 (SCM_VARIABLE_REF (process_use_modules_var),
|
2001-11-23 21:38:33 +00:00
|
|
|
|
scm_list_1 (scm_list_1 (convert_module_name (name))));
|
1998-11-26 17:59:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_module_export (SCM module, SCM namelist)
|
2002-12-10 13:26:25 +00:00
|
|
|
|
{
|
2002-12-10 16:07:30 +00:00
|
|
|
|
return scm_call_2 (SCM_VARIABLE_REF (module_export_x_var),
|
|
|
|
|
|
module, namelist);
|
2002-12-10 13:26:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-11-20 22:45:24 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
@code{scm_c_export}(@var{name-list})
|
|
|
|
|
|
|
|
|
|
|
|
@code{scm_c_export} exports the named bindings from the current
|
|
|
|
|
|
module, making them visible to users of the module. This function
|
|
|
|
|
|
takes a list of string arguments, terminated by NULL, e.g.
|
|
|
|
|
|
|
|
|
|
|
|
@example
|
|
|
|
|
|
scm_c_export ("add-double-record", "bamboozle-money", NULL);
|
|
|
|
|
|
@end example
|
|
|
|
|
|
*/
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_c_export (const char *name, ...)
|
1998-11-23 02:35:11 +00:00
|
|
|
|
{
|
2001-11-20 22:45:24 +00:00
|
|
|
|
if (name)
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
{
|
2001-11-20 22:45:24 +00:00
|
|
|
|
va_list ap;
|
2011-10-25 17:45:29 +02:00
|
|
|
|
SCM names = scm_cons (scm_from_utf8_symbol (name), SCM_EOL);
|
2001-11-20 22:45:24 +00:00
|
|
|
|
SCM *tail = SCM_CDRLOC (names);
|
|
|
|
|
|
va_start (ap, name);
|
|
|
|
|
|
while (1)
|
|
|
|
|
|
{
|
|
|
|
|
|
const char *n = va_arg (ap, const char *);
|
|
|
|
|
|
if (n == NULL)
|
|
|
|
|
|
break;
|
2011-10-25 17:45:29 +02:00
|
|
|
|
*tail = scm_cons (scm_from_utf8_symbol (n), SCM_EOL);
|
2001-11-20 22:45:24 +00:00
|
|
|
|
tail = SCM_CDRLOC (*tail);
|
|
|
|
|
|
}
|
|
|
|
|
|
va_end (ap);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
scm_module_export (scm_current_module (), names);
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
}
|
1998-11-23 02:35:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-12-10 13:26:25 +00:00
|
|
|
|
|
2000-06-04 01:30:05 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* C level implementation of the standard eval closure
|
|
|
|
|
|
*
|
2006-11-02 21:10:37 +00:00
|
|
|
|
* This increases loading speed substantially. The code may be
|
|
|
|
|
|
* replaced by something based on environments.[ch], in a future
|
|
|
|
|
|
* release.
|
2000-06-04 01:30:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* Return the list of default duplicate binding handlers (procedures). */
|
|
|
|
|
|
static inline SCM
|
|
|
|
|
|
default_duplicate_binding_handlers (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM get_handlers;
|
|
|
|
|
|
|
|
|
|
|
|
get_handlers = SCM_VARIABLE_REF (default_duplicate_binding_procedures_var);
|
|
|
|
|
|
|
|
|
|
|
|
return (scm_call_0 (get_handlers));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-18 17:39:35 +02:00
|
|
|
|
/* Each module has an "import obarray" that may be accessed concurrently
|
|
|
|
|
|
by several threads. This mutex protects access to any obarray. This
|
|
|
|
|
|
is coarse-grain but (1) pthread mutexes are quite cheap, and (2)
|
|
|
|
|
|
Scheme "programs" have a cache for free variables anyway. */
|
|
|
|
|
|
static scm_i_pthread_mutex_t import_obarray_mutex =
|
|
|
|
|
|
SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* Resolve the import of SYM in MODULE, where SYM is currently provided by
|
|
|
|
|
|
both IFACE1 as VAR1 and IFACE2 as VAR2. Return the variable chosen by the
|
|
|
|
|
|
duplicate binding handlers or `#f'. */
|
|
|
|
|
|
static inline SCM
|
|
|
|
|
|
resolve_duplicate_binding (SCM module, SCM sym,
|
|
|
|
|
|
SCM iface1, SCM var1,
|
|
|
|
|
|
SCM iface2, SCM var2)
|
|
|
|
|
|
{
|
2011-07-07 12:21:48 +02:00
|
|
|
|
SCM args[8];
|
|
|
|
|
|
SCM handlers;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
SCM result = SCM_BOOL_F;
|
|
|
|
|
|
|
2011-07-07 12:21:48 +02:00
|
|
|
|
if (scm_is_eq (var1, var2))
|
|
|
|
|
|
return var1;
|
|
|
|
|
|
|
|
|
|
|
|
args[0] = module;
|
|
|
|
|
|
args[1] = sym;
|
|
|
|
|
|
args[2] = iface1;
|
|
|
|
|
|
args[3] = SCM_VARIABLE_REF (var1);
|
|
|
|
|
|
if (SCM_UNBNDP (args[3]))
|
|
|
|
|
|
args[3] = SCM_BOOL_F;
|
|
|
|
|
|
args[4] = iface2;
|
|
|
|
|
|
args[5] = SCM_VARIABLE_REF (var2);
|
|
|
|
|
|
if (SCM_UNBNDP (args[5]))
|
|
|
|
|
|
args[5] = SCM_BOOL_F;
|
2018-06-18 17:39:35 +02:00
|
|
|
|
|
|
|
|
|
|
scm_i_pthread_mutex_lock (&import_obarray_mutex);
|
2011-07-07 12:21:48 +02:00
|
|
|
|
args[6] = scm_hashq_ref (SCM_MODULE_IMPORT_OBARRAY (module), sym, SCM_BOOL_F);
|
2018-06-18 17:39:35 +02:00
|
|
|
|
scm_i_pthread_mutex_unlock (&import_obarray_mutex);
|
|
|
|
|
|
|
2011-07-07 12:21:48 +02:00
|
|
|
|
args[7] = SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
handlers = SCM_MODULE_DUPLICATE_HANDLERS (module);
|
|
|
|
|
|
if (scm_is_false (handlers))
|
|
|
|
|
|
handlers = default_duplicate_binding_handlers ();
|
|
|
|
|
|
|
|
|
|
|
|
for (; scm_is_pair (handlers); handlers = SCM_CDR (handlers))
|
2007-05-05 20:38:57 +00:00
|
|
|
|
{
|
2011-07-07 12:21:48 +02:00
|
|
|
|
if (scm_is_true (args[6]))
|
|
|
|
|
|
{
|
|
|
|
|
|
args[7] = SCM_VARIABLE_REF (args[6]);
|
|
|
|
|
|
if (SCM_UNBNDP (args[7]))
|
|
|
|
|
|
args[7] = SCM_BOOL_F;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = scm_call_n (SCM_CAR (handlers), args, 8);
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_is_true (result))
|
|
|
|
|
|
return result;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-07-07 12:21:48 +02:00
|
|
|
|
return SCM_BOOL_F;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-02-10 21:19:33 +01:00
|
|
|
|
/* No lock is needed for access to this variable, as there are no
|
|
|
|
|
|
threads before modules are booted. */
|
2008-09-02 00:49:17 -07:00
|
|
|
|
SCM scm_pre_modules_obarray;
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* Lookup SYM as an imported variable of MODULE. */
|
|
|
|
|
|
static inline SCM
|
|
|
|
|
|
module_imported_variable (SCM module, SCM sym)
|
|
|
|
|
|
{
|
|
|
|
|
|
#define SCM_BOUND_THING_P scm_is_true
|
|
|
|
|
|
register SCM var, imports;
|
|
|
|
|
|
|
|
|
|
|
|
/* Search cached imported bindings. */
|
|
|
|
|
|
imports = SCM_MODULE_IMPORT_OBARRAY (module);
|
2018-06-18 17:39:35 +02:00
|
|
|
|
|
|
|
|
|
|
scm_i_pthread_mutex_lock (&import_obarray_mutex);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
var = scm_hashq_ref (imports, sym, SCM_UNDEFINED);
|
2018-06-18 17:39:35 +02:00
|
|
|
|
scm_i_pthread_mutex_unlock (&import_obarray_mutex);
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
if (SCM_BOUND_THING_P (var))
|
|
|
|
|
|
return var;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Search the use list for yet uncached imported bindings, possibly
|
|
|
|
|
|
resolving duplicates as needed and caching the result in the import
|
|
|
|
|
|
obarray. */
|
|
|
|
|
|
SCM uses;
|
|
|
|
|
|
SCM found_var = SCM_BOOL_F, found_iface = SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
for (uses = SCM_MODULE_USES (module);
|
|
|
|
|
|
scm_is_pair (uses);
|
|
|
|
|
|
uses = SCM_CDR (uses))
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM iface;
|
|
|
|
|
|
|
|
|
|
|
|
iface = SCM_CAR (uses);
|
|
|
|
|
|
var = scm_module_variable (iface, sym);
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_BOUND_THING_P (var))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SCM_BOUND_THING_P (found_var))
|
|
|
|
|
|
{
|
|
|
|
|
|
/* SYM is a duplicate binding (imported more than once) so we
|
|
|
|
|
|
need to resolve it. */
|
2011-07-07 12:21:48 +02:00
|
|
|
|
found_var = resolve_duplicate_binding (module, sym,
|
|
|
|
|
|
found_iface, found_var,
|
|
|
|
|
|
iface, var);
|
|
|
|
|
|
|
|
|
|
|
|
/* Note that it could be that FOUND_VAR doesn't belong
|
|
|
|
|
|
either to FOUND_IFACE or to IFACE, if it was created
|
|
|
|
|
|
by merge-generics. The right thing to do there would
|
|
|
|
|
|
be to treat the import obarray as the iface, but the
|
|
|
|
|
|
import obarray isn't actually a module. Oh well. */
|
2007-05-05 20:38:57 +00:00
|
|
|
|
if (scm_is_eq (found_var, var))
|
|
|
|
|
|
found_iface = iface;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
/* Keep track of the variable we found and check for other
|
|
|
|
|
|
occurences of SYM in the use list. */
|
|
|
|
|
|
found_var = var, found_iface = iface;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_BOUND_THING_P (found_var))
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Save the lookup result for future reference. */
|
2018-06-18 17:39:35 +02:00
|
|
|
|
scm_i_pthread_mutex_lock (&import_obarray_mutex);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
(void) scm_hashq_set_x (imports, sym, found_var);
|
2018-06-18 17:39:35 +02:00
|
|
|
|
scm_i_pthread_mutex_unlock (&import_obarray_mutex);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
return found_var;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
#undef SCM_BOUND_THING_P
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_module_local_variable, "module-local-variable", 2, 0, 0,
|
|
|
|
|
|
(SCM module, SCM sym),
|
|
|
|
|
|
"Return the variable bound to @var{sym} in @var{module}. Return "
|
|
|
|
|
|
"@code{#f} is @var{sym} is not bound locally in @var{module}.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_module_local_variable
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2001-10-13 15:40:29 +00:00
|
|
|
|
#define SCM_BOUND_THING_P(b) \
|
2004-07-06 10:59:25 +00:00
|
|
|
|
(scm_is_true (b))
|
2001-10-13 15:40:29 +00:00
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
register SCM b;
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_module_system_booted_p)
|
|
|
|
|
|
SCM_VALIDATE_MODULE (1, module);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_VALIDATE_SYMBOL (2, sym);
|
|
|
|
|
|
|
2009-04-26 13:10:30 +02:00
|
|
|
|
if (scm_is_false (module))
|
|
|
|
|
|
return scm_hashq_ref (scm_pre_modules_obarray, sym, SCM_UNDEFINED);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
2000-06-04 01:30:05 +00:00
|
|
|
|
/* 1. Check module obarray */
|
2007-05-05 20:38:57 +00:00
|
|
|
|
b = scm_hashq_ref (SCM_MODULE_OBARRAY (module), sym, SCM_UNDEFINED);
|
2001-10-13 15:40:29 +00:00
|
|
|
|
if (SCM_BOUND_THING_P (b))
|
2000-06-04 01:30:05 +00:00
|
|
|
|
return b;
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
2010-09-02 20:48:08 -07:00
|
|
|
|
/* At this point we should just be able to return #f, but there is the
|
|
|
|
|
|
possibility that a custom binder establishes a mapping for this
|
|
|
|
|
|
variable.
|
|
|
|
|
|
|
|
|
|
|
|
However a custom binder should be called only if there is no
|
|
|
|
|
|
imported binding with the name SYM. So here instead of the order:
|
|
|
|
|
|
|
|
|
|
|
|
2. Search imported bindings. In order to be consistent with
|
|
|
|
|
|
`module-variable', the binder gets called only when no
|
|
|
|
|
|
imported binding matches SYM.
|
|
|
|
|
|
|
|
|
|
|
|
3. Query the custom binder.
|
|
|
|
|
|
|
|
|
|
|
|
we first check if there is a binder at all, and if not, just return
|
|
|
|
|
|
#f directly.
|
|
|
|
|
|
*/
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2000-08-11 08:44:02 +00:00
|
|
|
|
SCM binder = SCM_MODULE_BINDER (module);
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
2004-07-06 10:59:25 +00:00
|
|
|
|
if (scm_is_true (binder))
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2010-09-02 20:48:08 -07:00
|
|
|
|
/* 2. */
|
|
|
|
|
|
b = module_imported_variable (module, sym);
|
|
|
|
|
|
if (SCM_BOUND_THING_P (b))
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
/* 3. */
|
2001-06-26 15:46:40 +00:00
|
|
|
|
b = scm_call_3 (binder, module, sym, SCM_BOOL_F);
|
2001-10-13 15:40:29 +00:00
|
|
|
|
if (SCM_BOUND_THING_P (b))
|
2000-06-04 01:30:05 +00:00
|
|
|
|
return b;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
#undef SCM_BOUND_THING_P
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM_DEFINE (scm_module_variable, "module-variable", 2, 0, 0,
|
|
|
|
|
|
(SCM module, SCM sym),
|
|
|
|
|
|
"Return the variable bound to @var{sym} in @var{module}. This "
|
|
|
|
|
|
"may be both a local variable or an imported variable. Return "
|
|
|
|
|
|
"@code{#f} is @var{sym} is not bound in @var{module}.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_module_variable
|
|
|
|
|
|
{
|
|
|
|
|
|
#define SCM_BOUND_THING_P(b) \
|
|
|
|
|
|
(scm_is_true (b))
|
|
|
|
|
|
|
|
|
|
|
|
register SCM var;
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_module_system_booted_p)
|
|
|
|
|
|
SCM_VALIDATE_MODULE (1, module);
|
|
|
|
|
|
|
|
|
|
|
|
SCM_VALIDATE_SYMBOL (2, sym);
|
|
|
|
|
|
|
2008-09-02 00:49:17 -07:00
|
|
|
|
if (scm_is_false (module))
|
|
|
|
|
|
return scm_hashq_ref (scm_pre_modules_obarray, sym, SCM_UNDEFINED);
|
|
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* 1. Check module obarray */
|
|
|
|
|
|
var = scm_hashq_ref (SCM_MODULE_OBARRAY (module), sym, SCM_UNDEFINED);
|
|
|
|
|
|
if (SCM_BOUND_THING_P (var))
|
|
|
|
|
|
return var;
|
|
|
|
|
|
|
|
|
|
|
|
/* 2. Search among the imported variables. */
|
|
|
|
|
|
var = module_imported_variable (module, sym);
|
|
|
|
|
|
if (SCM_BOUND_THING_P (var))
|
|
|
|
|
|
return var;
|
|
|
|
|
|
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* 3. Query the custom binder. */
|
|
|
|
|
|
SCM binder;
|
|
|
|
|
|
|
|
|
|
|
|
binder = SCM_MODULE_BINDER (module);
|
|
|
|
|
|
if (scm_is_true (binder))
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2007-05-05 20:38:57 +00:00
|
|
|
|
var = scm_call_3 (binder, module, sym, SCM_BOOL_F);
|
|
|
|
|
|
if (SCM_BOUND_THING_P (var))
|
|
|
|
|
|
return var;
|
2000-06-04 01:30:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
2001-10-13 15:40:29 +00:00
|
|
|
|
#undef SCM_BOUND_THING_P
|
2000-06-04 01:30:05 +00:00
|
|
|
|
}
|
2007-05-05 20:38:57 +00:00
|
|
|
|
#undef FUNC_NAME
|
2000-06-04 01:30:05 +00:00
|
|
|
|
|
2000-09-10 22:22:36 +00:00
|
|
|
|
SCM
|
2012-05-23 11:46:30 +02:00
|
|
|
|
scm_module_ensure_local_variable (SCM module, SCM sym)
|
|
|
|
|
|
#define FUNC_NAME "module-ensure-local-variable"
|
2000-06-04 01:30:05 +00:00
|
|
|
|
{
|
2012-05-23 11:46:30 +02:00
|
|
|
|
if (SCM_LIKELY (scm_module_system_booted_p))
|
2001-05-15 14:57:22 +00:00
|
|
|
|
{
|
2012-05-23 11:46:30 +02:00
|
|
|
|
SCM_VALIDATE_MODULE (1, module);
|
|
|
|
|
|
SCM_VALIDATE_SYMBOL (2, sym);
|
|
|
|
|
|
|
2001-06-26 15:46:40 +00:00
|
|
|
|
return scm_call_2 (SCM_VARIABLE_REF (module_make_local_var_x_var),
|
2012-05-23 11:46:30 +02:00
|
|
|
|
module, sym);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
2000-06-04 01:30:05 +00:00
|
|
|
|
|
2012-05-23 11:46:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
SCM handle, var;
|
2000-06-04 01:30:05 +00:00
|
|
|
|
|
2012-05-23 11:46:30 +02:00
|
|
|
|
handle = scm_hashq_create_handle_x (scm_pre_modules_obarray,
|
|
|
|
|
|
sym, SCM_BOOL_F);
|
|
|
|
|
|
var = SCM_CDR (handle);
|
2005-06-11 01:48:19 +00:00
|
|
|
|
|
2012-05-23 11:46:30 +02:00
|
|
|
|
if (scm_is_false (var))
|
|
|
|
|
|
{
|
|
|
|
|
|
var = scm_make_variable (SCM_UNDEFINED);
|
|
|
|
|
|
SCM_SETCDR (handle, var);
|
|
|
|
|
|
}
|
2001-05-15 14:57:22 +00:00
|
|
|
|
|
2012-05-23 11:46:30 +02:00
|
|
|
|
return var;
|
|
|
|
|
|
}
|
2009-03-30 21:20:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2010-05-07 10:51:28 +02:00
|
|
|
|
SCM_SYMBOL (sym_macroexpand, "macroexpand");
|
2009-03-09 20:49:54 +01:00
|
|
|
|
|
really boot primitive-eval from scheme.
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
(scm_init_eval): Rework so that scm_primitive_eval always calls out to
the primitive-eval variable. The previous definition is the default
value, which is probably overridden by scm_init_eval_in_scheme.
* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.
* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
ice-9/eval.scm to replace the primitive-eval definition, if everything
is there and up-to-date.
* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
there for eval.go.
* module/ice-9/boot-9.scm: No need to define module-transformer.
* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
modules are booted.
(primitive-eval): Inline a definition for identity. Throw a more
standard error for "wrong number of arguments".
* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
syncase macro is now a pair: the transformer, and the module that was
current when the transformer was installed. The latter is used for
hygiene purposes, replacing the use of procedure-module, which didn't
work with the interpreter's shared-code closures.
(chi-macro): Adapt for the binding being a pair, and get the hygiene
from the cdr.
(eval-local-transformer): Adapt to new form of macro bindings.
* module/ice-9/psyntax-pp.scm: Regenerated.
* .gitignore: Ignore eval.go.stamp.
* module/Makefile.am: Reorder for fastest serial compilation, now that
there are no ordering constraints. I did a number of experiments here
and this seems to be the best; but the bulk of the time is compiling
psyntax-pp.scm with eval.scm. Not so great.
* libguile/vm-engine.c (vm-engine): Throw a more standard error for
"wrong type to apply".
* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
the new evaluator, and throw in another (gc) for good measure.
* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
arity is of a closure made by eval.scm -- or more accurately all
closures have 0 required args and no rest args. So punt for now.
* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
check that a variable is unbound, currently; perhaps the full "fixing
letrec" expansion could fix this. But barring that, punt.
2009-12-01 23:54:25 +01:00
|
|
|
|
SCM_DEFINE (scm_module_transformer, "module-transformer", 1, 0, 0,
|
|
|
|
|
|
(SCM module),
|
|
|
|
|
|
"Returns the syntax expander for the given module.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_module_transformer
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
{
|
2009-03-09 20:49:54 +01:00
|
|
|
|
if (SCM_UNLIKELY (scm_is_false (module)))
|
2010-05-07 10:51:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
SCM v = scm_hashq_ref (scm_pre_modules_obarray,
|
|
|
|
|
|
sym_macroexpand,
|
2009-03-09 20:49:54 +01:00
|
|
|
|
SCM_BOOL_F);
|
|
|
|
|
|
if (scm_is_false (v))
|
2010-05-07 10:51:28 +02:00
|
|
|
|
SCM_MISC_ERROR ("no module, and `macroexpand' unbound", SCM_EOL);
|
|
|
|
|
|
return SCM_VARIABLE_REF (v);
|
2009-03-09 20:49:54 +01:00
|
|
|
|
}
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
else
|
really boot primitive-eval from scheme.
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
(scm_init_eval): Rework so that scm_primitive_eval always calls out to
the primitive-eval variable. The previous definition is the default
value, which is probably overridden by scm_init_eval_in_scheme.
* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.
* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
ice-9/eval.scm to replace the primitive-eval definition, if everything
is there and up-to-date.
* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
there for eval.go.
* module/ice-9/boot-9.scm: No need to define module-transformer.
* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
modules are booted.
(primitive-eval): Inline a definition for identity. Throw a more
standard error for "wrong number of arguments".
* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
syncase macro is now a pair: the transformer, and the module that was
current when the transformer was installed. The latter is used for
hygiene purposes, replacing the use of procedure-module, which didn't
work with the interpreter's shared-code closures.
(chi-macro): Adapt for the binding being a pair, and get the hygiene
from the cdr.
(eval-local-transformer): Adapt to new form of macro bindings.
* module/ice-9/psyntax-pp.scm: Regenerated.
* .gitignore: Ignore eval.go.stamp.
* module/Makefile.am: Reorder for fastest serial compilation, now that
there are no ordering constraints. I did a number of experiments here
and this seems to be the best; but the bulk of the time is compiling
psyntax-pp.scm with eval.scm. Not so great.
* libguile/vm-engine.c (vm-engine): Throw a more standard error for
"wrong type to apply".
* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
the new evaluator, and throw in another (gc) for good measure.
* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
arity is of a closure made by eval.scm -- or more accurately all
closures have 0 required args and no rest args. So punt for now.
* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
check that a variable is unbound, currently; perhaps the full "fixing
letrec" expansion could fix this. But barring that, punt.
2009-12-01 23:54:25 +01:00
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_MODULE (SCM_ARG1, module);
|
|
|
|
|
|
return SCM_MODULE_TRANSFORMER (module);
|
|
|
|
|
|
}
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
}
|
really boot primitive-eval from scheme.
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
(scm_init_eval): Rework so that scm_primitive_eval always calls out to
the primitive-eval variable. The previous definition is the default
value, which is probably overridden by scm_init_eval_in_scheme.
* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.
* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
ice-9/eval.scm to replace the primitive-eval definition, if everything
is there and up-to-date.
* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
there for eval.go.
* module/ice-9/boot-9.scm: No need to define module-transformer.
* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
modules are booted.
(primitive-eval): Inline a definition for identity. Throw a more
standard error for "wrong number of arguments".
* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
syncase macro is now a pair: the transformer, and the module that was
current when the transformer was installed. The latter is used for
hygiene purposes, replacing the use of procedure-module, which didn't
work with the interpreter's shared-code closures.
(chi-macro): Adapt for the binding being a pair, and get the hygiene
from the cdr.
(eval-local-transformer): Adapt to new form of macro bindings.
* module/ice-9/psyntax-pp.scm: Regenerated.
* .gitignore: Ignore eval.go.stamp.
* module/Makefile.am: Reorder for fastest serial compilation, now that
there are no ordering constraints. I did a number of experiments here
and this seems to be the best; but the bulk of the time is compiling
psyntax-pp.scm with eval.scm. Not so great.
* libguile/vm-engine.c (vm-engine): Throw a more standard error for
"wrong type to apply".
* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
the new evaluator, and throw in another (gc) for good measure.
* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
arity is of a closure made by eval.scm -- or more accurately all
closures have 0 required args and no rest args. So punt for now.
* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
check that a variable is unbound, currently; perhaps the full "fixing
letrec" expansion could fix this. But barring that, punt.
2009-12-01 23:54:25 +01:00
|
|
|
|
#undef FUNC_NAME
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_current_module_transformer ()
|
|
|
|
|
|
{
|
2009-03-09 20:49:54 +01:00
|
|
|
|
return scm_module_transformer (scm_current_module ());
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-11 15:58:02 +00:00
|
|
|
|
SCM_DEFINE (scm_module_import_interface, "module-import-interface", 2, 0, 0,
|
|
|
|
|
|
(SCM module, SCM sym),
|
2007-05-05 20:38:57 +00:00
|
|
|
|
"Return the module or interface from which @var{sym} is imported "
|
|
|
|
|
|
"in @var{module}. If @var{sym} is not imported (i.e., it is not "
|
|
|
|
|
|
"defined in @var{module} or it is a module-local binding instead "
|
|
|
|
|
|
"of an imported one), then @code{#f} is returned.")
|
2003-03-11 15:58:02 +00:00
|
|
|
|
#define FUNC_NAME s_scm_module_import_interface
|
|
|
|
|
|
{
|
2007-05-05 20:38:57 +00:00
|
|
|
|
SCM var, result = SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
SCM_VALIDATE_MODULE (1, module);
|
|
|
|
|
|
SCM_VALIDATE_SYMBOL (2, sym);
|
|
|
|
|
|
|
|
|
|
|
|
var = scm_module_variable (module, sym);
|
|
|
|
|
|
if (scm_is_true (var))
|
2003-03-11 15:58:02 +00:00
|
|
|
|
{
|
2007-05-05 20:38:57 +00:00
|
|
|
|
/* Look for the module that provides VAR. */
|
|
|
|
|
|
SCM local_var;
|
|
|
|
|
|
|
|
|
|
|
|
local_var = scm_hashq_ref (SCM_MODULE_OBARRAY (module), sym,
|
|
|
|
|
|
SCM_UNDEFINED);
|
|
|
|
|
|
if (scm_is_eq (local_var, var))
|
|
|
|
|
|
result = module;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Look for VAR among the used modules. */
|
|
|
|
|
|
SCM uses, imported_var;
|
|
|
|
|
|
|
|
|
|
|
|
for (uses = SCM_MODULE_USES (module);
|
|
|
|
|
|
scm_is_pair (uses) && scm_is_false (result);
|
|
|
|
|
|
uses = SCM_CDR (uses))
|
|
|
|
|
|
{
|
|
|
|
|
|
imported_var = scm_module_variable (SCM_CAR (uses), sym);
|
|
|
|
|
|
if (scm_is_eq (imported_var, var))
|
|
|
|
|
|
result = SCM_CAR (uses);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-03-11 15:58:02 +00:00
|
|
|
|
}
|
2007-05-05 20:38:57 +00:00
|
|
|
|
|
|
|
|
|
|
return result;
|
2003-03-11 15:58:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
2010-04-23 17:03:34 +02:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_module_public_interface (SCM module)
|
2008-09-29 21:36:25 +02:00
|
|
|
|
{
|
2010-04-23 17:03:34 +02:00
|
|
|
|
return scm_call_1 (SCM_VARIABLE_REF (module_public_interface_var), module);
|
2008-09-29 21:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_module_lookup (SCM module, const char *name)
|
|
|
|
|
|
{
|
2011-10-25 17:45:29 +02:00
|
|
|
|
return scm_module_lookup (module, scm_from_utf8_symbol (name));
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_module_lookup (SCM module, SCM sym)
|
|
|
|
|
|
#define FUNC_NAME "module-lookup"
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM var;
|
2012-05-23 11:46:30 +02:00
|
|
|
|
var = scm_module_variable (module, sym);
|
2004-07-06 10:59:25 +00:00
|
|
|
|
if (scm_is_false (var))
|
2009-10-23 15:47:08 +02:00
|
|
|
|
unbound_variable (FUNC_NAME, sym);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
return var;
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_lookup (const char *name)
|
|
|
|
|
|
{
|
2011-10-25 17:45:29 +02:00
|
|
|
|
return scm_lookup (scm_from_utf8_symbol (name));
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_lookup (SCM sym)
|
|
|
|
|
|
{
|
2012-05-23 11:46:30 +02:00
|
|
|
|
return scm_module_lookup (scm_current_module (), sym);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-03-08 09:27:23 +01:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_public_variable (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM mod, iface;
|
|
|
|
|
|
|
2018-05-14 10:38:05 +02:00
|
|
|
|
mod = scm_maybe_resolve_module (module_name);
|
2011-03-08 09:27:23 +01:00
|
|
|
|
|
|
|
|
|
|
if (scm_is_false (mod))
|
|
|
|
|
|
scm_misc_error ("public-lookup", "Module named ~s does not exist",
|
|
|
|
|
|
scm_list_1 (module_name));
|
|
|
|
|
|
|
|
|
|
|
|
iface = scm_module_public_interface (mod);
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_is_false (iface))
|
|
|
|
|
|
scm_misc_error ("public-lookup", "Module ~s has no public interface",
|
|
|
|
|
|
scm_list_1 (mod));
|
|
|
|
|
|
|
|
|
|
|
|
return scm_module_variable (iface, name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_private_variable (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM mod;
|
|
|
|
|
|
|
2018-05-14 10:38:05 +02:00
|
|
|
|
mod = scm_maybe_resolve_module (module_name);
|
2011-03-08 09:27:23 +01:00
|
|
|
|
|
|
|
|
|
|
if (scm_is_false (mod))
|
|
|
|
|
|
scm_misc_error ("private-lookup", "Module named ~s does not exist",
|
|
|
|
|
|
scm_list_1 (module_name));
|
|
|
|
|
|
|
|
|
|
|
|
return scm_module_variable (mod, name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_public_variable (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_public_variable (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_private_variable (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_private_variable (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_public_lookup (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM var;
|
|
|
|
|
|
|
|
|
|
|
|
var = scm_public_variable (module_name, name);
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_is_false (var))
|
|
|
|
|
|
scm_misc_error ("public-lookup", "No variable bound to ~s in module ~s",
|
|
|
|
|
|
scm_list_2 (name, module_name));
|
|
|
|
|
|
|
|
|
|
|
|
return var;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_private_lookup (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM var;
|
|
|
|
|
|
|
|
|
|
|
|
var = scm_private_variable (module_name, name);
|
|
|
|
|
|
|
|
|
|
|
|
if (scm_is_false (var))
|
|
|
|
|
|
scm_misc_error ("private-lookup", "No variable bound to ~s in module ~s",
|
|
|
|
|
|
scm_list_2 (name, module_name));
|
|
|
|
|
|
|
|
|
|
|
|
return var;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_public_lookup (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_public_lookup (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_private_lookup (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_private_lookup (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_public_ref (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_variable_ref (scm_public_lookup (module_name, name));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_private_ref (SCM module_name, SCM name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_variable_ref (scm_private_lookup (module_name, name));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_public_ref (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_public_ref (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_private_ref (const char *module_name, const char *name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_private_ref (convert_module_name (module_name),
|
2011-10-25 17:45:29 +02:00
|
|
|
|
scm_from_utf8_symbol (name));
|
2011-03-08 09:27:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_module_define (SCM module, const char *name, SCM value)
|
|
|
|
|
|
{
|
2011-10-25 17:45:29 +02:00
|
|
|
|
return scm_module_define (module, scm_from_utf8_symbol (name), value);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_module_define (SCM module, SCM sym, SCM value)
|
|
|
|
|
|
#define FUNC_NAME "module-define"
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM var;
|
|
|
|
|
|
|
2012-05-23 11:46:30 +02:00
|
|
|
|
var = scm_module_ensure_local_variable (module, sym);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM_VARIABLE_SET (var, value);
|
2012-05-23 11:46:30 +02:00
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
return var;
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_define (const char *name, SCM value)
|
|
|
|
|
|
{
|
2011-10-25 17:45:29 +02:00
|
|
|
|
return scm_define (scm_from_utf8_symbol (name), value);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-11-30 22:17:46 +01:00
|
|
|
|
SCM_DEFINE (scm_define, "define!", 2, 0, 0,
|
|
|
|
|
|
(SCM sym, SCM value),
|
|
|
|
|
|
"Define @var{sym} to be @var{value} in the current module."
|
|
|
|
|
|
"Returns the variable itself. Note that this is a procedure, "
|
|
|
|
|
|
"not a macro.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_define
|
2001-05-15 14:57:22 +00:00
|
|
|
|
{
|
2009-11-30 22:17:46 +01:00
|
|
|
|
SCM_VALIDATE_SYMBOL (SCM_ARG1, sym);
|
2012-05-23 11:46:30 +02:00
|
|
|
|
|
|
|
|
|
|
return scm_module_define (scm_current_module (), sym, value);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
2009-11-30 22:17:46 +01:00
|
|
|
|
#undef FUNC_NAME
|
2001-05-15 14:57:22 +00:00
|
|
|
|
|
2007-05-05 20:38:57 +00:00
|
|
|
|
SCM_DEFINE (scm_module_reverse_lookup, "module-reverse-lookup", 2, 0, 0,
|
|
|
|
|
|
(SCM module, SCM variable),
|
|
|
|
|
|
"Return the symbol under which @var{variable} is bound in "
|
|
|
|
|
|
"@var{module} or @var{#f} if @var{variable} is not visible "
|
|
|
|
|
|
"from @var{module}. If @var{module} is @code{#f}, then the "
|
|
|
|
|
|
"pre-module obarray is used.")
|
|
|
|
|
|
#define FUNC_NAME s_scm_module_reverse_lookup
|
2001-05-15 14:57:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM obarray;
|
2001-05-26 20:51:22 +00:00
|
|
|
|
long i, n;
|
2001-05-15 14:57:22 +00:00
|
|
|
|
|
2004-07-06 10:59:25 +00:00
|
|
|
|
if (scm_is_false (module))
|
2001-05-15 14:57:22 +00:00
|
|
|
|
obarray = scm_pre_modules_obarray;
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM_VALIDATE_MODULE (1, module);
|
|
|
|
|
|
obarray = SCM_MODULE_OBARRAY (module);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-08 19:17:25 +02:00
|
|
|
|
SCM_VALIDATE_VARIABLE (SCM_ARG2, variable);
|
|
|
|
|
|
|
2003-09-12 15:11:09 +00:00
|
|
|
|
if (!SCM_HASHTABLE_P (obarray))
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
/* XXX - We do not use scm_hash_fold here to avoid searching the
|
|
|
|
|
|
whole obarray. We should have a scm_hash_find procedure. */
|
|
|
|
|
|
|
* hooks.c (scm_c_hook_add): Fixed bug in append mode.
* environments.c (obarray_enter, obarray_retrieve, obarray_remove,
leaf_environment_fold, obarray_remove_all): Use hashtable
accessors.
* gc.c (scm_init_storage): Moved hook initialization to
scm_storage_prehistory.
(scm_storage_prehistory): New function.
(scm_igc): Added commentary about placement of
scm_after_sweep_c_hook.
* gc-mark.c (scm_mark_all): Use hashtable accessors.
(scm_gc_mark_dependencies): Use SCM_WVECT_WEAK_KEY_P and
SCM_WVECT_WEAK_VALUE_P.
* hashtab.c, hashtab.h (scm_hash_for_each, scm_hash_map): New
functions.
(scm_vector_to_hash_table, scm_c_make_resizing_hash_table):
Removed.
(scm_make_weak_key_hash_table, scm_make_weak_value_hash_table,
scm_make_doubly_weak_hash_table): Moved here from weaks.c.
* init.c (scm_init_guile_1): Removed call to scm_init_weaks; Added
calls to scm_storage_prehistory and scm_hashtab_prehistory.
* modules.c (module-reverse-lookup): Use hashtable accessors.
* symbols.c, symbols.h (scm_i_hash_symbol): New function.
* weaks.c, weaks.h (scm_make_weak_key_alist_vector,
scm_make_weak_value_alist_vector,
scm_make_doubly_weak_alist_vector): New functions.
* weaks.c (scm_init_weaks_builtins): New function.
* weaks.h (SCM_WVECTF_WEAK_KEY, SCM_WVECTF_WEAK_VALUE,
SCM_WVECTF_NOSCAN, SCM_WVECT_WEAK_KEY_P, SCM_WVECT_WEAK_VALUE_P,
SCM_WVECT_NOSCAN_P): New macros.
* weaks.c (scm_scan_weak_vectors): Use SCM_WVECT_WEAK_KEY_P
and SCM_WVECT_WEAK_VALUE_P.
* weaks.c, weaks.h (scm_i_allocate_weak_vector): Renamed from
allocate_weak_vector and exported.
* Makefile.am (ice9_sources): Added weak-vector.scm.
* weak-vector.scm: New file.
* boot-9.scm (module-clear!): Use hash-clear!.
(module-for-each): Use hash-for-each.
(module-map): Use hash-map.
2003-02-19 15:04:51 +00:00
|
|
|
|
n = SCM_HASHTABLE_N_BUCKETS (obarray);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
|
|
{
|
2005-01-02 20:49:04 +00:00
|
|
|
|
SCM ls = SCM_HASHTABLE_BUCKET (obarray, i), handle;
|
2004-09-22 17:41:37 +00:00
|
|
|
|
while (!scm_is_null (ls))
|
2001-05-15 14:57:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
handle = SCM_CAR (ls);
|
2006-05-09 22:11:09 +00:00
|
|
|
|
|
2011-10-24 10:52:55 +02:00
|
|
|
|
if (scm_is_eq (SCM_CDR (handle), variable))
|
|
|
|
|
|
return SCM_CAR (handle);
|
2006-05-09 22:11:09 +00:00
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
ls = SCM_CDR (ls);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-08 19:17:25 +02:00
|
|
|
|
if (!scm_is_false (module))
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Try the `uses' list. */
|
|
|
|
|
|
SCM uses = SCM_MODULE_USES (module);
|
|
|
|
|
|
while (scm_is_pair (uses))
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM sym = scm_module_reverse_lookup (SCM_CAR (uses), variable);
|
|
|
|
|
|
if (scm_is_true (sym))
|
|
|
|
|
|
return sym;
|
|
|
|
|
|
uses = SCM_CDR (uses);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2001-05-15 14:57:22 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
SCM_SYMBOL (scm_sym_system_module, "system-module");
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_modules_prehistory ()
|
|
|
|
|
|
{
|
2012-02-19 15:19:14 +01:00
|
|
|
|
scm_pre_modules_obarray = scm_c_make_hash_table (1790);
|
2001-05-15 14:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1998-11-22 12:05:14 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_init_modules ()
|
|
|
|
|
|
{
|
2018-06-20 17:19:31 +02:00
|
|
|
|
#include "modules.x"
|
2001-05-15 14:57:22 +00:00
|
|
|
|
module_make_local_var_x_var = scm_c_define ("module-make-local-var!",
|
|
|
|
|
|
SCM_UNDEFINED);
|
2009-12-05 11:30:09 +01:00
|
|
|
|
the_module = scm_make_fluid ();
|
1998-11-22 12:05:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-05-15 14:57:22 +00:00
|
|
|
|
static void
|
1998-11-22 12:05:14 +00:00
|
|
|
|
scm_post_boot_init_modules ()
|
|
|
|
|
|
{
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM module_type = SCM_VARIABLE_REF (scm_c_lookup ("module-type"));
|
Remove indirection in structs
* libguile/gc.c (scm_storage_prehistory): Register struct displacement
here.
* libguile/goops.c (scm_sys_modify_instance): Fix the format of a
comment.
* libguile/modules.c (scm_post_boot_init_modules): Update for new format
of struct vtable references.
* libguile/struct.c (scm_i_alloc_struct): Update to include slots
directly, instead of being indirected by an embedded pointer.
(scm_c_make_structv, scm_allocate_struct, scm_i_make_vtable_vtable):
Adapt to pass vtable bits as argument to scm_i_alloc_struct, not
vtable data bits.
(scm_init_struct): Remove two-word displacement from libgc.
* libguile/struct.h: Update comment.
(SCM_STRUCT_SLOTS, SCM_STRUCT_DATA): Update definitions.
(SCM_STRUCT_VTABLE_DATA, SCM_STRUCT_VTABLE_SLOTS): Remove.
(SCM_STRUCT_VTABLE, SCM_STRUCT_LAYOUT, SCM_STRUCT_PRINTER)
(SCM_STRUCT_FINALIZER, SCM_STRUCT_VTABLE_FLAGS)
(SCM_STRUCT_VTABLE_FLAG_IS_SET): Simplify definitions.
* module/system/base/types.scm (cell->object, address->inferior-struct):
Adapt to struct representation change.
2017-09-07 16:55:30 +02:00
|
|
|
|
scm_module_tag = SCM_UNPACK (module_type) + scm_tc3_struct;
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
|
2009-12-05 11:30:09 +01:00
|
|
|
|
resolve_module_var = scm_c_lookup ("resolve-module");
|
2010-11-19 13:11:47 +01:00
|
|
|
|
define_module_star_var = scm_c_lookup ("define-module*");
|
2009-12-05 11:30:09 +01:00
|
|
|
|
process_use_modules_var = scm_c_lookup ("process-use-modules");
|
|
|
|
|
|
module_export_x_var = scm_c_lookup ("module-export!");
|
|
|
|
|
|
the_root_module_var = scm_c_lookup ("the-root-module");
|
|
|
|
|
|
default_duplicate_binding_procedures_var =
|
|
|
|
|
|
scm_c_lookup ("default-duplicate-binding-procedures");
|
2010-04-23 17:03:34 +02:00
|
|
|
|
module_public_interface_var = scm_c_lookup ("module-public-interface");
|
Use 'scm_from_utf8_{string,symbol,keyword}' for C string literals.
Partial fix for <https://bugs.gnu.org/33044>.
Reported by Tom de Vries <tdevries@suse.de>.
Fix several instances of the mistake of using 'scm_from_locale_*' for C
strings that originally came from a C string literal. Change several
uses of 'scm_from_latin1_*' as well, to promote the practice of writing
code that works for arbitrary C string literals.
Also add missing years to the copyright notices of changed files, based
on the git history.
* libguile/debug-malloc.c, libguile/deprecation.c, libguile/error.c,
libguile/eval.c, libguile/expand.c, libguile/extensions.c,
libguile/filesys.c, libguile/init.c, libguile/load.c,
libguile/modules.c, libguile/pairs.c, libguile/posix.c,
libguile/print.c, libguile/random.c, libguile/read.c,
libguile/regex-posix.c, libguile/snarf.h, libguile/srfi-13.c,
libguile/stacks.c, libguile/stime.c, libguile/strports.c,
libguile/values.c: Use 'scm_from_utf8_*' where appropriate.
2018-10-16 02:34:18 -04:00
|
|
|
|
k_ensure = scm_from_utf8_keyword ("ensure");
|
* modules.h, modules.c: Moved around a lot of code so that
deprecated features appear at the bottom.
(root_module_lookup_closure, scm_sym_app, scm_sym_modules,
module_prefix, make_modules_in_var, beautify_user_module_x_var,
scm_the_root_module, scm_make_module, scm_ensure_user_module,
scm_load_scheme_module): Deprecated.
(scm_system_module_env_p): Return SCM_BOOL_T directly for
environments corresponding to the root module.
(convert_module_name, scm_c_resolve_module,
scm_c_call_with_current_module, scm_c_define_module,
scm_c_use_module, scm_c_export): New.
(the_root_module): New static variant of scm_the_root_module. Use
it everywhere instead of scm_the_root_module.
2001-05-19 01:22:12 +00:00
|
|
|
|
|
2000-08-11 08:44:02 +00:00
|
|
|
|
scm_module_system_booted_p = 1;
|
1998-11-22 12:05:14 +00:00
|
|
|
|
}
|