*** empty log message ***
[bpt/guile.git] / libguile / modules.c
index 951ee41..d2d1d44 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998,2000,2001,2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1998,2000,2001,2002, 2003, 2004 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
@@ -12,7 +12,7 @@
  *
  * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 
@@ -91,6 +91,11 @@ scm_c_call_with_current_module (SCM module,
   return scm_c_with_fluid (the_module, module, func, data);
 }
 
+void
+scm_frame_current_module (SCM module)
+{
+  scm_frame_fluid (the_module, module);
+}
 
 /*
   convert "A B C" to scheme list (A B C)
@@ -111,7 +116,8 @@ convert_module_name (const char *name)
        ptr++;
       if (ptr > name)
        {
-         *tail = scm_cons (scm_mem2symbol (name, ptr-name), SCM_EOL);
+         SCM sym = scm_from_locale_symboln (name, ptr-name);
+         *tail = scm_cons (sym, SCM_EOL);
          tail = SCM_CDRLOC (*tail);
        }
       name = ptr;
@@ -185,7 +191,7 @@ scm_c_export (const char *name, ...)
   if (name)
     {
       va_list ap;
-      SCM names = scm_cons (scm_str2symbol (name), SCM_EOL);
+      SCM names = scm_cons (scm_from_locale_symbol (name), SCM_EOL);
       SCM *tail = SCM_CDRLOC (names);
       va_start (ap, name);
       while (1)
@@ -193,7 +199,7 @@ scm_c_export (const char *name, ...)
          const char *n = va_arg (ap, const char *);
          if (n == NULL)
            break;
-         *tail = scm_cons (scm_str2symbol (n), SCM_EOL);
+         *tail = scm_cons (scm_from_locale_symbol (n), SCM_EOL);
          tail = SCM_CDRLOC (*tail);
        }
       va_end (ap);
@@ -216,10 +222,10 @@ scm_top_level_env (SCM thunk)
 SCM
 scm_env_top_level (SCM env)
 {
-  while (SCM_CONSP (env))
+  while (scm_is_pair (env))
     {
       SCM car_env = SCM_CAR (env);
-      if (!SCM_CONSP (car_env) && !SCM_FALSEP (scm_procedure_p (car_env)))
+      if (!scm_is_pair (car_env) && scm_is_true (scm_procedure_p (car_env)))
        return car_env;
       env = SCM_CDR (env);
     }
@@ -242,14 +248,14 @@ the_root_module ()
 SCM
 scm_lookup_closure_module (SCM proc)
 {
-  if (SCM_FALSEP (proc))
+  if (scm_is_false (proc))
     return the_root_module ();
   else if (SCM_EVAL_CLOSURE_P (proc))
     return SCM_PACK (SCM_SMOB_DATA (proc));
   else
     {
       SCM mod = scm_procedure_property (proc, sym_module);
-      if (SCM_FALSEP (mod))
+      if (scm_is_false (mod))
        mod = the_root_module ();
       return mod;
     }
@@ -277,7 +283,7 @@ static SCM
 module_variable (SCM module, SCM sym)
 {
 #define SCM_BOUND_THING_P(b) \
-  (!SCM_FALSEP (b))
+  (scm_is_true (b))
 
   /* 1. Check module obarray */
   SCM b = scm_hashq_ref (SCM_MODULE_OBARRAY (module), sym, SCM_UNDEFINED);
