changeset 132:14281d5bd36f

minor git-svn-id: https://luan-java.googlecode.com/svn/trunk@133 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 10 Jun 2014 09:17:25 +0000
parents 15a8e6588f3c
children 98aba462c422
files src/luan/LuanBit.java src/luan/LuanException.java src/luan/interp/Closure.java src/luan/interp/ConstExpr.java src/luan/interp/ExpList.java src/luan/interp/FnCall.java src/luan/interp/LuanStateImpl.java
diffstat 7 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/LuanBit.java
--- a/src/luan/LuanBit.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/LuanBit.java	Tue Jun 10 09:17:25 2014 +0000
@@ -16,6 +16,21 @@
 		return new LuanException(this,msg);
 	}
 
+	public String stackTrace() {
+		StringBuilder buf = new StringBuilder();
+		LuanElement el = this.el;
+		for( int i  = luan.stackTrace.size() - 1; i>=0; i-- ) {
+			StackTraceElement stackTraceElement = luan.stackTrace.get(i);
+			buf.append( "\n\t" ).append( el.toString(stackTraceElement.fnName) );
+			el = stackTraceElement.call;
+		}
+		return buf.toString();
+	}
+
+	public void dumpStack() {
+		System.err.println( stackTrace() );
+	}
+
 	public Object call(LuanFunction fn,String fnName,Object[] args) throws LuanException {
 		List<StackTraceElement> stackTrace = luan.stackTrace;
 		stackTrace.add( new StackTraceElement(el,fnName) );
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/LuanException.java
--- a/src/luan/LuanException.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/LuanException.java	Tue Jun 10 09:17:25 2014 +0000
@@ -6,7 +6,7 @@
 
 	LuanException(LuanBit bit,Object msg) {
 		super(message(msg),cause(msg));
-		stackTrace = stackTrace(bit.luan,bit.el,msg);
+		stackTrace = stackTrace(bit,msg);
 	}
 
 	@Override public String getMessage() {
@@ -35,13 +35,9 @@
 		}
 	}
 
-	private static String stackTrace(LuanState luan,LuanElement el,Object msg) {
+	private static String stackTrace(LuanBit bit,Object msg) {
 		StringBuilder buf = new StringBuilder();
-		for( int i  = luan.stackTrace.size() - 1; i>=0; i-- ) {
-			StackTraceElement stackTraceElement = luan.stackTrace.get(i);
-			buf.append( "\n\t" ).append( el.toString(stackTraceElement.fnName) );
-			el = stackTraceElement.call;
-		}
+		buf.append( bit.stackTrace() );
 		if( msg instanceof LuanException ) {
 			LuanException le = (LuanException)msg;
 			buf.append( "\ncaused by:" ).append( le.stackTrace );
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/interp/Closure.java
--- a/src/luan/interp/Closure.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/interp/Closure.java	Tue Jun 10 09:17:25 2014 +0000
@@ -62,7 +62,6 @@
 				stack[i] = args[i];
 			}
 			Object returnValues;
-			Closure tailFn;
 			try {
 				fnDef.block.eval(luan);
 			} catch(ReturnException e) {
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/interp/ConstExpr.java
--- a/src/luan/interp/ConstExpr.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/interp/ConstExpr.java	Tue Jun 10 09:17:25 2014 +0000
@@ -18,4 +18,8 @@
 	@Override public Object eval(LuanStateImpl luan) {
 		return obj;
 	}
+
+	@Override public String toString() {
+		return "(ConstExpr "+obj+")";
+	}
 }
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/interp/ExpList.java
--- a/src/luan/interp/ExpList.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/interp/ExpList.java	Tue Jun 10 09:17:25 2014 +0000
@@ -121,12 +121,17 @@
 		}
 
 		@Override public Object eval(LuanStateImpl luan) throws LuanException {
+//System.out.println("SingleExpList "+expr);
 			return expr.eval(luan);
 		}
 
 		@Override public LuanSource.Element se() {
 			return expr.se();
 		}
+
+		@Override public String toString() {
+			return "(SingleExpList "+expr+")";
+		}
 	}
 
 	private final Adder[] adders;
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/interp/FnCall.java
--- a/src/luan/interp/FnCall.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/interp/FnCall.java	Tue Jun 10 09:17:25 2014 +0000
@@ -32,4 +32,8 @@
 			return call(luan,h);
 		throw luan.bit(fnExpr.se()).exception( "attempt to call '"+fnExpr.se().text()+"' (a " + Luan.type(o) + " value)" );
 	}
+
+	@Override public String toString() {
+		return "(FnCall "+fnName+" "+fnExpr+" "+args+")";
+	}
 }
diff -r 15a8e6588f3c -r 14281d5bd36f src/luan/interp/LuanStateImpl.java
--- a/src/luan/interp/LuanStateImpl.java	Tue Jun 10 04:15:19 2014 +0000
+++ b/src/luan/interp/LuanStateImpl.java	Tue Jun 10 09:17:25 2014 +0000
@@ -83,6 +83,7 @@
 	// returns stack
 	Object[] newFrame(Closure closure, int stackSize, Object[] varArgs) {
 		returnValues = LuanFunction.NOTHING;
+		tailFn = null;
 		frame = new Frame(frame,closure,stackSize,varArgs);
 		return frame.stack;
 	}