[uim-commit] r2916 - branches/r5rs/sigscheme/src

yamaken at freedesktop.org yamaken at freedesktop.org
Sat Jan 14 10:43:57 PST 2006


Author: yamaken
Date: 2006-01-14 10:43:29 -0800 (Sat, 14 Jan 2006)
New Revision: 2916

Modified:
   branches/r5rs/sigscheme/src/eval.c
   branches/r5rs/sigscheme/src/operations-srfi34.c
   branches/r5rs/sigscheme/src/sigscheme.h
Log:
* sigscheme/src/sigscheme.h
  - (SCM_EVAL_STATE_INIT, SCM_EVAL_STATE_INIT1, SCM_EVAL_STATE_INIT2):
    New macro
* sigscheme/src/eval.c
  - (scm_call): Replace manual initialization of ScmEvalState with
    SCM_EVAL_STATE_INIT2()
* sigscheme/src/operations-srfi34.c
  - (guard_handler_body, guard_body): Replace manual initialization of
    ScmEvalState with SCM_EVAL_STATE_INIT1()


Modified: branches/r5rs/sigscheme/src/eval.c
===================================================================
--- branches/r5rs/sigscheme/src/eval.c	2006-01-14 17:36:29 UTC (rev 2915)
+++ branches/r5rs/sigscheme/src/eval.c	2006-01-14 18:43:29 UTC (rev 2916)
@@ -126,8 +126,7 @@
      * closure, it'll have its own environment, if it's a syntax, it's
      * an error, and if it's a C procedure, it doesn't have any free
      * variables at the Scheme level. */
-    state.env      = SCM_INTERACTION_ENV;
-    state.ret_type = SCM_RETTYPE_AS_IS;
+    SCM_EVAL_STATE_INIT2(state, SCM_INTERACTION_ENV, SCM_RETTYPE_AS_IS);
 
     ret = call(proc, args, &state, SUPPRESS_EVAL_ARGS);
     if (state.ret_type == SCM_RETTYPE_NEED_EVAL)
@@ -407,6 +406,7 @@
     scm_push_trace_frame(obj, env);
 #endif
 
+    /* intentionally does not use SCM_EVAL_STATE_INIT() to avoid overhead */
     state.env = env;
 
 eval_loop:

Modified: branches/r5rs/sigscheme/src/operations-srfi34.c
===================================================================
--- branches/r5rs/sigscheme/src/operations-srfi34.c	2006-01-14 17:36:29 UTC (rev 2915)
+++ branches/r5rs/sigscheme/src/operations-srfi34.c	2006-01-14 18:43:29 UTC (rev 2916)
@@ -358,8 +358,7 @@
     cond_env = scm_extend_environment(LIST_1(sym_var),
                                       LIST_1(condition),
                                       lex_env);
-    eval_state.env = cond_env;
-    eval_state.ret_type = SCM_RETTYPE_NEED_EVAL;
+    SCM_EVAL_STATE_INIT1(eval_state, cond_env);
     caught = scm_s_cond_internal(clauses, SCM_INVALID, &eval_state);
 
     if (VALIDP(caught)) {
@@ -387,8 +386,7 @@
     body    = scm_symbol_value(sym_body,    eval_state->env);
 
     /* evaluate the body */
-    lex_eval_state.env      = lex_env;
-    lex_eval_state.ret_type = SCM_RETTYPE_NEED_EVAL;
+    SCM_EVAL_STATE_INIT1(lex_eval_state, lex_env);
     result = scm_s_body(body, &lex_eval_state);
     if (lex_eval_state.ret_type == SCM_RETTYPE_NEED_EVAL)
         result = EVAL(result, lex_env);

Modified: branches/r5rs/sigscheme/src/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/src/sigscheme.h	2006-01-14 17:36:29 UTC (rev 2915)
+++ branches/r5rs/sigscheme/src/sigscheme.h	2006-01-14 18:43:29 UTC (rev 2916)
@@ -344,11 +344,6 @@
     SCM_REDUCE_STOP     /* Callee wants to stop. */
 };
 
-enum ScmReturnType {
-    SCM_RETTYPE_AS_IS     = 0,
-    SCM_RETTYPE_NEED_EVAL = 1
-};
-
 enum ScmPortFlag {
     SCM_PORTFLAG_NONE        = 0,
     SCM_PORTFLAG_OUTPUT      = 1 << 0,
@@ -380,13 +375,6 @@
 #include "storage-fatty.h"
 #endif /* SCM_OBJ_COMPACT */
 
-/* The evaluator's state */
-typedef struct ScmEvalState_ ScmEvalState;
-struct ScmEvalState_ {
-    ScmObj env;
-    enum ScmReturnType ret_type;
-};
-
 typedef struct ScmStorageConf_ ScmStorageConf;
 struct ScmStorageConf_ {
     /* heap */
@@ -641,6 +629,35 @@
 #define SCM_SYM_UNQUOTE_SPLICING SCM_SAL_SYM_UNQUOTE_SPLICING
 
 /*=======================================
+   Evaluator's State
+=======================================*/
+enum ScmReturnType {
+    SCM_RETTYPE_AS_IS     = 0,
+    SCM_RETTYPE_NEED_EVAL = 1
+};
+
+typedef struct ScmEvalState_ ScmEvalState;
+struct ScmEvalState_ {
+    ScmObj env;
+    enum ScmReturnType ret_type;
+};
+
+/* Use these constructors instead of manually initialize each members because
+ * another member may be added. Such member will implicitly be initialized
+ * properly as long as the constructors are used. */
+#define SCM_EVAL_STATE_INIT(state)                                           \
+    SCM_EVAL_STATE_INIT2((state), SCM_INTERACTION_ENV, SCM_RETTYPE_NEED_EVAL)
+
+#define SCM_EVAL_STATE_INIT1(state, env)                                     \
+    SCM_EVAL_STATE_INIT2((state), (env), SCM_RETTYPE_NEED_EVAL)
+
+#define SCM_EVAL_STATE_INIT2(state, _env, _ret_type)                         \
+    do {                                                                     \
+        (state).env      = (_env);                                           \
+        (state).ret_type = (_ret_type);                                      \
+    } while (/* CONSTCOND */ 0)
+
+/*=======================================
    Variable Declarations
 =======================================*/
 /* storage-gc.c */



More information about the uim-commit mailing list