[armedbear-cvs] r13168 - in branches/0.24.x/abcl/src/org/armedbear/lisp: . java/swing

Erik Huelsmann ehuelsmann at common-lisp.net
Fri Jan 21 22:12:09 UTC 2011


Author: ehuelsmann
Date: Fri Jan 21 17:12:08 2011
New Revision: 13168

Log:
Merge r13141-13146 and r13156: Make sure ABCL doesn't call System.exit()
in order to be a well-behaving library.

Added:
   branches/0.24.x/abcl/src/org/armedbear/lisp/IntegrityError.java
      - copied unchanged from r13146, /trunk/abcl/src/org/armedbear/lisp/IntegrityError.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/ProcessingTerminated.java
      - copied, changed from r13146, /trunk/abcl/src/org/armedbear/lisp/ProcessingTerminated.java
Modified:
   branches/0.24.x/abcl/src/org/armedbear/lisp/Autoload.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/Extensions.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/Interpreter.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/Lisp.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/Main.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/Primitives.java
   branches/0.24.x/abcl/src/org/armedbear/lisp/java/swing/REPLConsole.java

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Autoload.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Autoload.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Autoload.java	Fri Jan 21 17:12:08 2011
@@ -141,7 +141,7 @@
             if (symbol != null) {
                 if (symbol.getSymbolFunction() instanceof Autoload) {
                     Debug.trace("Unable to autoload " + symbol.writeToString());
-                    System.exit(-1);
+                    throw new IntegrityError();
                 }
             }
         }

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Extensions.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Extensions.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Extensions.java	Fri Jan 21 17:12:08 2011
@@ -200,8 +200,7 @@
     @Override
     public LispObject execute()
     {
-      exit(0);
-      return LispThread.currentThread().nothing();
+      throw new ProcessingTerminated();
     }
     @Override
     public LispObject execute(LispObject first, LispObject second)
@@ -213,8 +212,7 @@
           if (second instanceof Fixnum)
             status = ((Fixnum)second).value;
         }
-      exit(status);
-      return LispThread.currentThread().nothing();
+      throw new ProcessingTerminated(status);
     }
   }
 
@@ -229,8 +227,7 @@
     {
       ((Stream)Symbol.STANDARD_OUTPUT.getSymbolValue())._finishOutput();
       ((Stream)Symbol.ERROR_OUTPUT.getSymbolValue())._finishOutput();
-      exit(0);
-      return LispThread.currentThread().nothing();
+      throw new ProcessingTerminated();
     }
     @Override
     public LispObject execute(LispObject first, LispObject second)
@@ -241,8 +238,7 @@
           if (second instanceof Fixnum)
             status = ((Fixnum)second).value;
         }
-      exit(status);
-      return LispThread.currentThread().nothing();
+      throw new ProcessingTerminated(status);
     }
   }
 

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Interpreter.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Interpreter.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Interpreter.java	Fri Jan 21 17:12:08 2011
@@ -89,7 +89,7 @@
             Stream out = getStandardOutput();
             out._writeString(help());
             out._finishOutput();
-            exit(0);
+            exit(0); // FIXME
         }
         if (noinform)
             _NOINFORM_.setSymbolValue(T);
@@ -253,7 +253,7 @@
                         ++i;
                     } else {
                         System.err.println("No argument supplied to --eval");
-                        exit(1);
+                        exit(1); // FIXME
                     }
                 } else if (arg.equals("--load") ||
                            arg.equals("--load-system-file")) {
@@ -261,7 +261,7 @@
                         ++i;
                     } else {
                         System.err.println("No argument supplied to --load");
-                        exit(1);
+                        exit(1); // FIXME
                     }
                 } else {
                     arglist = new Cons(args[i], arglist);
@@ -301,13 +301,13 @@
                             sb.append(c.getCondition().writeToString());
                             sb.append(separator);
                             System.err.print(sb.toString());
-                            exit(2);
+                            exit(2); // FIXME
                         }
                         ++i;
                     } else {
                         // Shouldn't happen.
                         System.err.println("No argument supplied to --eval");
-                        exit(1);
+                        exit(1); // FIXME
                     }
                 } else if (arg.equals("--load") ||
                            arg.equals("--load-system-file")) {
@@ -322,16 +322,17 @@
                     } else {
                         // Shouldn't happen.
                         System.err.println("No argument supplied to --load");
-                        exit(1);
+                        exit(1);  // FIXME
                     }
                 }
             }
         }
         if (_BATCH_MODE_.getSymbolValue() == T) {
-            exit(0);
+            exit(0); // FIXME
         }
     }
 
+    @SuppressWarnings("CallToThreadDumpStack")
     public void run()
     {
         final LispThread thread = LispThread.currentThread();
@@ -342,66 +343,80 @@
                 thread.execute(tplFun);
                 return;
             }
