Mercurial Hosting > luan
changeset 645:859c0dedc8b6
remove LuanSource
line wrap: on
line diff
--- a/core/src/luan/LuanElement.java Tue Mar 29 13:53:01 2016 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package luan; - - -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); - } - - 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); - } - - int lineNumber() { - int line = 0; - int i = -1; - do { - line++; - i = source.text.indexOf('\n',i+1); - } while( i != -1 && i < start ); - return line; - } - -}
--- a/core/src/luan/LuanException.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/LuanException.java Tue Mar 29 18:09:51 2016 -0600 @@ -16,6 +16,7 @@ table.rawPut( "java", this ); table.rawPut( "message", msg ); table.rawPut( "message_string", luan.toString(msg) ); +/* for( StackTraceElement ste : luan.stackTrace ) { LuanTable tbl = new LuanTable(); tbl.rawPut( "source", ste.call.source.name ); @@ -23,6 +24,7 @@ tbl.rawPut( "call_to", ste.fnName ); table.rawPut( table.rawLength() + 1, tbl ); } +*/ LuanTable metatable = new LuanTable(); table.setMetatable(metatable); try { @@ -59,6 +61,7 @@ } public static String __to_string(LuanTable table) { +/* StringBuilder buf = new StringBuilder(); Object msg = table.rawGet("message"); @@ -82,6 +85,11 @@ } return buf.toString(); +*/ + LuanException ex = (LuanException)table.rawGet("java"); + StringWriter sw = new StringWriter(); + ex.printStackTrace(new PrintWriter(sw)); + return sw.toString(); } }
--- a/core/src/luan/LuanSource.java Tue Mar 29 13:53:01 2016 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package luan; - - -public final class LuanSource { - public final String name; - public final String text; - - public LuanSource(String name,String text) { - this.name = name; - this.text = text; - } -}
--- a/core/src/luan/LuanState.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/LuanState.java Tue Mar 29 18:09:51 2016 -0600 @@ -15,8 +15,6 @@ public abstract class LuanState implements DeepCloneable { - protected final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); - private Map registry; private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>(); @@ -32,7 +30,6 @@ public abstract boolean hasJava(); public abstract void setJava(); - public abstract LuanSource currentSource(); public final Map registry() { return registry; @@ -68,19 +65,19 @@ public Boolean checkBoolean(Object obj) throws LuanException { if( obj instanceof Boolean ) return (Boolean)obj; - throw new LuanException(this, "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a boolean" ); + throw new LuanException(this, "attempt to use a " + Luan.type(obj) + " value as a boolean" ); } public String checkString(Object obj) throws LuanException { if( obj instanceof String ) return (String)obj; - throw new LuanException(this, "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a string" ); + throw new LuanException(this, "attempt to use a " + Luan.type(obj) + " value as a string" ); } public LuanFunction checkFunction(Object obj) throws LuanException { if( obj instanceof LuanFunction ) return (LuanFunction)obj; - throw new LuanException(this, "attempt to call '"+context()+"' (a " + Luan.type(obj) + " value)" ); + throw new LuanException(this, "attempt to call a " + Luan.type(obj) + " value" ); } abstract public boolean isLessThan(Object o1,Object o2) throws LuanException; @@ -106,16 +103,9 @@ } if( obj != null && hasJava() ) return JavaLuan.__index(this,obj,key,false); - throw new LuanException(this, "attempt to index a " + Luan.type(obj) + " value in '"+context()+"'" ); + throw new LuanException(this, "attempt to index a " + Luan.type(obj) + " value" ); } - public String context() { - return stackTrace.get(stackTrace.size()-1).call.text(); - } - - public void dumpStack() { - System.err.println( stackTrace ); - } /* public Number checkNumber(Object obj) throws LuanException { if( obj instanceof Number )
--- a/core/src/luan/StackTraceElement.java Tue Mar 29 13:53:01 2016 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package luan; - - -public final class StackTraceElement { - final LuanElement call; - final String fnName; - - public StackTraceElement(LuanElement call,String fnName) { - this.call = call; - this.fnName = fnName; - } -}
--- a/core/src/luan/impl/AddExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/AddExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class AddExpr extends BinaryOpExpr { - AddExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + AddExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/AndExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/AndExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,13 +2,12 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class AndExpr extends BinaryOpExpr { - AndExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + AndExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/BinaryOpExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/BinaryOpExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -4,30 +4,23 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; abstract class BinaryOpExpr extends CodeImpl implements Expr { final Expr op1; final Expr op2; - BinaryOpExpr(LuanElement el,Expr op1,Expr op2) { - super(el); + BinaryOpExpr(Expr op1,Expr op2) { this.op1 = op1; this.op2 = op2; } Object arithmetic(LuanStateImpl luan,String op,Object o1,Object o2) throws LuanException { - luan.push(el,null); - try { - LuanFunction fn = luan.getBinHandler(op,o1,o2); - if( fn != null ) - return Luan.first(fn.call(luan,new Object[]{o1,o2})); - String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2); - throw new LuanException(luan,"attempt to perform arithmetic on a "+type+" value"); - } finally { - luan.pop(); - } + LuanFunction fn = luan.getBinHandler(op,o1,o2); + if( fn != null ) + return Luan.first(fn.call(luan,new Object[]{o1,o2})); + String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2); + throw new LuanException(luan,"attempt to perform arithmetic on a "+type+" value"); } }
--- a/core/src/luan/impl/Closure.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/Closure.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,7 +3,6 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanState; -import luan.LuanElement; import luan.LuanException; import luan.DeepCloner; import luan.DeepCloneable;
--- a/core/src/luan/impl/Code.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/Code.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,8 +1,4 @@ package luan.impl; -import luan.LuanElement; - -interface Code { - public LuanElement el(); -} +interface Code {}
--- a/core/src/luan/impl/CodeImpl.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/CodeImpl.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,16 +1,4 @@ package luan.impl; -import luan.LuanElement; - -class CodeImpl implements Code { - final LuanElement el; - - CodeImpl(LuanElement el) { - this.el = el; - } - - @Override public final LuanElement el() { - return el; - } -} +class CodeImpl implements Code {}
--- a/core/src/luan/impl/ConcatExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ConcatExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,28 +3,22 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; final class ConcatExpr extends BinaryOpExpr { - ConcatExpr(LuanElement el,Expr op1,Expr op2) { - super(el,op1,op2); + ConcatExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o1 = op1.eval(luan); Object o2 = op2.eval(luan); - luan.push(el,null); - try { - LuanFunction fn = luan.getBinHandler("__concat",o1,o2); - if( fn != null ) - return Luan.first(fn.call(luan,new Object[]{o1,o2})); - } finally { - luan.pop(); - } - String s1 = luan.toString(o1,op1.el()); - String s2 = luan.toString(o2,op2.el()); + LuanFunction fn = luan.getBinHandler("__concat",o1,o2); + if( fn != null ) + return Luan.first(fn.call(luan,new Object[]{o1,o2})); + String s1 = luan.toString(o1); + String s2 = luan.toString(o2); return s1 + s2; } }
--- a/core/src/luan/impl/ConstExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ConstExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,10 @@ package luan.impl; -import luan.LuanElement; - final class ConstExpr extends CodeImpl implements Expr { private final Object obj; - ConstExpr(LuanElement el,Object obj) { - super(el); + ConstExpr(Object obj) { this.obj = obj; }
--- a/core/src/luan/impl/DivExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/DivExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class DivExpr extends BinaryOpExpr { - DivExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + DivExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/EqExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/EqExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -5,13 +5,12 @@ import luan.LuanFunction; import luan.LuanTable; import luan.LuanException; -import luan.LuanElement; final class EqExpr extends BinaryOpExpr { - EqExpr(LuanElement el,Expr op1,Expr op2) { - super(el,op1,op2); + EqExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -44,13 +43,8 @@ Object f = mt1.rawGet("__eq"); if( f == null || !f.equals(mt2.rawGet("__eq")) ) return false; - luan.push(el,"__eq"); - try { - LuanFunction fn = luan.checkFunction(f); - return luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); - } finally { - luan.pop(); - } + LuanFunction fn = luan.checkFunction(f); + return luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); } @Override public String toString() {
--- a/core/src/luan/impl/ExpList.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ExpList.java Tue Mar 29 18:09:51 2016 -0600 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; import luan.LuanException; -import luan.LuanElement; import luan.LuanFunction; import luan.Luan; @@ -16,10 +15,6 @@ @Override public Object[] eval(LuanStateImpl luan) { return LuanFunction.NOTHING; } - - @Override public LuanElement el() { - return null; - } }; static Expr[] toArray(List<Expressions> list) { @@ -65,10 +60,6 @@ } return a; } - - @Override public LuanElement el() { - return new LuanElement(exprs[0].el().source,exprs[0].el().start,exprs[exprs.length-1].el().end); - } } private static class ExprList2 implements Expressions { @@ -88,9 +79,5 @@ list.addAll( Arrays.asList(Luan.array( last.eval(luan) )) ); return list.toArray(); } - - @Override public LuanElement el() { - return new LuanElement(exprs[0].el().source,exprs[0].el().start,last.el().end); - } } }
--- a/core/src/luan/impl/ExprImpl.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ExprImpl.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,11 +1,4 @@ package luan.impl; -import luan.LuanElement; - -abstract class ExprImpl extends CodeImpl implements Expr { - - ExprImpl(LuanElement el) { - super(el); - } -} +abstract class ExprImpl extends CodeImpl implements Expr {}
--- a/core/src/luan/impl/ExpressionsExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ExpressionsExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,7 +3,6 @@ import java.util.List; import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class ExpressionsExpr implements Expr { @@ -19,8 +18,4 @@ return Luan.first( expressions.eval(luan) ); } - public LuanElement el() { - return expressions.el(); - } - }
--- a/core/src/luan/impl/FnCall.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/FnCall.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,20 +3,16 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; import luan.LuanTable; final class FnCall extends CodeImpl implements Expressions { final Expr fnExpr; final Expressions args; - final String fnName; - FnCall(LuanElement el,Expr fnExpr,Expressions args) { - super(el); + FnCall(Expr fnExpr,Expressions args) { this.fnExpr = fnExpr; this.args = args; - this.fnName = fnExpr.el().text(); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -24,25 +20,20 @@ } private Object call(LuanStateImpl luan,Object o,Object[] argVals) throws LuanException { - luan.push(el,fnName); - try { - if( o instanceof LuanFunction ) { - LuanFunction fn = (LuanFunction)o; - return fn.call( luan, argVals ); - } - if( o instanceof LuanTable ) { - LuanTable t = (LuanTable)o; - Object h = t.getHandler("__call"); - if( h != null ) - return call(luan,h,argVals); - } - throw new LuanException(luan, "attempt to call '"+fnName+"' (a " + Luan.type(o) + " value)" ); - } finally { - luan.pop(); + if( o instanceof LuanFunction ) { + LuanFunction fn = (LuanFunction)o; + return fn.call( luan, argVals ); } + if( o instanceof LuanTable ) { + LuanTable t = (LuanTable)o; + Object h = t.getHandler("__call"); + if( h != null ) + return call(luan,h,argVals); + } + throw new LuanException(luan, "attempt to call a " + Luan.type(o) + " value" ); } @Override public String toString() { - return "(FnCall "+fnName+" "+fnExpr+" "+args+")"; + return "(FnCall "+fnExpr+" "+args+")"; } }
--- a/core/src/luan/impl/FnDef.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/FnDef.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,7 +1,6 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class FnDef extends CodeImpl implements Expr { @@ -11,8 +10,7 @@ final boolean isVarArg; final UpValue.Getter[] upValueGetters; - FnDef(LuanElement se,Stmt block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) { - super(se); + FnDef(Stmt block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) { this.block = block; this.stackSize = stackSize; this.numArgs = numArgs;
--- a/core/src/luan/impl/ForStmt.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ForStmt.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,7 +3,6 @@ import luan.Luan; import luan.LuanException; import luan.LuanFunction; -import luan.LuanElement; final class ForStmt extends CodeImpl implements Stmt { @@ -12,8 +11,7 @@ private final Expr iterExpr; private final Stmt block; - ForStmt(LuanElement el,int iVars,int nVars,Expr iterExpr,Stmt block) { - super(el); + ForStmt(int iVars,int nVars,Expr iterExpr,Stmt block) { this.iVars = iVars; this.nVars = nVars; this.iterExpr = iterExpr; @@ -22,10 +20,8 @@ @Override public void eval(LuanStateImpl luan) throws LuanException { Object fnObj = iterExpr.eval(luan); - luan.push( iterExpr.el(), iterExpr.el().text() ); try { LuanFunction iter = luan.checkFunction(fnObj); - String name = iterExpr.el().text(); while(true) { Object vals = iter.call(luan); if( vals==null ) @@ -48,7 +44,6 @@ } catch(BreakException e) { } finally { luan.stackClear(iVars,iVars+nVars); - luan.pop(); } }
--- a/core/src/luan/impl/GetLocalVar.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/GetLocalVar.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,10 @@ package luan.impl; -import luan.LuanElement; - final class GetLocalVar extends CodeImpl implements Expr { private final int index; - GetLocalVar(LuanElement se,int index) { - super(se); + GetLocalVar(int index) { if( index < 0 ) throw new RuntimeException(); this.index = index; }
--- a/core/src/luan/impl/GetUpVar.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/GetUpVar.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,10 @@ package luan.impl; -import luan.LuanElement; - final class GetUpVar extends CodeImpl implements Expr { private final int index; - GetUpVar(LuanElement se,int index) { - super(se); + GetUpVar(int index) { if( index < 0 ) throw new RuntimeException(); this.index = index; }
--- a/core/src/luan/impl/IfStmt.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/IfStmt.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,7 +2,6 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class IfStmt extends CodeImpl implements Stmt { @@ -10,15 +9,14 @@ final Stmt thenStmt; final Stmt elseStmt; - IfStmt(LuanElement el,Expr cnd,Stmt thenStmt,Stmt elseStmt) { - super(el); + IfStmt(Expr cnd,Stmt thenStmt,Stmt elseStmt) { this.cnd = cnd; this.thenStmt = thenStmt; this.elseStmt = elseStmt; } @Override public void eval(LuanStateImpl luan) throws LuanException { - if( luan.checkBoolean( cnd.eval(luan), cnd.el() ) ) { + if( luan.checkBoolean( cnd.eval(luan) ) ) { thenStmt.eval(luan); } else { elseStmt.eval(luan);
--- a/core/src/luan/impl/IndexExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/IndexExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,24 +1,18 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class IndexExpr extends BinaryOpExpr { - IndexExpr(LuanElement el,Expr op1,Expr op2) { - super(el,op1,op2); + IndexExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o1 = op1.eval(luan); Object o2 = op2.eval(luan); - luan.push(el,null); - try { - return luan.index(o1,o2); - } finally { - luan.pop(); - } + return luan.index(o1,o2); } }
--- a/core/src/luan/impl/LeExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LeExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,13 +3,12 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; final class LeExpr extends BinaryOpExpr { - LeExpr(LuanElement el,Expr op1,Expr op2) { - super(el,op1,op2); + LeExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -29,17 +28,12 @@ String s2 = (String)o2; return s1.compareTo(s2) <= 0; } - luan.push(el,null); - try { - LuanFunction fn = luan.getBinHandler("__le",o1,o2); - if( fn != null ) - return luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); - fn = luan.getBinHandler("__lt",o1,o2); - if( fn != null ) - return !luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o2,o1})) ); - throw new LuanException(luan, "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); - } finally { - luan.pop(); - } + LuanFunction fn = luan.getBinHandler("__le",o1,o2); + if( fn != null ) + return luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); + fn = luan.getBinHandler("__lt",o1,o2); + if( fn != null ) + return !luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o2,o1})) ); + throw new LuanException(luan, "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); } }
--- a/core/src/luan/impl/LenExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LenExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -4,13 +4,12 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; final class LenExpr extends UnaryOpExpr { - LenExpr(LuanElement el,Expr op) { - super(el,op); + LenExpr(Expr op) { + super(op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { @@ -23,14 +22,9 @@ byte[] a = (byte[])o; return a.length; } - luan.push(el,null); - try { - if( !(o instanceof LuanTable) ) - throw new LuanException(luan, "attempt to get length of a " + Luan.type(o) + " value" ); - LuanTable t = (LuanTable)o; - return t.length(luan); - } finally { - luan.pop(); - } + if( !(o instanceof LuanTable) ) + throw new LuanException(luan, "attempt to get length of a " + Luan.type(o) + " value" ); + LuanTable t = (LuanTable)o; + return t.length(luan); } }
--- a/core/src/luan/impl/LtExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LtExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,23 +3,17 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; final class LtExpr extends BinaryOpExpr { - LtExpr(LuanElement el,Expr op1,Expr op2) { - super(el,op1,op2); + LtExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o1 = op1.eval(luan); Object o2 = op2.eval(luan); - luan.push(el,null); - try { - return luan.isLessThan(o1,o2); - } finally { - luan.pop(); - } + return luan.isLessThan(o1,o2); } }
--- a/core/src/luan/impl/LuanCompiler.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LuanCompiler.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,8 +3,6 @@ import luan.LuanFunction; import luan.LuanState; import luan.LuanException; -import luan.LuanSource; -import luan.LuanElement; import luan.LuanTable; import luan.modules.JavaLuan; import luan.modules.PackageLuan; @@ -14,8 +12,8 @@ public final class LuanCompiler { private LuanCompiler() {} // never - public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env,boolean allowExpr) throws LuanException { - LuanParser parser = new LuanParser(src,env); + public static LuanFunction compile(LuanState luan,String sourceName,String sourceText,LuanTable env,boolean allowExpr) throws LuanException { + LuanParser parser = new LuanParser(sourceName,sourceText,env); parser.addVar( "java", JavaLuan.javaFn ); parser.addVar( "require", PackageLuan.requireFn ); FnDef fnDef = parse(luan,parser,allowExpr);
--- a/core/src/luan/impl/LuanParser.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LuanParser.java Tue Mar 29 18:09:51 2016 -0600 @@ -8,8 +8,6 @@ import java.util.Scanner; import luan.Luan; import luan.LuanState; -import luan.LuanSource; -import luan.LuanElement; import luan.LuanTable; import luan.modules.PackageLuan; @@ -97,14 +95,14 @@ private static final String _ENV = "_ENV"; private static final UpValue.Getter[] NO_UP_VALUE_GETTERS = new UpValue.Getter[0]; - final LuanSource source; +// final LuanSource source; private Frame frame; private final Parser parser; - LuanParser(LuanSource source,LuanTable env) { - this.source = source; + LuanParser(String sourceName,String sourceText,LuanTable env) { +// this.source = source; this.frame = new Frame( env!=null ? env : new LuanTable() ); - this.parser = new Parser(source); + this.parser = new Parser(sourceName,sourceText); if( env != null ) addVar(_ENV,env); } @@ -113,14 +111,6 @@ frame.addUpValueGetter(name,new UpValue.ValueGetter(value)); } - private LuanElement se(int start) { - return se(start,null); - } - - private LuanElement se(int start,String text) { - return new LuanElement(source,start,parser.currentIndex(),text); - } - private List<String> symbols() { return frame.symbols; } @@ -185,7 +175,7 @@ } private FnDef newFnDef(int start,Stmt stmt) { - return new FnDef( se(start), stmt, frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) ); + return new FnDef( stmt, frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) ); } FnDef Expression() throws ParseException { @@ -193,7 +183,7 @@ int start = parser.begin(); Expressions expr = ExprZ(In.NOTHING); if( expr != null && parser.endOfInput() ) { - Stmt stmt = new ReturnStmt( se(start), expr ); + Stmt stmt = new ReturnStmt( expr ); return parser.success(newFnDef(start,stmt)); } return parser.failure(null); @@ -266,17 +256,14 @@ } private Stmt TemplateStmt() throws ParseException { - int start = parser.currentIndex(); + parser.currentIndex(); Expressions exprs = TemplateExpressions(In.NOTHING); if( exprs == null ) return null; - 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") ); - se = se(start,"write"); - Expr writeExp = new IndexExpr( se, stdoutExp, new ConstExpr(se,"write") ); - FnCall writeCall = new FnCall( se(start), writeExp, exprs ); + FnCall requireCall = new FnCall( new ConstExpr(PackageLuan.requireFn), new ConstExpr("luan:Io") ); + Expr stdoutExp = new IndexExpr( expr(requireCall), new ConstExpr("stdout") ); + Expr writeExp = new IndexExpr( stdoutExp, new ConstExpr("write") ); + FnCall writeCall = new FnCall( writeExp, exprs ); return new ExpressionsStmt(writeCall); } @@ -306,19 +293,19 @@ throw parser.exception("Unclosed template expression"); } while( !parser.test( "<%" ) ); String match = parser.textFrom(i); - builder.add( new ConstExpr(se(i),match) ); + builder.add( new ConstExpr(match) ); } } } private Stmt ReturnStmt() throws ParseException { - int start = parser.begin(); + parser.begin(); if( !Keyword("return",In.NOTHING) ) return parser.failure(null); Expressions exprs = ExpList(In.NOTHING); if( exprs==null ) exprs = ExpList.emptyExpList; - return parser.success( new ReturnStmt(se(start),exprs) ); + return parser.success( new ReturnStmt(exprs) ); } private Stmt FunctionStmt() throws ParseException { @@ -326,14 +313,14 @@ if( !Keyword("function",In.NOTHING) ) return parser.failure(null); - int start = parser.currentIndex(); - Var var = nameVar(start,RequiredName(In.NOTHING)); + parser.currentIndex(); + Var var = nameVar(RequiredName(In.NOTHING)); while( parser.match( '.' ) ) { Spaces(In.NOTHING); Expr exp = NameExpr(In.NOTHING); if( exp==null ) return parser.failure(null); - var = indexVar( start, expr(var.expr()), exp ); + var = indexVar( expr(var.expr()), exp ); } Settable fnName = var.settable(); @@ -361,7 +348,7 @@ } private Stmt ForStmt() throws ParseException { - int start = parser.begin(); + parser.begin(); int stackStart = symbolsSize(); if( !Keyword("for",In.NOTHING) ) return parser.failure(null); @@ -373,7 +360,7 @@ addSymbols(names); Stmt loop = RequiredLoopBlock(); RequiredKeyword("end",In.NOTHING); - Stmt stmt = new ForStmt( se(start), stackStart, symbolsSize() - stackStart, expr, loop ); + Stmt stmt = new ForStmt( stackStart, symbolsSize() - stackStart, expr, loop ); popSymbols( symbolsSize() - stackStart ); return parser.success(stmt); } @@ -445,24 +432,24 @@ } private Stmt WhileStmt() throws ParseException { - int start = parser.begin(); + parser.begin(); if( !Keyword("while",In.NOTHING) ) return parser.failure(null); Expr cnd = expr(RequiredExpr(In.NOTHING)); RequiredKeyword("do",In.NOTHING); Stmt loop = RequiredLoopBlock(); RequiredKeyword("end",In.NOTHING); - return parser.success( new WhileStmt(se(start),cnd,loop) ); + return parser.success( new WhileStmt(cnd,loop) ); } private Stmt RepeatStmt() throws ParseException { - int start = parser.begin(); + parser.begin(); if( !Keyword("repeat",In.NOTHING) ) return parser.failure(null); Stmt loop = RequiredLoopBlock(); RequiredKeyword("until",In.NOTHING); Expr cnd = expr(RequiredExpr(In.NOTHING)); - return parser.success( new RepeatStmt(se(start),loop,cnd) ); + return parser.success( new RepeatStmt(loop,cnd) ); } private Stmt RequiredLoopBlock() throws ParseException { @@ -480,7 +467,7 @@ } private Stmt IfStmt2() throws ParseException { - int start = parser.currentIndex(); + parser.currentIndex(); Expr cnd = expr(RequiredExpr(In.NOTHING)); RequiredKeyword("then",In.NOTHING); Stmt thenBlock = RequiredBlock(); @@ -491,7 +478,7 @@ elseBlock = Keyword("else",In.NOTHING) ? RequiredBlock() : Stmt.EMPTY; RequiredKeyword("end",In.NOTHING); } - return new IfStmt(se(start),cnd,thenBlock,elseBlock); + return new IfStmt(cnd,thenBlock,elseBlock); } private Stmt SetStmt() throws ParseException { @@ -544,31 +531,31 @@ } private Expressions OrExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = AndExpr(in); if( exp==null ) return parser.failure(null); while( Keyword("or",in) ) { Expressions exp2 = AndExpr(in); - exp = new OrExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new OrExpr( expr(exp), required(expr(exp2)) ); } return parser.success(exp); } private Expressions AndExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = RelExpr(in); if( exp==null ) return parser.failure(null); while( Keyword("and",in) ) { Expressions exp2 = RelExpr(in); - exp = new AndExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new AndExpr( expr(exp), required(expr(exp2)) ); } return parser.success(exp); } private Expressions RelExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = ConcatExpr(in); if( exp==null ) return parser.failure(null); @@ -576,27 +563,27 @@ if( parser.match("==") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new EqExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new EqExpr( expr(exp), required(expr(exp2)) ); } else if( parser.match("~=") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new NotExpr( se(start), new EqExpr( se(start), expr(exp), required(expr(exp2)) ) ); + exp = new NotExpr( new EqExpr( expr(exp), required(expr(exp2)) ) ); } else if( parser.match("<=") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new LeExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new LeExpr( expr(exp), required(expr(exp2)) ); } else if( parser.match(">=") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new LeExpr( se(start), required(expr(exp2)), expr(exp) ); + exp = new LeExpr( required(expr(exp2)), expr(exp) ); } else if( parser.match("<") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new LtExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new LtExpr( expr(exp), required(expr(exp2)) ); } else if( parser.match(">") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new LtExpr( se(start), required(expr(exp2)), expr(exp) ); + exp = new LtExpr( required(expr(exp2)), expr(exp) ); } else break; } @@ -604,20 +591,20 @@ } private Expressions ConcatExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = SumExpr(in); if( exp==null ) return parser.failure(null); if( parser.match("..") ) { Spaces(in); Expressions exp2 = ConcatExpr(in); - exp = new ConcatExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new ConcatExpr( expr(exp), required(expr(exp2)) ); } return parser.success(exp); } private Expressions SumExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = TermExpr(in); if( exp==null ) return parser.failure(null); @@ -625,11 +612,11 @@ if( parser.match('+') ) { Spaces(in); Expressions exp2 = TermExpr(in); - exp = new AddExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new AddExpr( expr(exp), required(expr(exp2)) ); } else if( Minus() ) { Spaces(in); Expressions exp2 = TermExpr(in); - exp = new SubExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new SubExpr( expr(exp), required(expr(exp2)) ); } else break; } @@ -642,7 +629,7 @@ } private Expressions TermExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = UnaryExpr(in); if( exp==null ) return parser.failure(null); @@ -650,15 +637,15 @@ if( parser.match('*') ) { Spaces(in); Expressions exp2 = UnaryExpr(in); - exp = new MulExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new MulExpr( expr(exp), required(expr(exp2)) ); } else if( parser.match('/') ) { Spaces(in); Expressions exp2 = UnaryExpr(in); - exp = new DivExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new DivExpr( expr(exp), required(expr(exp2)) ); } else if( Mod() ) { Spaces(in); Expressions exp2 = UnaryExpr(in); - exp = new ModExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new ModExpr( expr(exp), required(expr(exp2)) ); } else break; } @@ -671,21 +658,21 @@ } private Expressions UnaryExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); if( parser.match('#') ) { Spaces(in); Expressions exp = UnaryExpr(in); - return parser.success( new LenExpr( se(start), required(expr(exp)) ) ); + return parser.success( new LenExpr( required(expr(exp)) ) ); } if( Minus() ) { Spaces(in); Expressions exp = UnaryExpr(in); - return parser.success( new UnmExpr( se(start), required(expr(exp)) ) ); + return parser.success( new UnmExpr( required(expr(exp)) ) ); } if( Keyword("not",in) ) { Spaces(in); Expressions exp = UnaryExpr(in); - return parser.success( new NotExpr( se(start), required(expr(exp)) ) ); + return parser.success( new NotExpr( required(expr(exp)) ) ); } Expressions exp = PowExpr(in); if( exp==null ) @@ -694,14 +681,14 @@ } private Expressions PowExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); Expressions exp = SingleExpr(in); if( exp==null ) return parser.failure(null); if( parser.match('^') ) { Spaces(in); Expressions exp2 = PowExpr(in); - exp = new PowExpr( se(start), expr(exp), required(expr(exp2)) ); + exp = new PowExpr( expr(exp), required(expr(exp2)) ); } return parser.success(exp); } @@ -757,15 +744,15 @@ } private VarArgs VarArgs(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); if( !frame.isVarArg || !parser.match("...") ) return parser.failure(null); Spaces(in); - return parser.success( new VarArgs(se(start)) ); + return parser.success( new VarArgs() ); } private Expr TableExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); if( !parser.match('{') ) return parser.failure(null); Spaces(In.NOTHING); @@ -782,7 +769,7 @@ if( !parser.match('}') ) throw parser.exception("Expected table element or '}'"); Spaces(in); - return parser.success( new TableExpr( se(start), fields.toArray(new TableExpr.Field[0]), ExpList.build(builder) ) ); + return parser.success( new TableExpr( fields.toArray(new TableExpr.Field[0]), ExpList.build(builder) ) ); } private boolean FieldSep() throws ParseException { @@ -814,18 +801,18 @@ } private Var VarZ(In in) throws ParseException { - int start = parser.begin(); - Var var = VarStart(in,start); + parser.begin(); + Var var = VarStart(in); if( var==null ) return parser.failure(null); Var var2; - while( (var2=Var2(in,start,var.expr())) != null ) { + while( (var2=Var2(in,var.expr())) != null ) { var = var2; } return parser.success(var); } - private Var VarStart(In in,int start) throws ParseException { + private Var VarStart(In in) throws ParseException { if( parser.match('(') ) { In inParens = in.parens(); Spaces(inParens); @@ -836,7 +823,7 @@ } String name = Name(in); if( name != null ) - return nameVar(start,name); + return nameVar(name); Expressions exp; exp = TableExpr(in); if( exp != null ) @@ -847,19 +834,19 @@ return null; } - private Var Var2(In in,int start,Expressions exp1) throws ParseException { + private Var Var2(In in,Expressions exp1) throws ParseException { parser.begin(); Expr exp2 = SubExpr(in); if( exp2 != null ) - return parser.success(indexVar(start,expr(exp1),exp2)); + return parser.success(indexVar(expr(exp1),exp2)); if( parser.match('.') ) { Spaces(in); exp2 = NameExpr(in); if( exp2!=null ) - return parser.success(indexVar(start,expr(exp1),exp2)); + return parser.success(indexVar(expr(exp1),exp2)); return parser.failure(null); } - FnCall fnCall = Args( in, start, expr(exp1), new ArrayList<Expressions>() ); + FnCall fnCall = Args( in, expr(exp1), new ArrayList<Expressions>() ); if( fnCall != null ) return parser.success(exprVar(fnCall)); return parser.failure(null); @@ -873,30 +860,26 @@ private Expr env() { int index = stackIndex(_ENV); if( index != -1 ) - return new GetLocalVar(null,index); + return new GetLocalVar(index); index = upValueIndex(_ENV); if( index != -1 ) - return new GetUpVar(null,index); + return new GetUpVar(index); return null; } - private Var nameVar(final int start,final String name) { - return nameVar(se(start,name),name); - } - - private Var nameVar(final LuanElement se,final String name) { + private Var nameVar(final String name) { return new Var() { public Expr expr() throws ParseException { int index = stackIndex(name); if( index != -1 ) - return new GetLocalVar(se,index); + return new GetLocalVar(index); index = upValueIndex(name); if( index != -1 ) - return new GetUpVar(se,index); + return new GetUpVar(index); Expr envExpr = env(); if( envExpr != null ) - return new IndexExpr( se, envExpr, new ConstExpr(se,name) ); + return new IndexExpr( envExpr, new ConstExpr(name) ); parser.failure(null); throw parser.exception("name '"+name+"' not defined"); } @@ -910,7 +893,7 @@ return new SetUpVar(index); Expr envExpr = env(); if( envExpr != null ) - return new SetTableEntry( se, envExpr, new ConstExpr(se,name) ); + return new SetTableEntry( envExpr, new ConstExpr(name) ); parser.failure(null); throw parser.exception("name '"+name+"' not defined"); } @@ -930,28 +913,28 @@ }; } - private Var indexVar(final int start,final Expr table,final Expr key) { + private Var indexVar(final Expr table,final Expr key) { return new Var() { public Expr expr() { - return new IndexExpr( se(start), table, key ); + return new IndexExpr( table, key ); } public Settable settable() { - return new SetTableEntry(se(start),table,key); + return new SetTableEntry(table,key); } }; } - private FnCall Args(In in,int start,Expr fn,List<Expressions> builder) throws ParseException { + private FnCall Args(In in,Expr fn,List<Expressions> builder) throws ParseException { parser.begin(); return args(in,builder) - ? parser.success( new FnCall( se(start), fn, ExpList.build(builder) ) ) + ? parser.success( new FnCall( fn, ExpList.build(builder) ) ) : parser.failure((FnCall)null); } private boolean args(In in,List<Expressions> builder) throws ParseException { - int start = parser.begin(); + parser.begin(); if( parser.match('(') ) { In inParens = in.parens(); Spaces(inParens); @@ -968,7 +951,7 @@ } String s = StringLiteral(in); if( s != null ) { - builder.add( new ConstExpr(se(start),s) ); + builder.add( new ConstExpr(s) ); return parser.success(); } /* @@ -1021,11 +1004,11 @@ } private Expr NameExpr(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); String name = Name(in); if( name==null ) return parser.failure(null); - return parser.success(new ConstExpr(se(start),name)); + return parser.success(new ConstExpr(name)); } private String RequiredName(In in) throws ParseException { @@ -1105,18 +1088,18 @@ )); private Expr Literal(In in) throws ParseException { - int start = parser.begin(); + parser.begin(); if( NilLiteral(in) ) - return parser.success(new ConstExpr(se(start),null)); + return parser.success(new ConstExpr(null)); Boolean b = BooleanLiteral(in); if( b != null ) - return parser.success(new ConstExpr(se(start),b)); + return parser.success(new ConstExpr(b)); Number n = NumberLiteral(in); if( n != null ) - return parser.success(new ConstExpr(se(start),n)); + return parser.success(new ConstExpr(n)); String s = StringLiteral(in); if( s != null ) - return parser.success(new ConstExpr(se(start),s)); + return parser.success(new ConstExpr(s)); return parser.failure(null); }
--- a/core/src/luan/impl/LuanStateImpl.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/LuanStateImpl.java Tue Mar 29 18:09:51 2016 -0600 @@ -9,10 +9,7 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; -import luan.LuanSource; import luan.DeepCloner; -import luan.StackTraceElement; final class LuanStateImpl extends LuanState { @@ -119,12 +116,6 @@ ((LuanTable)frame.closure.upValues()[0].get()).hasJava = true; } - @Override public LuanSource currentSource(){ - if( frame==null ) - return null; - return frame.closure.fnDef.el().source; - } - @Override public boolean isLessThan(Object o1,Object o2) throws LuanException { @@ -160,31 +151,4 @@ return checkFunction(f); } - Boolean checkBoolean(Object obj,LuanElement el) throws LuanException { - push(el,null); - try { - return checkBoolean(obj); - } finally { - pop(); - } - } - - String toString(Object obj,LuanElement el) throws LuanException { - push(el,null); - try { - return toString(obj); - } finally { - pop(); - } - } - - void push(LuanElement el,String fnName) { - if( el == null ) throw new RuntimeException(); - stackTrace.add( new StackTraceElement(el,fnName) ); - } - - void pop() { - stackTrace.remove(stackTrace.size()-1); - } - }
--- a/core/src/luan/impl/ModExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ModExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class ModExpr extends BinaryOpExpr { - ModExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + ModExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/MulExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/MulExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class MulExpr extends BinaryOpExpr { - MulExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + MulExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/NotExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/NotExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,17 +2,16 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class NotExpr extends UnaryOpExpr { - NotExpr(LuanElement el,Expr op) { - super(el,op); + NotExpr(Expr op) { + super(op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { - return !luan.checkBoolean( op.eval(luan), op.el() ); + return !luan.checkBoolean( op.eval(luan) ); } @Override public String toString() {
--- a/core/src/luan/impl/OrExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/OrExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,13 +2,12 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class OrExpr extends BinaryOpExpr { - OrExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + OrExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/ParseException.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ParseException.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,16 +1,18 @@ package luan.impl; -import luan.LuanSource; - public final class ParseException extends Exception { - public final LuanSource src; +// public final LuanSource src; + public final String sourceName; + public final String text; public final int iCurrent; public final int iHigh; - ParseException(String msg,LuanSource src,int iCurrent,int iHigh) { + ParseException(String msg,String sourceName,String text,int iCurrent,int iHigh) { super(msg); - this.src = src; +// this.src = src; + this.sourceName = sourceName; + this.text = text; this.iCurrent = iCurrent; this.iHigh = iHigh; //System.out.println("iCurrent = "+iCurrent); @@ -25,7 +27,7 @@ int line = 0; int i = -1; while(true) { - int j = src.text.indexOf('\n',i+1); + int j = text.indexOf('\n',i+1); if( j == -1 || j >= index ) break; i = j; @@ -37,13 +39,13 @@ } private String[] lines() { - return src.text.split("\n",-1); + return text.split("\n",-1); } public String getFancyMessage() { Location loc = new Location(iCurrent); String line = lines()[loc.line]; - String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + src.name + "\n"; + String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + sourceName + "\n"; StringBuilder sb = new StringBuilder(msg); sb.append( line + "\n" ); for( int i=0; i<loc.pos; i++ ) {
--- a/core/src/luan/impl/Parser.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/Parser.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,19 +1,19 @@ package luan.impl; -import luan.LuanSource; - final class Parser { - private final LuanSource src; +// private final LuanSource src; + public final String sourceName; public final String text; private final int len; private int[] stack = new int[256]; private int frame = 0; private int iHigh; - public Parser(LuanSource src) { - this.src = src; - this.text = src.text; + public Parser(String sourceName,String text) { +// this.src = src; + this.sourceName = sourceName; + this.text = text; this.len = text.length(); } @@ -64,7 +64,7 @@ } public ParseException exception(String msg) { - return new ParseException(msg,src,i(),iHigh); + return new ParseException(msg,sourceName,text,i(),iHigh); } public ParseException exception() {
--- a/core/src/luan/impl/PowExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/PowExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class PowExpr extends BinaryOpExpr { - PowExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + PowExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/RepeatStmt.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/RepeatStmt.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,15 +2,13 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class RepeatStmt extends CodeImpl implements Stmt { private final Stmt doStmt; private final Expr cnd; - RepeatStmt(LuanElement el,Stmt doStmt,Expr cnd) { - super(el); + RepeatStmt(Stmt doStmt,Expr cnd) { this.doStmt = doStmt; this.cnd = cnd; } @@ -19,7 +17,7 @@ try { do { doStmt.eval(luan); - } while( !luan.checkBoolean( cnd.eval(luan), el ) ); + } while( !luan.checkBoolean( cnd.eval(luan) ) ); } catch(BreakException e) {} } }
--- a/core/src/luan/impl/ReturnStmt.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ReturnStmt.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,15 +3,13 @@ import luan.Luan; import luan.LuanException; import luan.LuanFunction; -import luan.LuanElement; final class ReturnStmt extends CodeImpl implements Stmt { private final Expressions expressions; boolean throwReturnException = true; - ReturnStmt(LuanElement el,Expressions expressions) { - super(el); + ReturnStmt(Expressions expressions) { this.expressions = expressions; } @@ -25,12 +23,7 @@ if( tailFn instanceof Closure ) { luan.tailFn = (Closure)tailFn; } else { - luan.push(el,tailFnCall.fnName); - try { - luan.returnValues = tailFn.call(luan,Luan.array(luan.returnValues)); - } finally { - luan.pop(); - } + luan.returnValues = tailFn.call(luan,Luan.array(luan.returnValues)); } } if( throwReturnException )
--- a/core/src/luan/impl/SetTableEntry.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/SetTableEntry.java Tue Mar 29 18:09:51 2016 -0600 @@ -4,7 +4,6 @@ import luan.LuanTable; import luan.Luan; import luan.LuanFunction; -import luan.LuanElement; import luan.LuanMeta; import luan.modules.JavaLuan; @@ -13,8 +12,7 @@ private final Expr tableExpr; private final Expr keyExpr; - SetTableEntry(LuanElement el,Expr tableExpr,Expr keyExpr) { - super(el); + SetTableEntry(Expr tableExpr,Expr keyExpr) { this.tableExpr = tableExpr; this.keyExpr = keyExpr; } @@ -24,20 +22,15 @@ } private void newIndex(LuanStateImpl luan,Object t,Object key,Object value) throws LuanException { - luan.push(el,null); - try { - if( t instanceof LuanTable ) { - LuanTable tbl = (LuanTable)t; - tbl.put(luan,key,value); - return; - } - if( t != null && luan.hasJava() ) - JavaLuan.__new_index(luan,t,key,value); - else - throw new LuanException(luan, "attempt to index a " + Luan.type(t) + " value in '"+el.text()+"'" ); - } finally { - luan.pop(); + if( t instanceof LuanTable ) { + LuanTable tbl = (LuanTable)t; + tbl.put(luan,key,value); + return; } + if( t != null && luan.hasJava() ) + JavaLuan.__new_index(luan,t,key,value); + else + throw new LuanException(luan, "attempt to index a " + Luan.type(t) + " value" ); } }
--- a/core/src/luan/impl/SubExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/SubExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,12 @@ package luan.impl; import luan.LuanException; -import luan.LuanElement; final class SubExpr extends BinaryOpExpr { - SubExpr(LuanElement se,Expr op1,Expr op2) { - super(se,op1,op2); + SubExpr(Expr op1,Expr op2) { + super(op1,op2); } @Override public Object eval(LuanStateImpl luan) throws LuanException {
--- a/core/src/luan/impl/TableExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/TableExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,7 +2,6 @@ import luan.LuanException; import luan.LuanTable; -import luan.LuanElement; import luan.Luan; @@ -21,8 +20,7 @@ private final Field[] fields; private final Expressions expressions; - TableExpr(LuanElement se,Field[] fields,Expressions expressions) { - super(se); + TableExpr(Field[] fields,Expressions expressions) { this.fields = fields; this.expressions = expressions; }
--- a/core/src/luan/impl/ThemeParser.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/ThemeParser.java Tue Mar 29 18:09:51 2016 -0600 @@ -5,9 +5,7 @@ import java.util.List; import java.util.ArrayList; import luan.Luan; -import luan.LuanSource; import luan.LuanTable; -import luan.LuanElement; import luan.LuanState; import luan.LuanFunction; import luan.LuanException; @@ -16,9 +14,9 @@ public final class ThemeParser { - public static LuanFunction compile(LuanState luan,LuanSource source) throws LuanException { + public static LuanFunction compile(LuanState luan,String sourceName,String sourceText) throws LuanException { try { - FnDef fnDef = new ThemeParser(source).parse(); + FnDef fnDef = new ThemeParser(sourceName,sourceText).parse(); final LuanStateImpl luanImpl = (LuanStateImpl)luan; return new Closure(luanImpl,fnDef); } catch(ParseException e) { @@ -89,21 +87,13 @@ private static final String INDENT = "-INDENT-"; private static final UpValue.Getter[] NO_UP_VALUE_GETTERS = new UpValue.Getter[0]; - private final LuanSource source; +// private final LuanSource source; private final Parser parser; private Frame frame = new Frame(); - private ThemeParser(LuanSource source) { - this.source = source; - this.parser = new Parser(this.source); - } - - private LuanElement se(int start) { - return se(start,null); - } - - private LuanElement se(int start,String text) { - return new LuanElement(source,start,parser.currentIndex(),text); + private ThemeParser(String sourceName,String sourceText) { +// this.source = source; + this.parser = new Parser(sourceName,sourceText); } private int symbolsSize() { @@ -116,8 +106,8 @@ frame.stackSize = symbolsSize(); } - private FnDef newFnDef(int start,Stmt stmt) { - return new FnDef( se(start), stmt, frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) ); + private FnDef newFnDef(Stmt stmt) { + return new FnDef( stmt, frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) ); } private int stackIndex(String name) { @@ -141,7 +131,7 @@ } private Expr env() { - return new GetLocalVar(null,stackIndex(ENV)); + return new GetLocalVar(stackIndex(ENV)); } private FnDef parse() throws ParseException { @@ -149,16 +139,14 @@ int stackStart = symbolsSize(); { addSymbol(IO); - LuanElement se = se(0,"require 'luan:Io'"); - FnCall requireCall = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(se,"luan:Io") ); + FnCall requireCall = new FnCall( new ConstExpr(PackageLuan.requireFn), new ConstExpr("luan:Io") ); SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(IO)), new ExpressionsExpr(requireCall) ); stmts.add(setStmt); } { addSymbol(MOD); - LuanElement se = se(0,"local M = {['-INDENT-']=''}"); - TableExpr.Field indent = new TableExpr.Field(new ConstExpr(null,INDENT),new ConstExpr(null,"")); - TableExpr tableExpr = new TableExpr( se, new TableExpr.Field[]{indent}, ExpList.emptyExpList ); + TableExpr.Field indent = new TableExpr.Field(new ConstExpr(INDENT),new ConstExpr("")); + TableExpr tableExpr = new TableExpr( new TableExpr.Field[]{indent}, ExpList.emptyExpList ); SetStmt setStmt = new SetStmt( new SetLocalVar(stackIndex(MOD)), tableExpr ); stmts.add(setStmt); } @@ -170,14 +158,14 @@ parser.anyChar(); } } - stmts.add( new ReturnStmt(null,new GetLocalVar(null,stackIndex(MOD))) ); + stmts.add( new ReturnStmt(new GetLocalVar(stackIndex(MOD))) ); Stmt block = new Block( stmts.toArray(new Stmt[0]), stackStart, symbolsSize() ); - FnDef fnDef = newFnDef(0,block); + FnDef fnDef = newFnDef(block); return fnDef; } private Stmt parseDef() throws ParseException { - int start = parser.begin(); + parser.begin(); if( !parser.match("{define:") ) return parser.failure(null); String name = parseName(); @@ -192,12 +180,12 @@ InlineSpaces(); spaces = parser.textFrom(startSpaces); } - Expr table = new GetLocalVar(null,stackIndex(MOD)); - Settable fnName = new SetTableEntry(se(start),table,new ConstExpr(null,name)); + Expr table = new GetLocalVar(stackIndex(MOD)); + Settable fnName = new SetTableEntry(table,new ConstExpr(name)); frame = new Frame(frame); addSymbol(ENV); Stmt block = parseBody("define:"+name,spaces,indent); - FnDef fnDef = newFnDef(start,block); + FnDef fnDef = newFnDef(block); frame = frame.parent; Stmt rtn = new SetStmt(fnName,fnDef); return parser.success(rtn); @@ -210,7 +198,7 @@ { addSymbol(INDENT); final Expr env = env(); - Expr exp = new ExprImpl(se(start,"indent")) { + Expr exp = new ExprImpl() { @Override public Object eval(LuanStateImpl luan) throws LuanException { Object obj = env.eval(luan); if( !(obj instanceof LuanTable) ) @@ -291,22 +279,22 @@ List<Expressions> args = new ArrayList<Expressions>(); if( start < end ) { String text = parser.text.substring(start,end); - args.add( new ConstExpr(null,text) ); + args.add( new ConstExpr(text) ); } if( indent ) { - args.add( new GetLocalVar(null,stackIndex(INDENT)) ); + args.add( new GetLocalVar(stackIndex(INDENT)) ); } if( !args.isEmpty() ) { - Expr io = new GetUpVar(null,upValueIndex(IO)); - Expr stdoutExp = new IndexExpr( se(start,"stdout"), io, new ConstExpr(null,"stdout") ); - Expr writeExp = new IndexExpr( se(start,"write"), stdoutExp, new ConstExpr(null,"write") ); - FnCall writeCall = new FnCall( se(start), writeExp, ExpList.build(args) ); + Expr io = new GetUpVar(upValueIndex(IO)); + Expr stdoutExp = new IndexExpr( io, new ConstExpr("stdout") ); + Expr writeExp = new IndexExpr( stdoutExp, new ConstExpr("write") ); + FnCall writeCall = new FnCall( writeExp, ExpList.build(args) ); stmts.add( new ExpressionsStmt(writeCall) ); } } private Stmt parseBlock(String spaces,boolean afterIndent) throws ParseException { - int start = parser.begin(); + parser.begin(); String tagSpaces = null; if( afterIndent ) { tagSpaces = spaces; @@ -340,21 +328,21 @@ frame = new Frame(frame); addSymbol(ENV); Stmt block = parseBody("block:"+name,spaces,false); - FnDef fnDef = newFnDef(start,block); + FnDef fnDef = newFnDef(block); frame = frame.parent; // String rtn = "<% env." + tag.name + "(" + (tag.attrs.isEmpty() ? "nil" : table(tag.attrs)) + ",env,function(env) %>" + block + "<% end) %>"; Expr env = env(); - Expr fn = new IndexExpr( se(start,"block:"+name), env, new ConstExpr(null,name) ); + Expr fn = new IndexExpr( env, new ConstExpr(name) ); List<Expressions> args = new ArrayList<Expressions>(); args.add( env ); args.add( fnDef ); - FnCall fnCall = new FnCall( se(start), fn, ExpList.build(args) ); + FnCall fnCall = new FnCall( fn, ExpList.build(args) ); Stmt rtn = new ExpressionsStmt(fnCall); return parser.success(rtn); } private Stmt parseSimpleTag(String spaces) throws ParseException { - int start = parser.begin(); + parser.begin(); if( !parser.match('{') ) return parser.failure(null); String name = parseName(); @@ -364,12 +352,12 @@ return parser.failure(null); // rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>"; Expr env = env(); - Expr fn = new IndexExpr( se(start,name), env, new ConstExpr(null,name) ); + Expr fn = new IndexExpr( env, new ConstExpr(name) ); if( spaces!=null && spaces.length() > 0 ) { final Expr oldEnv = env; - final Expr oldIndentExpr = new GetLocalVar(null,stackIndex(INDENT)); + final Expr oldIndentExpr = new GetLocalVar(stackIndex(INDENT)); final String addSpaces = spaces; - env = new ExprImpl(se(start,"indent_env")) { + env = new ExprImpl() { @Override public Object eval(LuanStateImpl luan) throws LuanException { LuanTable mt = new LuanTable(); mt.rawPut("__index",oldEnv.eval(luan)); @@ -382,7 +370,7 @@ } }; } - FnCall fnCall = new FnCall( se(start), fn, env ); + FnCall fnCall = new FnCall( fn, env ); Stmt rtn = new ExpressionsStmt(fnCall); return parser.success(rtn); }
--- a/core/src/luan/impl/UnaryOpExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/UnaryOpExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,13 +1,10 @@ package luan.impl; -import luan.LuanElement; - abstract class UnaryOpExpr extends CodeImpl implements Expr { final Expr op; - UnaryOpExpr(LuanElement se,Expr op) { - super(se); + UnaryOpExpr(Expr op) { this.op = op; } }
--- a/core/src/luan/impl/UnmExpr.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/UnmExpr.java Tue Mar 29 18:09:51 2016 -0600 @@ -3,32 +3,26 @@ import luan.Luan; import luan.LuanFunction; import luan.LuanException; -import luan.LuanElement; import luan.LuanTable; // unary minus final class UnmExpr extends UnaryOpExpr { - UnmExpr(LuanElement el,Expr op) { - super(el,op); + UnmExpr(Expr op) { + super(op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o = op.eval(luan); if( o instanceof Number ) return -((Number)o).doubleValue(); - luan.push(el,null); - try { - if( o instanceof LuanTable ) { - LuanFunction fn = luan.getHandlerFunction("__unm",(LuanTable)o); - if( fn != null ) { - return Luan.first(fn.call(luan,new Object[]{o})); - } + if( o instanceof LuanTable ) { + LuanFunction fn = luan.getHandlerFunction("__unm",(LuanTable)o); + if( fn != null ) { + return Luan.first(fn.call(luan,new Object[]{o})); } - throw new LuanException(luan,"attempt to perform arithmetic on a "+Luan.type(o)+" value"); - } finally { - luan.pop(); } + throw new LuanException(luan,"attempt to perform arithmetic on a "+Luan.type(o)+" value"); } }
--- a/core/src/luan/impl/VarArgs.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/VarArgs.java Tue Mar 29 18:09:51 2016 -0600 @@ -1,14 +1,8 @@ package luan.impl; -import luan.LuanElement; - final class VarArgs extends CodeImpl implements Expressions { - VarArgs(LuanElement se) { - super(se); - } - @Override public Object[] eval(LuanStateImpl luan) { return luan.varArgs(); }
--- a/core/src/luan/impl/WhileStmt.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/impl/WhileStmt.java Tue Mar 29 18:09:51 2016 -0600 @@ -2,22 +2,20 @@ import luan.Luan; import luan.LuanException; -import luan.LuanElement; final class WhileStmt extends CodeImpl implements Stmt { private final Expr cnd; private final Stmt doStmt; - WhileStmt(LuanElement el,Expr cnd,Stmt doStmt) { - super(el); + WhileStmt(Expr cnd,Stmt doStmt) { this.cnd = cnd; this.doStmt = doStmt; } @Override public void eval(LuanStateImpl luan) throws LuanException { try { - while( luan.checkBoolean( cnd.eval(luan), el ) ) { + while( luan.checkBoolean( cnd.eval(luan) ) ) { doStmt.eval(luan); } } catch(BreakException e) {}
--- a/core/src/luan/modules/BasicLuan.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/modules/BasicLuan.java Tue Mar 29 18:09:51 2016 -0600 @@ -13,8 +13,6 @@ import luan.LuanFunction; import luan.LuanJavaFunction; import luan.LuanException; -import luan.LuanSource; -import luan.LuanElement; import luan.LuanMethod; import luan.LuanMeta; import luan.impl.LuanCompiler; @@ -32,7 +30,7 @@ { if( allowExpr==null ) allowExpr = false; - return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr); + return LuanCompiler.compile(luan,sourceName,text,env,allowExpr); } public static LuanFunction load_theme(LuanState luan,String text,String sourceName) @@ -40,7 +38,7 @@ { if( sourceName==null ) sourceName = "THEME"; - return ThemeParser.compile(luan,new LuanSource(sourceName,text)); + return ThemeParser.compile(luan,sourceName,text); } public static LuanFunction load_file(LuanState luan,String fileName,Boolean addExtension) throws LuanException {
--- a/core/src/luan/modules/JavaLuan.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/modules/JavaLuan.java Tue Mar 29 18:09:51 2016 -0600 @@ -22,13 +22,12 @@ import luan.LuanException; import luan.LuanFunction; import luan.LuanJavaFunction; -import luan.LuanElement; public final class JavaLuan { public static void java(LuanState luan) throws LuanException { - check(luan,luan.currentSource().name); + check(luan,"fix later"); luan.setJava(); } @@ -110,7 +109,7 @@ //System.out.println("invalid member '"+key+"' for java object: "+obj); if( canReturnFail ) return FAIL; - throw new LuanException(luan, "invalid index for java "+cls+" in '"+luan.context()+"'" ); + throw new LuanException(luan, "invalid index for java "+cls ); } private static Object member(Object obj,List<Member> members) throws LuanException { @@ -177,7 +176,7 @@ } } } - throw new LuanException(luan, "invalid index for java "+cls+" in '"+luan.context()+"'" ); + throw new LuanException(luan, "invalid index for java "+cls ); } private static void setMember(Object obj,List<Member> members,Object value) {
--- a/core/src/luan/modules/PackageLuan.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/modules/PackageLuan.java Tue Mar 29 18:09:51 2016 -0600 @@ -8,7 +8,6 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanJavaFunction; -import luan.LuanElement; import luan.LuanException;
--- a/core/src/luan/modules/StringLuan.java Tue Mar 29 13:53:01 2016 -0600 +++ b/core/src/luan/modules/StringLuan.java Tue Mar 29 18:09:51 2016 -0600 @@ -7,7 +7,6 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanJavaFunction; -import luan.LuanElement; import luan.LuanException; import luan.LuanMethod;
--- a/http/src/luan/modules/http/HttpServicer.java Tue Mar 29 13:53:01 2016 -0600 +++ b/http/src/luan/modules/http/HttpServicer.java Tue Mar 29 18:09:51 2016 -0600 @@ -26,7 +26,6 @@ import luan.Luan; import luan.LuanState; import luan.LuanFunction; -import luan.LuanElement; import luan.LuanException; import luan.LuanTable; import luan.LuanMeta;