[uim-commit] r1779 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Mon Oct 3 14:21:34 PDT 2005


Author: yamaken
Date: 2005-10-03 14:21:31 -0700 (Mon, 03 Oct 2005)
New Revision: 1779

Modified:
   branches/r5rs/sigscheme/operations-siod.c
   branches/r5rs/sigscheme/sigscheme.c
   branches/r5rs/sigscheme/sigscheme.h
Log:
* This commit introduces a syntax 'use' to enable builtin optional
  features dynamically

* sigscheme/sigscheme.h
  - (ScmExp_use): New function decl
* sigscheme/sigscheme.c
  - (struct module_info): New type
  - (module_info_table): New variable
  - (ScmExp_use): New function
  - (SigScm_Initialize_internal):
    - Add initialization for 'use'
    - Replace optional procedures initialization with ScmExp_use()
* sigscheme/operations-siod.c
  - (SigScm_Initialize_SIOD): Add runtime SRFI-60 initialization as
    dependency resolution on dynamic SIOD-compatible feature
    initialization


Modified: branches/r5rs/sigscheme/operations-siod.c
===================================================================
--- branches/r5rs/sigscheme/operations-siod.c	2005-10-03 21:21:00 UTC (rev 1778)
+++ branches/r5rs/sigscheme/operations-siod.c	2005-10-03 21:21:31 UTC (rev 1779)
@@ -91,23 +91,22 @@
 =======================================*/
 void SigScm_Initialize_SIOD(void)
 {
-    /*=======================================================================
-      SIOD Compatible Variables and Procedures
-    =======================================================================*/
+    ScmExp_use(Scm_Intern("srfi-60"), SCM_INTERACTION_ENV);
+    Scm_DefineAlias("bit-and"               , "logand");
+    Scm_DefineAlias("bit-or"                , "logior");
+    Scm_DefineAlias("bit-xor"               , "logxor");
+    Scm_DefineAlias("bit-not"               , "lognot");
+
     Scm_RegisterProcedureVariadic1("symbol-bound?"     , ScmOp_symbol_boundp);
     Scm_RegisterProcedureFixed1("symbol-value"         , ScmOp_symbol_value);
     Scm_RegisterProcedureFixed2("set-symbol-value!"    , ScmOp_set_symbol_value);
 #if SCM_COMPAT_SIOD_BUGS
     Scm_RegisterProcedureFixed2("="                    , ScmOp_siod_eql);
 #endif
-    Scm_DefineAlias("bit-and"               , "logand");
-    Scm_DefineAlias("bit-or"                , "logior");
-    Scm_DefineAlias("bit-xor"               , "logxor");
-    Scm_DefineAlias("bit-not"               , "lognot");
     Scm_RegisterProcedureFixedTailRec0("the-environment" , ScmOp_the_environment);
     Scm_RegisterProcedureFixed1("%%closure-code"       , ScmOp_closure_code);
     Scm_RegisterProcedureVariadic0("verbose" , ScmOp_verbose);
-    /* datas.c */
+
     SigScm_SetVerboseLevel(2);
 }
 

Modified: branches/r5rs/sigscheme/sigscheme.c
===================================================================
--- branches/r5rs/sigscheme/sigscheme.c	2005-10-03 21:21:00 UTC (rev 1778)
+++ branches/r5rs/sigscheme/sigscheme.c	2005-10-03 21:21:31 UTC (rev 1779)
@@ -44,6 +44,10 @@
 /*=======================================
   File Local Struct Declarations
 =======================================*/
+struct module_info {
+    const char *name;
+    void (*initializer)(void);
+};
 
 /*=======================================
   File Local Macro Declarations
@@ -61,6 +65,39 @@
 static ScmObj scm_return_value    = NULL;
 #endif
 
+static struct module_info module_info_table[] = {
+#if SCM_USE_NONSTD_FEATURES
+#if 0
+    {"sscm", SigScm_Initialize_NONSTD_FEATURES},
+#endif
+#endif
+#if SCM_USE_SRFI1
+    {"srfi-1", SigScm_Initialize_SRFI1},
+#endif
+#if SCM_USE_SRFI2
+    {"srfi-2", SigScm_Initialize_SRFI2},
+#endif
+#if SCM_USE_SRFI8
+    {"srfi-8", SigScm_Initialize_SRFI8},
+#endif
+#if SCM_USE_SRFI23
+    {"srfi-23", SigScm_Initialize_SRFI23},
+#endif
+#if SCM_USE_SRFI34
+    {"srfi-34", SigScm_Initialize_SRFI34},
+#endif
+#if SCM_USE_SRFI38
+    {"srfi-38", SigScm_Initialize_SRFI38},
+#endif
+#if SCM_USE_SRFI60
+    {"srfi-60", SigScm_Initialize_SRFI60},
+#endif
+#if SCM_COMPAT_SIOD
+    {"siod", SigScm_Initialize_SIOD},
+#endif
+    {NULL, NULL}
+};
+
 /*=======================================
   File Local Function Declarations
 =======================================*/
