summaryrefslogtreecommitdiff
path: root/libguile/modules.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/modules.c')
-rw-r--r--libguile/modules.c103
1 files changed, 57 insertions, 46 deletions
diff --git a/libguile/modules.c b/libguile/modules.c
index e4cccd2bc..0e8f083a0 100644
--- a/libguile/modules.c
+++ b/libguile/modules.c
@@ -1,21 +1,21 @@
-/* Copyright (C) 1998, 2000-2004, 2006-2012, 2018
- * Free Software Foundation, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
+/* Copyright 1998,2000-2004,2006-2012,2017-2019
+ 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/>. */
@@ -25,19 +25,25 @@
#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 "boolean.h"
+#include "deprecation.h"
+#include "eval.h"
+#include "fluids.h"
+#include "gsubr.h"
+#include "hashtab.h"
+#include "keywords.h"
+#include "list.h"
+#include "pairs.h"
+#include "procprop.h"
+#include "smob.h"
+#include "struct.h"
+#include "symbols.h"
+#include "threads.h"
+#include "variable.h"
+#include "vectors.h"
+
+#include "modules.h"
-#include "libguile/modules.h"
int scm_module_system_booted_p = 0;
@@ -76,15 +82,21 @@ scm_the_root_module (void)
return SCM_BOOL_F;
}
+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;
+}
+
SCM_DEFINE (scm_current_module, "current-module", 0, 0, 0,
(),
"Return the current module.")
#define FUNC_NAME s_scm_current_module
{
- if (scm_module_system_booted_p)
- return scm_fluid_ref (the_module);
- else
- return SCM_BOOL_F;
+ return scm_i_current_module (SCM_I_CURRENT_THREAD);
}
#undef FUNC_NAME
@@ -178,6 +190,13 @@ scm_resolve_module (SCM name)
}
SCM
+scm_maybe_resolve_module (SCM name)
+{
+ return scm_call_3 (SCM_VARIABLE_REF (resolve_module_var), name,
+ k_ensure, SCM_BOOL_F);
+}
+
+SCM
scm_c_define_module (const char *name,
void (*init)(void *), void *data)
{
@@ -651,8 +670,7 @@ scm_public_variable (SCM module_name, SCM name)
{
SCM mod, iface;
- mod = scm_call_3 (scm_variable_ref (resolve_module_var), module_name,
- k_ensure, SCM_BOOL_F);
+ mod = scm_maybe_resolve_module (module_name);
if (scm_is_false (mod))
scm_misc_error ("public-lookup", "Module named ~s does not exist",
@@ -672,8 +690,7 @@ scm_private_variable (SCM module_name, SCM name)
{
SCM mod;
- mod = scm_call_3 (scm_variable_ref (resolve_module_var), module_name,
- k_ensure, SCM_BOOL_F);
+ mod = scm_maybe_resolve_module (module_name);
if (scm_is_false (mod))
scm_misc_error ("private-lookup", "Module named ~s does not exist",
@@ -883,7 +900,7 @@ scm_modules_prehistory ()
void
scm_init_modules ()
{
-#include "libguile/modules.x"
+#include "modules.x"
module_make_local_var_x_var = scm_c_define ("module-make-local-var!",
SCM_UNDEFINED);
the_module = scm_make_fluid ();
@@ -893,7 +910,7 @@ static void
scm_post_boot_init_modules ()
{
SCM module_type = SCM_VARIABLE_REF (scm_c_lookup ("module-type"));
- scm_module_tag = (SCM_CELL_WORD_1 (module_type) + scm_tc3_struct);
+ scm_module_tag = SCM_UNPACK (module_type) + scm_tc3_struct;
resolve_module_var = scm_c_lookup ("resolve-module");
define_module_star_var = scm_c_lookup ("define-module*");
@@ -907,9 +924,3 @@ scm_post_boot_init_modules ()
scm_module_system_booted_p = 1;
}
-
-/*
- Local Variables:
- c-file-style: "gnu"
- End:
-*/