-            // We only arrive here if something went wrong and we weren't able
-            // to load top-level.lisp and run the normal top-level loop.
-            Stream out = getStandardOutput();
-            while (true) {
-                try {
-                    thread.resetStack();
-                    thread.clearSpecialBindings();
-                    out._writeString("* ");
-                    out._finishOutput();
-                    LispObject object =
-                        getStandardInput().read(false, EOF, false, thread,
-                                                Stream.currentReadtable);
-                    if (object == EOF)
-                        break;
-                    out.setCharPos(0);
-                    Symbol.MINUS.setSymbolValue(object);
-                    LispObject result = Lisp.eval(object, new Environment(), thread);
-                    Debug.assertTrue(result != null);
-                    Symbol.STAR_STAR_STAR.setSymbolValue(Symbol.STAR_STAR.getSymbolValue());
-                    Symbol.STAR_STAR.setSymbolValue(Symbol.STAR.getSymbolValue());
-                    Symbol.STAR.setSymbolValue(result);
-                    Symbol.PLUS_PLUS_PLUS.setSymbolValue(Symbol.PLUS_PLUS.getSymbolValue());
-                    Symbol.PLUS_PLUS.setSymbolValue(Symbol.PLUS.getSymbolValue());
-                    Symbol.PLUS.setSymbolValue(Symbol.MINUS.getSymbolValue());
-                    out = getStandardOutput();
-                    out.freshLine();
-                    LispObject[] values = thread.getValues();
-                    Symbol.SLASH_SLASH_SLASH.setSymbolValue(Symbol.SLASH_SLASH.getSymbolValue());
-                    Symbol.SLASH_SLASH.setSymbolValue(Symbol.SLASH.getSymbolValue());
-                    if (values != null) {
-                        LispObject slash = NIL;
-                        for (int i = values.length; i-- > 0;)
-                            slash = new Cons(values[i], slash);
-                        Symbol.SLASH.setSymbolValue(slash);
-                        for (int i = 0; i < values.length; i++)
-                            out._writeLine(values[i].writeToString());
-                    } else {
-                        Symbol.SLASH.setSymbolValue(new Cons(result));
-                        out._writeLine(result.writeToString());
-                    }
-                    out._finishOutput();
-                }
-                catch (StackOverflowError e) {
-                    getStandardInput().clearInput();
-                    out._writeLine("Stack overflow");
-                }
-                catch (ControlTransfer c) {
-                    // We're on the toplevel, if this occurs,
-                    // we're toast...
-                    reportError(c, thread);
-                }
-                catch (Throwable t) {
-                    getStandardInput().clearInput();
-                    out.printStackTrace(t);
-                    thread.printBacktrace();
-                }
-            }
+        }
+        catch (ProcessingTerminated e) {
+            throw e;
+        }
+        catch (IntegrityError e) {
+            return;
         }
         catch (Throwable t) {
             t.printStackTrace();
+            return;
+        }
+        
+        // We only arrive here if something went wrong and we weren't able
+        // to load top-level.lisp and run the normal top-level loop.
+        Stream out = getStandardOutput();
+        while (true) {
+            try {
+                thread.resetStack();
+                thread.clearSpecialBindings();
+                out._writeString("* ");
+                out._finishOutput();
+                LispObject object =
+                    getStandardInput().read(false, EOF, false, thread,
+                                            Stream.currentReadtable);
+                if (object == EOF)
+                    break;
+                out.setCharPos(0);
+                Symbol.MINUS.setSymbolValue(object);
+                LispObject result = Lisp.eval(object, new Environment(), thread);
+                Debug.assertTrue(result != null);
+                Symbol.STAR_STAR_STAR.setSymbolValue(Symbol.STAR_STAR.getSymbolValue());
+                Symbol.STAR_STAR.setSymbolValue(Symbol.STAR.getSymbolValue());
+                Symbol.STAR.setSymbolValue(result);
+                Symbol.PLUS_PLUS_PLUS.setSymbolValue(Symbol.PLUS_PLUS.getSymbolValue());
+                Symbol.PLUS_PLUS.setSymbolValue(Symbol.PLUS.getSymbolValue());
+                Symbol.PLUS.setSymbolValue(Symbol.MINUS.getSymbolValue());
+                out = getStandardOutput();
+                out.freshLine();
+                LispObject[] values = thread.getValues();
+                Symbol.SLASH_SLASH_SLASH.setSymbolValue(Symbol.SLASH_SLASH.getSymbolValue());
+                Symbol.SLASH_SLASH.setSymbolValue(Symbol.SLASH.getSymbolValue());
+                if (values != null) {
+                    LispObject slash = NIL;
+                    for (int i = values.length; i-- > 0;)
+                        slash = new Cons(values[i], slash);
+                    Symbol.SLASH.setSymbolValue(slash);
+                    for (int i = 0; i < values.length; i++)
+                        out._writeLine(values[i].writeToString());
+                } else {
+                    Symbol.SLASH.setSymbolValue(new Cons(result));
+                    out._writeLine(result.writeToString());
+                }
+                out._finishOutput();
+            }
+            catch (StackOverflowError e) {
+                getStandardInput().clearInput();
+                out._writeLine("Stack overflow");
+            }
+            catch (ControlTransfer c) {
+                // We're on the toplevel, if this occurs,
+                // we're toast...
+                reportError(c, thread);
+            }
+            catch (ProcessingTerminated e) {
+                throw e;
+            }
+            catch (IntegrityError e) {
+                return;
+            }
+            catch (Throwable t) {
+                getStandardInput().clearInput();
+                out.printStackTrace(t);
+                thread.printBacktrace();
+            }
         }
     }
 

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Lisp.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Lisp.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Lisp.java	Fri Jan 21 17:12:08 2011
@@ -289,6 +289,14 @@
           {
             throw c;
           }