@@ -285,7 +291,7 @@ module_variable (SCM module, SCM sym)
     return b;
   {
     SCM binder = SCM_MODULE_BINDER (module);
-    if (!SCM_FALSEP (binder))
+    if (scm_is_true (binder))
       /* 2. Custom binder */
       {
        b = scm_call_3 (binder, module, sym, SCM_BOOL_F);
@@ -296,7 +302,7 @@ module_variable (SCM module, SCM sym)
   {
     /* 3. Search the use list */
     SCM uses = SCM_MODULE_USES (module);
-    while (SCM_CONSP (uses))
+    while (scm_is_pair (uses))
       {
        b = module_variable (SCM_CAR (uses), sym);
        if (SCM_BOUND_THING_P (b))
@@ -320,7 +326,7 @@ SCM
 scm_eval_closure_lookup (SCM eclo, SCM sym, SCM definep)
 {
   SCM module = SCM_PACK (SCM_SMOB_DATA (eclo));
-  if (!SCM_FALSEP (definep))
+  if (scm_is_true (definep))
     {
       if (SCM_EVAL_CLOSURE_INTERFACE_P (eclo))
        return SCM_BOOL_F;
@@ -340,6 +346,19 @@ SCM_DEFINE (scm_standard_eval_closure, "standard-eval-closure", 1, 0, 0,
 }
 #undef FUNC_NAME
 
+
+SCM_DEFINE (scm_eval_closure_module, "eval-closure-module", 1, 0, 0,
+           (SCM closure),
+           "Return the module for @var{closure}.")
+#define FUNC_NAME s_scm_eval_closure_module
+{
+  SCM_ASSERT_TYPE(SCM_EVAL_CLOSURE_P (closure), closure, SCM_ARG1, FUNC_NAME, "eval-closure");
+  return SCM_PACK (SCM_CELL_WORD_1(closure));
+}
+#undef FUNC_NAME
+
+
 SCM_DEFINE (scm_standard_interface_eval_closure,
            "standard-interface-eval-closure", 1, 0, 0,
            (SCM module),
@@ -355,7 +374,7 @@ SCM_DEFINE (scm_standard_interface_eval_closure,
 SCM
 scm_module_lookup_closure (SCM module)
 {
-  if (SCM_FALSEP (module))
+  if (scm_is_false (module))
     return SCM_BOOL_F;
   else
     return SCM_MODULE_EVAL_CLOSURE (module);
@@ -373,7 +392,7 @@ scm_current_module_lookup_closure ()
 SCM
 scm_module_transformer (SCM module)
 {
-  if (SCM_FALSEP (module))
+  if (scm_is_false (module))
     return SCM_BOOL_F;
   else
     return SCM_MODULE_TRANSFORMER (module);
@@ -393,12 +412,12 @@ SCM_DEFINE (scm_module_import_interface, "module-import-interface", 2, 0, 0,
            "")
 #define FUNC_NAME s_scm_module_import_interface
 {
-#define SCM_BOUND_THING_P(b) (!SCM_FALSEP (b))
+#define SCM_BOUND_THING_P(b) (scm_is_true (b))
   SCM uses;
   SCM_VALIDATE_MODULE (SCM_ARG1, module);
   /* Search the use list */
   uses = SCM_MODULE_USES (module);
-  while (SCM_CONSP (uses))
+  while (scm_is_pair (uses))
     {
       SCM _interface = SCM_CAR (uses);
       /* 1. Check module obarray */
@@ -407,7 +426,7 @@ SCM_DEFINE (scm_module_import_interface, "module-import-interface", 2, 0, 0,
        return _interface;
       {
        SCM binder = SCM_MODULE_BINDER (_interface);
-       if (!SCM_FALSEP (binder))
+       if (scm_is_true (binder))
          /* 2. Custom binder */
          {
            b = scm_call_3 (binder, _interface, sym, SCM_BOOL_F);
@@ -417,7 +436,7 @@ SCM_DEFINE (scm_module_import_interface, "module-import-interface", 2, 0, 0,
       }
       /* 3. Search use list recursively. */
       _interface = scm_module_import_interface (_interface, sym);
-      if (!SCM_FALSEP (_interface))
+      if (scm_is_true (_interface))
        return _interface;
       uses = SCM_CDR (uses);
     }
@@ -460,14 +479,14 @@ scm_sym2var (SCM sym, SCM proc, SCM definep)
     {
       SCM handle;
 
-      if (SCM_FALSEP (definep))
+      if (scm_is_false (definep))
        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 (SCM_FALSEP (var))
+         if (scm_is_false (var))
            {
              var = scm_make_variable (SCM_UNDEFINED);
              SCM_SETCDR (handle, var);
@@ -475,7 +494,7 @@ scm_sym2var (SCM sym, SCM proc, SCM definep)
        }
     }
 
-  if (!SCM_FALSEP (var) && !SCM_VARIABLEP (var))
+  if (scm_is_true (var) && !SCM_VARIABLEP (var))
     SCM_MISC_ERROR ("~S is not bound to a variable", scm_list_1 (sym));
 
   return var;
@@ -485,7 +504,7 @@ scm_sym2var (SCM sym, SCM proc, SCM definep)
 SCM
 scm_c_module_lookup (SCM module, const char *name)
 {
-  return scm_module_lookup (module, scm_str2symbol (name));
+  return scm_module_lookup (module, scm_from_locale_symbol (name));
 }
 
 SCM
@@ -496,7 +515,7 @@ scm_module_lookup (SCM module, SCM sym)
   SCM_VALIDATE_MODULE (1, module);
 
   var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
-  if (SCM_FALSEP (var))
+  if (scm_is_false (var))
     SCM_MISC_ERROR ("unbound variable: ~S", scm_list_1 (sym));
   return var;
 }
@@ -505,7 +524,7 @@ scm_module_lookup (SCM module, SCM sym)
 SCM
 scm_c_lookup (const char *name)
 {
-  return scm_lookup (scm_str2symbol (name));
+  return scm_lookup (scm_from_locale_symbol (name));
 }
 
 SCM
@@ -513,7 +532,7 @@ scm_lookup (SCM sym)
 {
   SCM var = 
     scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_F);
-  if (SCM_FALSEP (var))
+  if (scm_is_false (var))
     scm_misc_error ("scm_lookup", "unbound variable: ~S", scm_list_1 (sym));
   return var;
 }
@@ -521,7 +540,7 @@ scm_lookup (SCM sym)
 SCM
 scm_c_module_define (SCM module, const char *name, SCM value)
 {
-  return scm_module_define (module, scm_str2symbol (name), value);
+  return scm_module_define (module, scm_from_locale_symbol (name), value);
 }
 
 SCM
@@ -540,7 +559,7 @@ scm_module_define (SCM module, SCM sym, SCM value)
 SCM
 scm_c_define (const char *name, SCM value)
 {
-  return scm_define (scm_str2symbol (name), value);
+  return scm_define (scm_from_locale_symbol (name), value);
 }
 
 SCM
@@ -559,7 +578,7 @@ scm_module_reverse_lookup (SCM module, SCM variable)
   SCM obarray;
   long i, n;
 
-  if (SCM_FALSEP (module))
+  if (scm_is_false (module))
     obarray = scm_pre_modules_obarray;
   else
     {
@@ -576,8 +595,8 @@ scm_module_reverse_lookup (SCM module, SCM variable)
   n = SCM_HASHTABLE_N_BUCKETS (obarray);
   for (i = 0; i < n; ++i)
     {
-      SCM ls = SCM_HASHTABLE_BUCKETS (obarray)[i], handle;
-      while (!SCM_NULLP (ls))
+      SCM ls = SCM_HASHTABLE_BUCKET (obarray, i), handle;
+      while (!scm_is_null (ls))
        {
          handle = SCM_CAR (ls);
          if (SCM_CDR (handle) == variable)
@@ -590,10 +609,10 @@ scm_module_reverse_lookup (SCM module, SCM variable)
    */
   {
     SCM uses = SCM_MODULE_USES (module);
-    while (SCM_CONSP (uses))
+    while (scm_is_pair (uses))
       {
        SCM sym = scm_module_reverse_lookup (SCM_CAR (uses), variable);
-       if (!SCM_FALSEP (sym))
+       if (scm_is_true (sym))
          return sym;
        uses = SCM_CDR (uses);
       }
@@ -620,9 +639,9 @@ SCM
 scm_system_module_env_p (SCM env)
 {
   SCM proc = scm_env_top_level (env);
-  if (SCM_FALSEP (proc))
+  if (scm_is_false (proc))
     return SCM_BOOL_T;
-  return ((!SCM_FALSEP (scm_procedure_property (proc,
+  return ((scm_is_true (scm_procedure_property (proc,
                                                scm_sym_system_module)))
          ? SCM_BOOL_T
          : SCM_BOOL_F);