diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-09-19 00:35:50 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-09-19 00:35:50 +0000 |
commit | 0f5bd2ae6cb5471fa8c174f28d707c191a98d8c1 (patch) | |
tree | 47135f15131733c07e7e2a07285c81d208e97577 | |
parent | 9bc5b30329913113c8a8310260b2c8d17cb0e0e3 (diff) |
added *1/2/3 *e and tweaked error messages
-rw-r--r-- | src/clj/clojure/boot.clj | 16 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 33 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Repl.java | 18 |
3 files changed, 46 insertions, 21 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index b43668cd..283f0b04 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -3320,3 +3320,19 @@ (when (every? seq cs) (lazy-cons (map first cs) (step (map rest cs)))))] (pmap #(apply f %) (step (cons coll colls)))))) + +(def + #^{:doc "bound in a repl thread to the most recent value printed"} + *1) + +(def + #^{:doc "bound in a repl thread to the second most recent value printed"} + *2) + +(def + #^{:doc "bound in a repl thread to the third most recent value printed"} + *3) + +(def + #^{:doc "bound in a repl thread to the most recent exception caught by the repl"} + *e) diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index 199767af..4b3cb544 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -296,8 +296,7 @@ static class DefExpr implements Expr{ catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(errorMsg(source, line, e.getMessage()), - e); + throw new CompilerException(source, line, e); else throw (CompilerException) e; } @@ -355,7 +354,7 @@ static class DefExpr implements Expr{ IPersistentMap mm = sym.meta(); mm = (IPersistentMap) RT.assoc(mm, RT.LINE_KEY, LINE.get()).assoc(RT.FILE_KEY, SOURCE.get()); Expr meta = analyze(context == C.EVAL ? context : C.EXPRESSION, mm); - return new DefExpr((String) SOURCE_PATH.get(),(Integer) LINE.get(), + return new DefExpr((String) SOURCE.get(),(Integer) LINE.get(), v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name), meta, RT.count(form) == 3); } @@ -717,7 +716,7 @@ static public abstract class HostExpr implements Expr, MaybePrimitiveExpr{ //determine static or instance //static target must be symbol, either fully.qualified.Classname or Classname that has been imported int line = (Integer) LINE.get(); - String source = (String) SOURCE_PATH.get(); + String source = (String) SOURCE.get(); Class c = maybeClass(RT.second(form), false); //at this point c will be non-null if static Expr instance = null; @@ -1126,8 +1125,7 @@ static class InstanceMethodExpr extends MethodExpr{ catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(errorMsg(source, line, e.getMessage()), - e); + throw new CompilerException(source, line, e); else throw (CompilerException) e; } @@ -1261,8 +1259,7 @@ static class StaticMethodExpr extends MethodExpr{ catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(errorMsg(source, line, e.getMessage()), - e); + throw new CompilerException(source, line, e); else throw (CompilerException) e; } @@ -2639,8 +2636,7 @@ static class InvokeExpr implements Expr{ catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(errorMsg(source,line,e.getMessage()), - e); + throw new CompilerException(source, line, e); else throw (CompilerException) e; } @@ -2698,7 +2694,7 @@ static class InvokeExpr implements Expr{ // throw new IllegalArgumentException( // String.format("No more than %d args supported", MAX_POSITIONAL_ARITY)); - return new InvokeExpr((String) SOURCE_PATH.get(),(Integer) LINE.get(), tagOf(form), fexpr, args); + return new InvokeExpr((String) SOURCE.get(),(Integer) LINE.get(), tagOf(form), fexpr, args); } } @@ -3767,8 +3763,7 @@ private static Expr analyze(C context, Object form, String name) throws Exceptio catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(String.format("%s:%d: %s", SOURCE.get(), (Integer) LINE.get(), e.getMessage()), - e); + throw new CompilerException((String) SOURCE.get(), (Integer) LINE.get(), e); else throw (CompilerException) e; } @@ -3776,8 +3771,11 @@ private static Expr analyze(C context, Object form, String name) throws Exceptio static public class CompilerException extends Exception{ - public CompilerException(String message, Throwable cause){ - super(message, cause); + public CompilerException(String source, int line, Throwable cause){ + super(errorMsg(source,line,cause.toString()), cause); + } + public String toString(){ + return getMessage(); } } @@ -3923,7 +3921,7 @@ private static Expr analyzeSeq(C context, ISeq form, String name) throws Excepti } static String errorMsg(String source, int line, String s){ - return String.format("%s:%d: %s", source,line, s); + return String.format("%s (%s:%d)", s, source, line); } public static Object eval(Object form) throws Exception{ @@ -3952,8 +3950,7 @@ public static Object eval(Object form) throws Exception{ catch(Throwable e) { if(!(e instanceof CompilerException)) - throw new CompilerException(errorMsg((String)SOURCE.get(), (Integer) LINE.get(),e.getMessage()), - e); + throw new CompilerException((String)SOURCE.get(), (Integer) LINE.get(),e); else throw (CompilerException) e; } diff --git a/src/jvm/clojure/lang/Repl.java b/src/jvm/clojure/lang/Repl.java index c91ed4b3..5ad59bbc 100644 --- a/src/jvm/clojure/lang/Repl.java +++ b/src/jvm/clojure/lang/Repl.java @@ -23,6 +23,10 @@ static final Var in_ns = RT.var("clojure", "in-ns"); static final Var refer = RT.var("clojure", "refer"); static final Var ns = RT.var("clojure", "*ns*"); static final Var warn_on_reflection = RT.var("clojure", "*warn-on-reflection*"); +static final Var star1 = RT.var("clojure", "*1"); +static final Var star2 = RT.var("clojure", "*2"); +static final Var star3 = RT.var("clojure", "*3"); +static final Var stare = RT.var("clojure", "*e"); public static void main(String[] args) throws Exception{ @@ -32,10 +36,15 @@ public static void main(String[] args) throws Exception{ { //*ns* must be thread-bound for in-ns to work //thread-bind *warn-on-reflection* so it can be set! + //thread-bind *1,*2,*3,*e so each repl has its own history //must have corresponding popThreadBindings in finally clause Var.pushThreadBindings( RT.map(ns, ns.get(), - warn_on_reflection, warn_on_reflection.get())); + warn_on_reflection, warn_on_reflection.get(), + star1, null, + star2, null, + star3, null, + stare, null)); //create and move into the user namespace in_ns.invoke(USER); @@ -76,14 +85,17 @@ public static void main(String[] args) throws Exception{ RT.print(ret, w); w.write('\n'); //w.flush(); + star3.set(star2.get()); + star2.set(star1.get()); + star1.set(ret); } catch(Throwable e) { Throwable c = e; while(c.getCause() != null) c = c.getCause(); - System.err.println(c); - e.printStackTrace(); + System.err.println(e instanceof Compiler.CompilerException ? e : c); + stare.set(e); } } } |