+        catch (ProcessingTerminated c)
+          {
+            throw c;
+          }
+        catch (IntegrityError c)
+          {
+            throw c;
+          }
         catch (Throwable t) // ControlTransfer handled above
           {
             Debug.trace(t);

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Main.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Main.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Main.java	Fri Jan 21 17:12:08 2011
@@ -30,26 +30,27 @@
  * obligated to do so.  If you do not wish to do so, delete this
  * exception statement from your version.
  */
-
 package org.armedbear.lisp;
 
-public final class Main
-{
-  public static final long startTimeMillis = System.currentTimeMillis();
+public final class Main {
+
+    public static final long startTimeMillis = System.currentTimeMillis();
+
+    public static void main(final String[] args) {
+        // Run the interpreter in a secondary thread so we can control the stack
+        // size.
+        Runnable r = new Runnable() {
 
-  public static void main(final String[] args)
-  {
-    // Run the interpreter in a secondary thread so we can control the stack
-    // size.
-    Runnable r = new Runnable()
-      {
-        public void run()
-        {
-          Interpreter interpreter = Interpreter.createDefaultInstance(args);
-          if (interpreter != null)
-          interpreter.run();
-        }
-      };
-    new Thread(null, r, "interpreter", 4194304L).start();
-  }
+            public void run() {
+               try {
+                    Interpreter interpreter = Interpreter.createDefaultInstance(args);
+                    if (interpreter != null)
+                            interpreter.run();
+                } catch (ProcessingTerminated e) {
+                    System.exit(e.getStatus());
+                }
+            }
+        };
+        new Thread(null, r, "interpreter", 4194304L).start();
+    }
 }

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/Primitives.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/Primitives.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/Primitives.java	Fri Jan 21 17:12:08 2011
@@ -1582,7 +1582,7 @@
 
         @Override
         public LispObject execute(LispObject[] args) {
-            Error e = new Error();
+            Error e = new IntegrityError();
 
             e.printStackTrace();
 
@@ -1595,9 +1595,7 @@
 for (LispObject a : args)
                     System.out.println(a.writeToString());
 
-            //###FIXME: Bail out, but do it nicer...
-            exit(1);
-            return NIL;
+            throw e;
         }
     };
 

Copied: branches/0.24.x/abcl/src/org/armedbear/lisp/ProcessingTerminated.java (from r13146, /trunk/abcl/src/org/armedbear/lisp/ProcessingTerminated.java)
==============================================================================
--- /trunk/abcl/src/org/armedbear/lisp/ProcessingTerminated.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/ProcessingTerminated.java	Fri Jan 21 17:12:08 2011
@@ -52,7 +52,7 @@
         this.status = status;
     }
 
-    int getStatus() {
+    public int getStatus() {
         return status;
     }
 }

Modified: branches/0.24.x/abcl/src/org/armedbear/lisp/java/swing/REPLConsole.java
==============================================================================
--- branches/0.24.x/abcl/src/org/armedbear/lisp/java/swing/REPLConsole.java	(original)
+++ branches/0.24.x/abcl/src/org/armedbear/lisp/java/swing/REPLConsole.java	Fri Jan 21 17:12:08 2011
@@ -302,7 +302,7 @@
       repl = Interpreter.createInstance().eval("#'top-level::top-level-loop");
     } catch (Throwable e) {
       e.printStackTrace();
-      exit(1);
+      System.exit(1);  // Ok. We haven't done anything useful yet.
     }
     final REPLConsole d = new REPLConsole(repl);
     final JTextComponent txt = new JTextArea(d);




More information about the armedbear-cvs mailing list