@@ -335,33 +372,22 @@
     Scm_RegisterProcedureFixed1("provided?"                , ScmOp_providedp);
     Scm_RegisterProcedureFixed1("file-exists?"             , ScmOp_file_existsp);
     Scm_RegisterProcedureFixed1("delete-file"              , ScmOp_delete_file);
+
+    Scm_RegisterSyntaxFixed1("use"                         , ScmExp_use);
     Scm_DefineAlias("call/cc", "call-with-current-continuation");
 #endif
 
-#if SCM_USE_SRFI1
-    SigScm_Initialize_SRFI1();
+#if 1
+    /* enable all features for backward compatibility */
+    ScmExp_use(Scm_Intern("srfi-1"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-2"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-8"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-23"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-34"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-38"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("srfi-60"), SCM_INTERACTION_ENV);
+    ScmExp_use(Scm_Intern("siod"), SCM_INTERACTION_ENV);
 #endif
-#if SCM_USE_SRFI2
-    SigScm_Initialize_SRFI2();
-#endif
-#if SCM_USE_SRFI8
-    SigScm_Initialize_SRFI8();
-#endif
-#if SCM_USE_SRFI23
-    SigScm_Initialize_SRFI23();
-#endif
-#if SCM_USE_SRFI34
-    SigScm_Initialize_SRFI34();
-#endif
-#if SCM_USE_SRFI38
-    SigScm_Initialize_SRFI38();
-#endif
-#if SCM_USE_SRFI60
-    SigScm_Initialize_SRFI60();
-#endif
-#if SCM_COMPAT_SIOD
-    SigScm_Initialize_SIOD();
-#endif
 }
 
 void SigScm_Finalize()
@@ -375,6 +401,38 @@
                          SCM_SYMBOL_VCELL(Scm_Intern(sym)));
 }
 
+/*
+ * TODO:
+ * - Make the interface and semantics of 'use' similar to other Scheme
+ *   implementations such as Gauche. This is important to make *.scm file
+ *   portable
+ * - Make a *.scm file loadable via this interface (if necessary to make
+ *   similar to other Scheme implementations), and make consistent with
+ *   'require'
+ * - Make the 'module' concept similar to other Scheme implementations and R6RS
+ * - Make the module_info_table dynamically registerable for dynamic loadable
+ *   objects (if necessary)
+ */
+ScmObj ScmExp_use(ScmObj feature, ScmObj env)
+{
+    struct module_info *mod = NULL;
+    DECLARE_FUNCTION("use", SyntaxFixed1);
+
+    ASSERT_SYMBOLP(feature);
+
+    for (mod = module_info_table; mod->name; mod++) {
+        if (EQ(feature, Scm_Intern(mod->name))) {
+            if (FALSEP(ScmOp_providedp(feature))) {
+                (*mod->initializer)();
+                ScmOp_provide(feature);
+            }
+            return SCM_TRUE;
+        }
+    }
+
+    return SCM_FALSE;
+}
+
 ScmObj Scm_eval_c_string(const char *exp)
 {
 #if !SCM_GCC4_READY_GC

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2005-10-03 21:21:00 UTC (rev 1778)
+++ branches/r5rs/sigscheme/sigscheme.h	2005-10-03 21:21:31 UTC (rev 1779)
@@ -173,6 +173,7 @@
 void SigScm_Initialize(void);
 void SigScm_Finalize(void);
 void Scm_DefineAlias(const char *newsym, const char *sym);
+ScmObj ScmExp_use(ScmObj feature, ScmObj env);
 ScmObj Scm_eval_c_string(const char *exp);
 #if SCM_COMPAT_SIOD
 ScmObj Scm_return_value(void);



More information about the uim-commit mailing list