Mercurial Hosting > luan
changeset 460:b48cfa14ba60
improve stack trace
line wrap: on
line diff
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/LuanBit.java --- a/core/src/luan/LuanBit.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/LuanBit.java Wed May 06 14:32:29 2015 -0600 @@ -19,10 +19,12 @@ public String stackTrace() { StringBuilder buf = new StringBuilder(); LuanElement el = this.el; + if( el != null ) + buf.append( "\n\t" ).append( el.toString(null) ); for( int i = luan.stackTrace.size() - 1; i>=0; i-- ) { StackTraceElement stackTraceElement = luan.stackTrace.get(i); + el = stackTraceElement.call; buf.append( "\n\t" ).append( el.toString(stackTraceElement.fnName) ); - el = stackTraceElement.call; } return buf.toString(); } @@ -32,6 +34,8 @@ } public Object call(LuanFunction fn,String fnName,Object[] args) throws LuanException { + if( el == null ) + return fn.call(luan,args); List<StackTraceElement> stackTrace = luan.stackTrace; stackTrace.add( new StackTraceElement(el,fnName) ); try { @@ -46,9 +50,8 @@ public String checkString(Object obj) throws LuanException { if( obj instanceof String ) return (String)obj; - if( el instanceof LuanSource.Element ) { - LuanSource.Element se = (LuanSource.Element)el; - throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a string" ); + if( el != null ) { + throw exception( "attempt to use '"+el.text()+"' (a " + Luan.type(obj) + " value) as a string" ); } else { throw exception( "attempt to use a " + Luan.type(obj) + " as a string" ); } @@ -57,9 +60,8 @@ public Number checkNumber(Object obj) throws LuanException { if( obj instanceof Number ) return (Number)obj; - if( el instanceof LuanSource.Element ) { - LuanSource.Element se = (LuanSource.Element)el; - throw exception( "attempt to perform arithmetic on '"+se.text()+"' (a " + Luan.type(obj) + " value)" ); + if( el != null ) { + throw exception( "attempt to perform arithmetic on '"+el.text()+"' (a " + Luan.type(obj) + " value)" ); } else { throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" ); } @@ -68,9 +70,8 @@ public LuanFunction checkFunction(Object obj) throws LuanException { if( obj instanceof LuanFunction ) return (LuanFunction)obj; - if( el instanceof LuanSource.Element ) { - LuanSource.Element se = (LuanSource.Element)el; - throw exception( "attempt to call '"+se.text()+"' (a " + Luan.type(obj) + " value)" ); + if( el != null ) { + throw exception( "attempt to call '"+el.text()+"' (a " + Luan.type(obj) + " value)" ); } else { throw exception( "attempt to call a " + Luan.type(obj) + " value" ); } @@ -79,9 +80,8 @@ public Boolean checkBoolean(Object obj) throws LuanException { if( obj instanceof Boolean ) return (Boolean)obj; - if( el instanceof LuanSource.Element ) { - LuanSource.Element se = (LuanSource.Element)el; - throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a boolean" ); + if( el != null ) { + throw exception( "attempt to use '"+el.text()+"' (a " + Luan.type(obj) + " value) as a boolean" ); } else { throw exception( "attempt to use a " + Luan.type(obj) + " as a boolean" ); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/LuanElement.java --- a/core/src/luan/LuanElement.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/LuanElement.java Wed May 06 14:32:29 2015 -0600 @@ -1,20 +1,51 @@ package luan; -public abstract class LuanElement { +public final class LuanElement { + public final LuanSource source; + public final int start; + public final int end; + private final String text; + + public LuanElement(LuanSource source,int start,int end) { + this(source,start,end,null); + } - final String toString(String fnName) { + public LuanElement(LuanSource source,int start,int end,String text) { + if( source==null ) + throw new NullPointerException("source is null"); + this.source = source; + this.start = start; + while( end > 0 && Character.isWhitespace(source.text.charAt(end-1)) ) { + end--; + } + this.end = end; + this.text = text; + } + + public String text() { + return text!=null ? text : source.text.substring(start,end); + } + + private String location() { + return source.name + " line " + lineNumber(); + } + + private int lineNumber() { + int line = 0; + int i = -1; + do { + line++; + i = source.text.indexOf('\n',i+1); + } while( i != -1 && i < start ); + return line; + } + + String toString(String fnName) { String s = location(); if( fnName != null ) - s += ": in function '" + fnName + "'"; + s += " in call to '" + fnName + "'"; return s; } - abstract String location(); - - public static final LuanElement JAVA = new LuanElement(){ - @Override String location() { - return "Java"; - } - }; }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/LuanSource.java --- a/core/src/luan/LuanSource.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/LuanSource.java Wed May 06 14:32:29 2015 -0600 @@ -9,60 +9,4 @@ this.name = name; this.text = text; } - - public static final class CompilerElement extends LuanElement { - public final LuanSource source; - - public CompilerElement(LuanSource source) { - if( source==null ) - throw new NullPointerException("source is null"); - this.source = source; - } - - @Override String location() { - return "Compiling " + source.name; - } - } - - public static final class Element extends LuanElement { - public final LuanSource source; - public final int start; - public final int end; - private final String text; - - public Element(LuanSource source,int start,int end) { - this(source,start,end,null); - } - - public Element(LuanSource source,int start,int end,String text) { - if( source==null ) - throw new NullPointerException("source is null"); - this.source = source; - this.start = start; - while( end > 0 && Character.isWhitespace(source.text.charAt(end-1)) ) { - end--; - } - this.end = end; - this.text = text; - } - - public String text() { - return text!=null ? text : source.text.substring(start,end); - } - - @Override String location() { - return source.name + ':' + lineNumber(); - } - - private int lineNumber() { - int line = 0; - int i = -1; - do { - line++; - i = source.text.indexOf('\n',i+1); - } while( i != -1 && i < start ); - return line; - } - - } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/LuanState.java --- a/core/src/luan/LuanState.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/LuanState.java Wed May 06 14:32:29 2015 -0600 @@ -50,7 +50,7 @@ // convenience methods - private final LuanBit JAVA = bit(LuanElement.JAVA); + private final LuanBit JAVA = bit(null); public LuanException exception(Object msg) { return JAVA.exception(msg);
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/AddExpr.java --- a/core/src/luan/impl/AddExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/AddExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class AddExpr extends BinaryOpExpr { - AddExpr(LuanSource.Element se,Expr op1,Expr op2) { + AddExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/AndExpr.java --- a/core/src/luan/impl/AndExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/AndExpr.java Wed May 06 14:32:29 2015 -0600 @@ -2,12 +2,12 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class AndExpr extends BinaryOpExpr { - AndExpr(LuanSource.Element se,Expr op1,Expr op2) { + AndExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/BinaryOpExpr.java --- a/core/src/luan/impl/BinaryOpExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/BinaryOpExpr.java Wed May 06 14:32:29 2015 -0600 @@ -4,21 +4,21 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; abstract class BinaryOpExpr extends CodeImpl implements Expr { final Expr op1; final Expr op2; - BinaryOpExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se); + BinaryOpExpr(LuanElement el,Expr op1,Expr op2) { + super(el); this.op1 = op1; this.op2 = op2; } Object arithmetic(LuanStateImpl luan,String op,Object o1,Object o2) throws LuanException { - return luan.bit(se()).arithmetic(op,o1,o2); + return luan.bit(el()).arithmetic(op,o1,o2); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/Code.java --- a/core/src/luan/impl/Code.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/Code.java Wed May 06 14:32:29 2015 -0600 @@ -1,8 +1,8 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; interface Code { - public LuanSource.Element se(); + public LuanElement el(); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/CodeImpl.java --- a/core/src/luan/impl/CodeImpl.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/CodeImpl.java Wed May 06 14:32:29 2015 -0600 @@ -1,16 +1,16 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; class CodeImpl implements Code { - final LuanSource.Element se; + final LuanElement el; - CodeImpl(LuanSource.Element se) { - this.se = se; + CodeImpl(LuanElement el) { + this.el = el; } - @Override public final LuanSource.Element se() { - return se; + @Override public final LuanElement el() { + return el; } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ConcatExpr.java --- a/core/src/luan/impl/ConcatExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ConcatExpr.java Wed May 06 14:32:29 2015 -0600 @@ -3,25 +3,25 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; final class ConcatExpr extends BinaryOpExpr { - ConcatExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se,op1,op2); + ConcatExpr(LuanElement el,Expr op1,Expr op2) { + super(el,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o1 = op1.eval(luan); Object o2 = op2.eval(luan); - LuanBit bit = luan.bit(se); + LuanBit bit = luan.bit(el); LuanFunction fn = bit.getBinHandler("__concat",o1,o2); if( fn != null ) return Luan.first(bit.call(fn,"__concat",new Object[]{o1,o2})); - String s1 = luan.bit(op1.se()).toString(o1); - String s2 = luan.bit(op2.se()).toString(o2); + String s1 = luan.bit(op1.el()).toString(o1); + String s2 = luan.bit(op2.el()).toString(o2); return s1 + s2; } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ConstExpr.java --- a/core/src/luan/impl/ConstExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ConstExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; final class ConstExpr extends CodeImpl implements Expr { private final Object obj; - ConstExpr(LuanSource.Element se,Object obj) { + ConstExpr(LuanElement se,Object obj) { super(se); this.obj = obj; }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/DivExpr.java --- a/core/src/luan/impl/DivExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/DivExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class DivExpr extends BinaryOpExpr { - DivExpr(LuanSource.Element se,Expr op1,Expr op2) { + DivExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/EqExpr.java --- a/core/src/luan/impl/EqExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/EqExpr.java Wed May 06 14:32:29 2015 -0600 @@ -5,14 +5,14 @@ import luan.LuanFunction; import luan.LuanTable; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; final class EqExpr extends BinaryOpExpr { - EqExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se,op1,op2); + EqExpr(LuanElement el,Expr op1,Expr op2) { + super(el,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -45,7 +45,7 @@ Object f = mt1.rawGet("__eq"); if( f == null || !f.equals(mt2.rawGet("__eq")) ) return false; - LuanBit bit = luan.bit(se); + LuanBit bit = luan.bit(el); LuanFunction fn = bit.checkFunction(f); return bit.checkBoolean( Luan.first(bit.call(fn,"__eq",new Object[]{o1,o2})) ); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ExpList.java --- a/core/src/luan/impl/ExpList.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ExpList.java Wed May 06 14:32:29 2015 -0600 @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanFunction; import luan.Luan; @@ -17,7 +17,7 @@ return LuanFunction.NOTHING; } - @Override public LuanSource.Element se() { + @Override public LuanElement el() { return null; } }; @@ -66,8 +66,8 @@ return a; } - @Override public LuanSource.Element se() { - return new LuanSource.Element(exprs[0].se().source,exprs[0].se().start,exprs[exprs.length-1].se().end); + @Override public LuanElement el() { + return new LuanElement(exprs[0].el().source,exprs[0].el().start,exprs[exprs.length-1].el().end); } } @@ -89,8 +89,8 @@ return list.toArray(); } - @Override public LuanSource.Element se() { - return new LuanSource.Element(exprs[0].se().source,exprs[0].se().start,last.se().end); + @Override public LuanElement el() { + return new LuanElement(exprs[0].el().source,exprs[0].el().start,last.el().end); } } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ExpressionsExpr.java --- a/core/src/luan/impl/ExpressionsExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ExpressionsExpr.java Wed May 06 14:32:29 2015 -0600 @@ -3,7 +3,7 @@ import java.util.List; import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class ExpressionsExpr implements Expr { @@ -19,8 +19,8 @@ return Luan.first( expressions.eval(luan) ); } - public LuanSource.Element se() { - return expressions.se(); + public LuanElement el() { + return expressions.el(); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/FnCall.java --- a/core/src/luan/impl/FnCall.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/FnCall.java Wed May 06 14:32:29 2015 -0600 @@ -3,7 +3,7 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanTable; @@ -12,11 +12,11 @@ final Expressions args; final String fnName; - FnCall(LuanSource.Element se,Expr fnExpr,Expressions args) { - super(se); + FnCall(LuanElement el,Expr fnExpr,Expressions args) { + super(el); this.fnExpr = fnExpr; this.args = args; - this.fnName = fnExpr.se().text(); + this.fnName = fnExpr.el().text(); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -26,7 +26,7 @@ private Object call(LuanStateImpl luan,Object o) throws LuanException { if( o instanceof LuanFunction ) { LuanFunction fn = (LuanFunction)o; - return luan.bit(se).call( fn, fnName, Luan.array(args.eval(luan)) ); + return luan.bit(el).call( fn, fnName, Luan.array(args.eval(luan)) ); } if( o instanceof LuanTable ) { LuanTable t = (LuanTable)o; @@ -34,7 +34,7 @@ if( h != null ) return call(luan,h); } - throw luan.bit(fnExpr.se()).exception( "attempt to call '"+fnExpr.se().text()+"' (a " + Luan.type(o) + " value)" ); + throw luan.bit(fnExpr.el()).exception( "attempt to call '"+fnExpr.el().text()+"' (a " + Luan.type(o) + " value)" ); } @Override public String toString() {
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/FnDef.java --- a/core/src/luan/impl/FnDef.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/FnDef.java Wed May 06 14:32:29 2015 -0600 @@ -1,7 +1,7 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class FnDef extends CodeImpl implements Expr { @@ -11,7 +11,7 @@ final boolean isVarArg; final UpValue.Getter[] upValueGetters; - FnDef(LuanSource.Element se,Stmt block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) { + FnDef(LuanElement se,Stmt block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) { super(se); this.block = block; this.stackSize = stackSize;
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ForStmt.java --- a/core/src/luan/impl/ForStmt.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ForStmt.java Wed May 06 14:32:29 2015 -0600 @@ -3,7 +3,7 @@ import luan.Luan; import luan.LuanException; import luan.LuanFunction; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; @@ -13,8 +13,8 @@ private final Expr iterExpr; private final Stmt block; - ForStmt(LuanSource.Element se,int iVars,int nVars,Expr iterExpr,Stmt block) { - super(se); + ForStmt(LuanElement el,int iVars,int nVars,Expr iterExpr,Stmt block) { + super(el); this.iVars = iVars; this.nVars = nVars; this.iterExpr = iterExpr; @@ -22,9 +22,9 @@ } @Override public void eval(LuanStateImpl luan) throws LuanException { - LuanBit bit = luan.bit(iterExpr.se()); + LuanBit bit = luan.bit(iterExpr.el()); LuanFunction iter = bit.checkFunction( iterExpr.eval(luan) ); - String name = iterExpr.se().text(); + String name = iterExpr.el().text(); try { while(true) { Object vals = bit.call(iter,name,LuanFunction.NOTHING);
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/GetLocalVar.java --- a/core/src/luan/impl/GetLocalVar.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/GetLocalVar.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; final class GetLocalVar extends CodeImpl implements Expr { private final int index; - GetLocalVar(LuanSource.Element se,int index) { + GetLocalVar(LuanElement se,int index) { super(se); this.index = index; }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/GetUpVar.java --- a/core/src/luan/impl/GetUpVar.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/GetUpVar.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; final class GetUpVar extends CodeImpl implements Expr { private final int index; - GetUpVar(LuanSource.Element se,int index) { + GetUpVar(LuanElement se,int index) { super(se); this.index = index; }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/IfStmt.java --- a/core/src/luan/impl/IfStmt.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/IfStmt.java Wed May 06 14:32:29 2015 -0600 @@ -2,7 +2,7 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class IfStmt extends CodeImpl implements Stmt { @@ -10,15 +10,15 @@ final Stmt thenStmt; final Stmt elseStmt; - IfStmt(LuanSource.Element se,Expr cnd,Stmt thenStmt,Stmt elseStmt) { - super(se); + IfStmt(LuanElement el,Expr cnd,Stmt thenStmt,Stmt elseStmt) { + super(el); this.cnd = cnd; this.thenStmt = thenStmt; this.elseStmt = elseStmt; } @Override public void eval(LuanStateImpl luan) throws LuanException { - if( luan.bit(cnd.se()).checkBoolean( cnd.eval(luan) ) ) { + if( luan.bit(cnd.el()).checkBoolean( cnd.eval(luan) ) ) { thenStmt.eval(luan); } else { elseStmt.eval(luan);
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/IndexExpr.java --- a/core/src/luan/impl/IndexExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/IndexExpr.java Wed May 06 14:32:29 2015 -0600 @@ -4,7 +4,7 @@ import luan.LuanException; import luan.LuanTable; import luan.LuanFunction; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanMeta; import luan.modules.StringLuan; import luan.modules.BinaryLuan; @@ -13,8 +13,8 @@ final class IndexExpr extends BinaryOpExpr { - IndexExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se,op1,op2); + IndexExpr(LuanElement el,Expr op1,Expr op2) { + super(el,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -33,6 +33,6 @@ if( obj != null && luan.currentEnvironment().hasJava() ) return JavaLuan.__index(luan,obj,key); else - throw luan.bit(op1.se()).exception( "attempt to index '"+op1.se().text()+"' (a " + Luan.type(obj) + " value)" ); + throw luan.bit(op1.el()).exception( "attempt to index '"+op1.el().text()+"' (a " + Luan.type(obj) + " value)" ); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LeExpr.java --- a/core/src/luan/impl/LeExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LeExpr.java Wed May 06 14:32:29 2015 -0600 @@ -3,14 +3,14 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; final class LeExpr extends BinaryOpExpr { - LeExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se,op1,op2); + LeExpr(LuanElement el,Expr op1,Expr op2) { + super(el,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -30,7 +30,7 @@ String s2 = (String)o2; return s1.compareTo(s2) <= 0; } - LuanBit bit = luan.bit(se); + LuanBit bit = luan.bit(el); LuanFunction fn = bit.getBinHandler("__le",o1,o2); if( fn != null ) return bit.checkBoolean( Luan.first(bit.call(fn,"__le",new Object[]{o1,o2})) );
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LenExpr.java --- a/core/src/luan/impl/LenExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LenExpr.java Wed May 06 14:32:29 2015 -0600 @@ -4,14 +4,14 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; final class LenExpr extends UnaryOpExpr { - LenExpr(LuanSource.Element se,Expr op) { - super(se,op); + LenExpr(LuanElement el,Expr op) { + super(el,op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -24,7 +24,7 @@ byte[] a = (byte[])o; return a.length; } - LuanBit bit = luan.bit(se); + LuanBit bit = luan.bit(el); if( !(o instanceof LuanTable) ) throw bit.exception( "attempt to get length of a " + Luan.type(o) + " value" ); LuanTable t = (LuanTable)o;
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LtExpr.java --- a/core/src/luan/impl/LtExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LtExpr.java Wed May 06 14:32:29 2015 -0600 @@ -3,18 +3,18 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class LtExpr extends BinaryOpExpr { - LtExpr(LuanSource.Element se,Expr op1,Expr op2) { - super(se,op1,op2); + LtExpr(LuanElement el,Expr op1,Expr op2) { + super(el,op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o1 = op1.eval(luan); Object o2 = op2.eval(luan); - return luan.bit(se).isLessThan(o1,o2); + return luan.bit(el).isLessThan(o1,o2); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LuanCompiler.java --- a/core/src/luan/impl/LuanCompiler.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LuanCompiler.java Wed May 06 14:32:29 2015 -0600 @@ -36,8 +36,7 @@ return parser.RequiredModule(); } catch(ParseException e) { //e.printStackTrace(); - LuanElement le = new LuanSource.CompilerElement(parser.source); - throw luan.bit(le).exception( e.getFancyMessage() ); + throw luan.exception( e.getFancyMessage() ); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LuanParser.java --- a/core/src/luan/impl/LuanParser.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LuanParser.java Wed May 06 14:32:29 2015 -0600 @@ -9,6 +9,7 @@ import luan.Luan; import luan.LuanState; import luan.LuanSource; +import luan.LuanElement; import luan.modules.PackageLuan; @@ -110,12 +111,12 @@ frame.addUpValueGetter(name,new UpValue.ValueGetter(value)); } - private LuanSource.Element se(int start) { + private LuanElement se(int start) { return se(start,null); } - private LuanSource.Element se(int start,String text) { - return new LuanSource.Element(source,start,parser.currentIndex(),text); + private LuanElement se(int start,String text) { + return new LuanElement(source,start,parser.currentIndex(),text); } private List<String> symbols() { @@ -268,7 +269,7 @@ Expressions exprs = TemplateExpressions(In.NOTHING); if( exprs == null ) return null; - LuanSource.Element se = se(start,"require 'luan:Io'"); + LuanElement se = se(start,"require 'luan:Io'"); FnCall requireCall = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(se,"luan:Io") ); se = se(start,"stdout"); Expr stdoutExp = new IndexExpr( se, expr(requireCall), new ConstExpr(se,"stdout") ); @@ -878,7 +879,7 @@ return nameVar(se(start,name),name); } - private Var nameVar(final LuanSource.Element se,final String name) { + private Var nameVar(final LuanElement se,final String name) { return new Var() { public Expr expr() {
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/LuanStateImpl.java --- a/core/src/luan/impl/LuanStateImpl.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/LuanStateImpl.java Wed May 06 14:32:29 2015 -0600 @@ -117,7 +117,7 @@ @Override public LuanSource currentSource(){ if( frame==null ) return null; - return frame.closure.fnDef.se().source; + return frame.closure.fnDef.el().source; } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ModExpr.java --- a/core/src/luan/impl/ModExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ModExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class ModExpr extends BinaryOpExpr { - ModExpr(LuanSource.Element se,Expr op1,Expr op2) { + ModExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/MulExpr.java --- a/core/src/luan/impl/MulExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/MulExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class MulExpr extends BinaryOpExpr { - MulExpr(LuanSource.Element se,Expr op1,Expr op2) { + MulExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/NotExpr.java --- a/core/src/luan/impl/NotExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/NotExpr.java Wed May 06 14:32:29 2015 -0600 @@ -2,17 +2,17 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class NotExpr extends UnaryOpExpr { - NotExpr(LuanSource.Element se,Expr op) { - super(se,op); + NotExpr(LuanElement el,Expr op) { + super(el,op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { - return !luan.bit(op.se()).checkBoolean( op.eval(luan) ); + return !luan.bit(op.el()).checkBoolean( op.eval(luan) ); } @Override public String toString() {
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/OrExpr.java --- a/core/src/luan/impl/OrExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/OrExpr.java Wed May 06 14:32:29 2015 -0600 @@ -2,12 +2,12 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class OrExpr extends BinaryOpExpr { - OrExpr(LuanSource.Element se,Expr op1,Expr op2) { + OrExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/PowExpr.java --- a/core/src/luan/impl/PowExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/PowExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class PowExpr extends BinaryOpExpr { - PowExpr(LuanSource.Element se,Expr op1,Expr op2) { + PowExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/RepeatStmt.java --- a/core/src/luan/impl/RepeatStmt.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/RepeatStmt.java Wed May 06 14:32:29 2015 -0600 @@ -2,15 +2,15 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class RepeatStmt extends CodeImpl implements Stmt { private final Stmt doStmt; private final Expr cnd; - RepeatStmt(LuanSource.Element se,Stmt doStmt,Expr cnd) { - super(se); + RepeatStmt(LuanElement el,Stmt doStmt,Expr cnd) { + super(el); this.doStmt = doStmt; this.cnd = cnd; } @@ -19,7 +19,7 @@ try { do { doStmt.eval(luan); - } while( !luan.bit(se).checkBoolean( cnd.eval(luan) ) ); + } while( !luan.bit(el).checkBoolean( cnd.eval(luan) ) ); } catch(BreakException e) {} } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/ReturnStmt.java --- a/core/src/luan/impl/ReturnStmt.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/ReturnStmt.java Wed May 06 14:32:29 2015 -0600 @@ -3,7 +3,7 @@ import luan.Luan; import luan.LuanException; import luan.LuanFunction; -import luan.LuanSource; +import luan.LuanElement; final class ReturnStmt extends CodeImpl implements Stmt { @@ -11,8 +11,8 @@ private final Expr tailFnExpr; boolean throwReturnException = true; - ReturnStmt(LuanSource.Element se,Expressions expressions) { - super(se); + ReturnStmt(LuanElement el,Expressions expressions) { + super(el); if( expressions instanceof FnCall ) { // tail call FnCall fnCall = (FnCall)expressions; this.expressions = fnCall.args; @@ -26,12 +26,12 @@ @Override public void eval(LuanStateImpl luan) throws LuanException { luan.returnValues = expressions.eval(luan); if( tailFnExpr != null ) { - LuanSource.Element seTail = tailFnExpr.se(); - LuanFunction tailFn = luan.bit(seTail).checkFunction( tailFnExpr.eval(luan) ); + LuanElement elTail = tailFnExpr.el(); + LuanFunction tailFn = luan.bit(elTail).checkFunction( tailFnExpr.eval(luan) ); if( tailFn instanceof Closure ) { luan.tailFn = (Closure)tailFn; } else { - luan.returnValues = luan.bit(seTail).call(tailFn,seTail.text(),Luan.array(luan.returnValues)); + luan.returnValues = luan.bit(elTail).call(tailFn,elTail.text(),Luan.array(luan.returnValues)); } } if( throwReturnException )
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/SetTableEntry.java --- a/core/src/luan/impl/SetTableEntry.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/SetTableEntry.java Wed May 06 14:32:29 2015 -0600 @@ -4,7 +4,7 @@ import luan.LuanTable; import luan.Luan; import luan.LuanFunction; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanMeta; import luan.modules.JavaLuan; @@ -13,8 +13,8 @@ private final Expr tableExpr; private final Expr keyExpr; - SetTableEntry(LuanSource.Element se,Expr tableExpr,Expr keyExpr) { - super(se); + SetTableEntry(LuanElement el,Expr tableExpr,Expr keyExpr) { + super(el); this.tableExpr = tableExpr; this.keyExpr = keyExpr; } @@ -32,7 +32,7 @@ if( t != null && luan.currentEnvironment().hasJava() ) JavaLuan.__new_index(luan,t,key,value); else - throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" ); + throw luan.bit(el).exception( "attempt to index '"+tableExpr.el().text()+"' (a " + Luan.type(t) + " value)" ); } }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/SubExpr.java --- a/core/src/luan/impl/SubExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/SubExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class SubExpr extends BinaryOpExpr { - SubExpr(LuanSource.Element se,Expr op1,Expr op2) { + SubExpr(LuanElement se,Expr op1,Expr op2) { super(se,op1,op2); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/TableExpr.java --- a/core/src/luan/impl/TableExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/TableExpr.java Wed May 06 14:32:29 2015 -0600 @@ -2,7 +2,7 @@ import luan.LuanException; import luan.LuanTable; -import luan.LuanSource; +import luan.LuanElement; import luan.Luan; @@ -21,7 +21,7 @@ private final Field[] fields; private final Expressions expressions; - TableExpr(LuanSource.Element se,Field[] fields,Expressions expressions) { + TableExpr(LuanElement se,Field[] fields,Expressions expressions) { super(se); this.fields = fields; this.expressions = expressions;
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/UnaryOpExpr.java --- a/core/src/luan/impl/UnaryOpExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/UnaryOpExpr.java Wed May 06 14:32:29 2015 -0600 @@ -1,12 +1,12 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; abstract class UnaryOpExpr extends CodeImpl implements Expr { final Expr op; - UnaryOpExpr(LuanSource.Element se,Expr op) { + UnaryOpExpr(LuanElement se,Expr op) { super(se); this.op = op; }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/UnmExpr.java --- a/core/src/luan/impl/UnmExpr.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/UnmExpr.java Wed May 06 14:32:29 2015 -0600 @@ -3,7 +3,7 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; import luan.LuanBit; import luan.LuanTable; @@ -11,15 +11,15 @@ // unary minus final class UnmExpr extends UnaryOpExpr { - UnmExpr(LuanSource.Element se,Expr op) { - super(se,op); + UnmExpr(LuanElement el,Expr op) { + super(el,op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o = op.eval(luan); if( o instanceof Number ) return -((Number)o).doubleValue(); - LuanBit bit = luan.bit(se); + LuanBit bit = luan.bit(el); if( o instanceof LuanTable ) { LuanFunction fn = bit.getHandlerFunction("__unm",(LuanTable)o); if( fn != null ) {
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/VarArgs.java --- a/core/src/luan/impl/VarArgs.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/VarArgs.java Wed May 06 14:32:29 2015 -0600 @@ -1,11 +1,11 @@ package luan.impl; -import luan.LuanSource; +import luan.LuanElement; final class VarArgs extends CodeImpl implements Expressions { - VarArgs(LuanSource.Element se) { + VarArgs(LuanElement se) { super(se); }
diff -r 30544d1a9cbf -r b48cfa14ba60 core/src/luan/impl/WhileStmt.java --- a/core/src/luan/impl/WhileStmt.java Wed May 06 12:58:06 2015 -0600 +++ b/core/src/luan/impl/WhileStmt.java Wed May 06 14:32:29 2015 -0600 @@ -2,22 +2,22 @@ import luan.Luan; import luan.LuanException; -import luan.LuanSource; +import luan.LuanElement; final class WhileStmt extends CodeImpl implements Stmt { private final Expr cnd; private final Stmt doStmt; - WhileStmt(LuanSource.Element se,Expr cnd,Stmt doStmt) { - super(se); + WhileStmt(LuanElement el,Expr cnd,Stmt doStmt) { + super(el); this.cnd = cnd; this.doStmt = doStmt; } @Override public void eval(LuanStateImpl luan) throws LuanException { try { - while( luan.bit(se).checkBoolean( cnd.eval(luan) ) ) { + while( luan.bit(el).checkBoolean( cnd.eval(luan) ) ) { doStmt.eval(luan); } } catch(BreakException e) {}