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

yamaken at freedesktop.org yamaken at freedesktop.org
Fri Dec 9 19:50:38 PST 2005


Author: yamaken
Date: 2005-12-09 19:50:34 -0800 (Fri, 09 Dec 2005)
New Revision: 2508

Modified:
   branches/r5rs/sigscheme/main.c
Log:
* sigscheme/main.c
  - (repl_loop):
    * Make 'read' error-proof
    * Eliminate result printing when error
    * Simplify
  - (is_repl_prompt, show_promptp): Rename is_repl_prompt() to
    show_promptp()
  - (main): Simplify


Modified: branches/r5rs/sigscheme/main.c
===================================================================
--- branches/r5rs/sigscheme/main.c	2005-12-10 03:02:51 UTC (rev 2507)
+++ branches/r5rs/sigscheme/main.c	2005-12-10 03:50:34 UTC (rev 2508)
@@ -67,7 +67,7 @@
 =======================================*/
 static void repl(void);
 static void repl_loop(void);
-static int  is_repl_prompt(void);
+static int show_promptp(void);
 
 /*=======================================
   Function Implementations
@@ -91,52 +91,66 @@
 
 static void repl_loop(void)
 {
-    ScmObj s_exp      = SCM_FALSE;
-    ScmObj result     = SCM_FALSE;
-    ScmObj sym_guard  = SCM_FALSE;
-    ScmObj cond_catch = SCM_FALSE;
-    int is_prompt     = is_repl_prompt();
+    ScmObj sexp, result;
+#if SCM_USE_SRFI34
+    ScmObj sym_guard, cond_catch, proc_read, err;
 
-#if SCM_USE_SRFI34
+    proc_read = Scm_SymbolValue(Scm_Intern("read"), SCM_INTERACTION_ENV);
+    err = CONS(SCM_UNDEF, SCM_UNDEF); /* unique ID */
+
     /* prepare the constant part of the form to get the loop fast */
     sym_guard = Scm_Intern("guard");
     cond_catch = LIST_2(Scm_Intern("err"),
-                        LIST_2(SYM_ELSE,
+                        LIST_3(SYM_ELSE,
                                LIST_2(Scm_Intern("%%inspect-error"),
-                                      Scm_Intern("err"))));
+                                      Scm_Intern("err")),
+                               LIST_2(SCM_SYM_QUOTE, err)));
 #endif /* SCM_USE_SRFI34 */
 
-    if (is_prompt)
-        SigScm_PortPrintf(scm_current_output_port, PROMPT_STR);
+    for (;;) {
+        if (show_promptp())
+            SCM_PORT_PUTS(scm_current_output_port, PROMPT_STR);
 
-    while (s_exp = SigScm_Read(scm_current_input_port), !EOFP(s_exp)) {
 #if SCM_USE_SRFI34
+        /* error-proof read */
+        sexp = EVAL(LIST_3(sym_guard, cond_catch,
+                           LIST_2(proc_read, scm_current_input_port)),
+                    SCM_INTERACTION_ENV);
+        if (EOFP(sexp))
+            break;
+        if (EQ(sexp, err))
+            continue;
+
         /*
          * Error-proof evaluation
          *
          * (guard (err
          *         (else
-         *          (%%inspect-error err)))
+         *          (%%inspect-error err)
+         *          #<err>))
          *   exp)
          *
          * To allow redefinition of 'guard' and '%%inspect-err', surely access
          * them via symbol instead of prepared syntax or procedure object.
          */
-        result = EVAL(LIST_3(sym_guard, cond_catch, s_exp),
+        result = EVAL(LIST_3(sym_guard, cond_catch, sexp),
                       SCM_INTERACTION_ENV);
 #else /* SCM_USE_SRFI34 */
-        result = EVAL(s_exp, SCM_INTERACTION_ENV);
+        sexp = SigScm_Read(scm_current_input_port)
+        if (EOFP(sexp))
+            break;
+
+        result = EVAL(sexp, SCM_INTERACTION_ENV);
 #endif /* SCM_USE_SRFI34 */
 
-        SCM_WRITESS_TO_PORT(scm_current_output_port, result);
-        SigScm_PortNewline(scm_current_output_port);
-
-        if (is_prompt)
-            SigScm_PortPrintf(scm_current_output_port, PROMPT_STR);
+        if (!EQ(result, err)) {
+            SCM_WRITESS_TO_PORT(scm_current_output_port, result);
+            SigScm_PortNewline(scm_current_output_port);
+        }
     }
 }
 
-static int is_repl_prompt(void)
+static int show_promptp(void)
 {
 #if SCM_COMPAT_SIOD
     return (FALSEP(ScmOp_providedp(feature_id_siod))
@@ -148,7 +162,7 @@
 
 int main(int argc, char **argv)
 {
-    const char *filename = NULL;
+    const char *filename;
     char **rest_argv;
 
     /* must be done before SigScm_Initialize() */



More information about the uim-commit mailing list