changeset 574:6cc2f047019b

remove LuanState.call()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 13 Jul 2015 12:31:53 -0600
parents 894f991baac5
children 7c3ad6db8ac3
files core/src/luan/Luan.java core/src/luan/LuanBit.java core/src/luan/LuanFunction.java core/src/luan/LuanPropertyMeta.java core/src/luan/LuanState.java core/src/luan/modules/BasicLuan.java core/src/luan/modules/IoLuan.java core/src/luan/modules/JavaLuan.java core/src/luan/modules/PackageLuan.java core/src/luan/modules/PickleCon.java core/src/luan/modules/PickleServer.java core/src/luan/modules/StringLuan.java core/src/luan/modules/TableLuan.java core/src/luan/modules/ThreadLuan.java http/src/luan/modules/http/HttpServicer.java lucene/src/luan/modules/lucene/LuceneIndex.java
diffstat 16 files changed, 44 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/Luan.java
--- a/core/src/luan/Luan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/Luan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -9,7 +9,7 @@
 	public static void main(String[] args) throws LuanException {
 		LuanState luan = LuanState.newInstance();
 		LuanFunction standalone = (LuanFunction)BasicLuan.load_file(luan,"classpath:luan/cmd_line.luan",null);
-		luan.call(standalone,args);
+		standalone.call(luan,args);
 	}
 
 	public static Object first(Object obj) {
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/LuanBit.java
--- a/core/src/luan/LuanBit.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/LuanBit.java	Mon Jul 13 12:31:53 2015 -0600
@@ -31,19 +31,27 @@
 	}
 
 	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) );
+		push(fnName);
 		try {
 			return fn.call(luan,args);
 		} catch(StackOverflowError e) {
 			throw exception("stack overflow");
 		} finally {
-			stackTrace.remove(stackTrace.size()-1);
+			pop();
 		}
 	}
 
+	public void push(String fnName) {
+		if( el == null )  throw new RuntimeException();
+		List<StackTraceElement> stackTrace = luan.stackTrace;
+		stackTrace.add( new StackTraceElement(el,fnName) );
+	}
+
+	public void pop() {
+		List<StackTraceElement> stackTrace = luan.stackTrace;
+		stackTrace.remove(stackTrace.size()-1);
+	}
+
 	public String checkString(Object obj) throws LuanException {
 		if( obj instanceof String )
 			return (String)obj;
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/LuanFunction.java
--- a/core/src/luan/LuanFunction.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/LuanFunction.java	Mon Jul 13 12:31:53 2015 -0600
@@ -7,6 +7,10 @@
 
 	public static final Object[] NOTHING = new Object[0];
 
+	public final Object call(LuanState luan) throws LuanException {
+		return call(luan,NOTHING);
+	}
+
 	@Override public String toString() {
 		return "function: " + Integer.toHexString(hashCode());
 	}
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/LuanPropertyMeta.java
--- a/core/src/luan/LuanPropertyMeta.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/LuanPropertyMeta.java	Mon Jul 13 12:31:53 2015 -0600
@@ -28,7 +28,7 @@
 		if( !(obj instanceof LuanFunction) )
 			throw luan.exception("get for '"+key+"' isn't a function");
 		LuanFunction fn = (LuanFunction)obj;
-		return luan.call(fn);
+		return fn.call(luan);
 	}
 
 	@Override protected Iterator keys(final LuanTable tbl) {
@@ -61,7 +61,7 @@
 		if( !(obj instanceof LuanFunction) )
 			throw luan.exception("set for '"+key+"' isn't a function");
 		LuanFunction fn = (LuanFunction)obj;
-		luan.call(fn,new Object[]{value});
+		fn.call(luan,new Object[]{value});
 	}
 
 	@Override public LuanTable newMetatable() {
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/LuanState.java
--- a/core/src/luan/LuanState.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/LuanState.java	Mon Jul 13 12:31:53 2015 -0600
@@ -60,7 +60,7 @@
 
 	public final Object eval(String cmd,LuanTable env) throws LuanException {
 		LuanFunction fn = BasicLuan.load(this,cmd,"eval",env,true);
-		return call(fn);
+		return fn.call(this);
 	}
 
 	public final LuanBit bit(LuanElement el) {
@@ -75,22 +75,6 @@
 		return JAVA.exception(msg);
 	}
 
-	public Object call(LuanFunction fn) throws LuanException {
-		return call(fn,null,LuanFunction.NOTHING);
-	}
-
-	public Object call(LuanFunction fn,String fnName) throws LuanException {
-		return call(fn,fnName,LuanFunction.NOTHING);
-	}
-
-	public Object call(LuanFunction fn,Object[] args) throws LuanException {
-		return call(fn,null,args);
-	}
-
-	public Object call(LuanFunction fn,String fnName,Object[] args) throws LuanException {
-		return JAVA.call(fn,fnName,args);
-	}
-
 	public Boolean checkBoolean(Object obj) throws LuanException {
 		return JAVA.checkBoolean(obj);
 	}
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/BasicLuan.java
--- a/core/src/luan/modules/BasicLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -204,20 +204,20 @@
 			finallyFn = (LuanFunction)obj;
 		}
 		try {
-			return luan.call(tryFn);
+			return tryFn.call(luan);
 		} catch(LuanException e) {
 			if( catchFn == null )
 				throw e;
-			return luan.call(catchFn,new Object[]{e.table()});
+			return catchFn.call(luan,new Object[]{e.table()});
 		} finally {
 			if( finallyFn != null )
-				luan.call(finallyFn);
+				finallyFn.call(luan);
 		}
 	}
 
 	@LuanMethod public static Object[] pcall(LuanState luan,LuanFunction f,Object... args) {
 		try {
-			Object[] r = Luan.array(luan.call(f,args));
+			Object[] r = Luan.array(f.call(luan,args));
 			Object[] rtn = new Object[r.length+1];
 			rtn[0] = true;
 			for( int i=0; i<r.length; i++ ) {
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/IoLuan.java
--- a/core/src/luan/modules/IoLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/IoLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -592,7 +592,7 @@
 		LuanFunction opener = (LuanFunction)schemes.get(luan.JAVA,scheme);
 		if( opener == null )
 			throw luan.exception( "invalid scheme '"+scheme+"' in '"+name+"'" );
-		return (LuanTable)Luan.first(luan.call(opener,"<open \""+name+"\">",new Object[]{location,addExtension}));
+		return (LuanTable)Luan.first(opener.call(luan,new Object[]{location,addExtension}));
 	}
 
 	public static final class LuanSocket extends LuanIO {
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/JavaLuan.java
--- a/core/src/luan/modules/JavaLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/JavaLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -335,7 +335,7 @@
 						if( fnObj == null )
 							throw new NullPointerException("luan_proxy couldn't find method '"+name+"'");
 						LuanFunction fn = luan.checkFunction(fnObj);
-						return Luan.first(luan.call(fn,name,args));
+						return Luan.first(fn.call(luan,args));
 					}
 				}
 			);
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/PackageLuan.java
--- a/core/src/luan/modules/PackageLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/PackageLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -51,7 +51,7 @@
 					return null;
 				LuanFunction loader = BasicLuan.load(luan,src,modName,null,false);
 				mod = Luan.first(
-					luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})
+					loader.call(luan,new Object[]{modName})
 				);
 				if( mod == null ) {
 					mod = loaded.rawGet(modName);
@@ -70,11 +70,11 @@
 		if( t == null )
 			return null;
 		LuanFunction existsFn = (LuanFunction)t.get(luan.JAVA,"exists");
-		boolean exists = (Boolean)Luan.first(luan.call(existsFn));
+		boolean exists = (Boolean)Luan.first(existsFn.call(luan));
 		if( !exists )
 			return null;
 		LuanFunction reader = (LuanFunction)t.get(luan.JAVA,"read_text");
-		return (String)Luan.first(luan.call(reader));
+		return (String)Luan.first(reader.call(luan));
 	}
 
 }
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/PickleCon.java
--- a/core/src/luan/modules/PickleCon.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/PickleCon.java	Mon Jul 13 12:31:53 2015 -0600
@@ -60,7 +60,7 @@
 		try {
 			src = readString();
 			LuanFunction fn = BasicLuan.load(luan,src,"pickle-reader",env,false);
-			return luan.call(fn);
+			return fn.call(luan);
 		} finally {
 			env.rawPut("_binaries",null);
 			env.rawPut("_read_binary",null);
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/PickleServer.java
--- a/core/src/luan/modules/PickleServer.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/PickleServer.java	Mon Jul 13 12:31:53 2015 -0600
@@ -104,7 +104,7 @@
 		}
 		PickleClient pc = new PickleClient(con);
 		try {
-			con.luan.call(fn,new Object[]{pc.table()});
+			fn.call(con.luan,new Object[]{pc.table()});
 		} finally {
 			try {
 				pc.call( "_unreverse_pickle()\n" );
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/StringLuan.java
--- a/core/src/luan/modules/StringLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -193,7 +193,7 @@
 						args[j] = m.group(j+1);
 					}
 				}
-				Object val = Luan.first( luan.call(fn,"repl-arg",args) );
+				Object val = Luan.first( fn.call(luan,args) );
 				if( val != null ) {
 					String replacement = luan.JAVA.toString(val);
 					m.appendReplacement(sb,replacement);
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/TableLuan.java
--- a/core/src/luan/modules/TableLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/TableLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -66,7 +66,7 @@
 			lt = new LessThan() {
 				public boolean isLessThan(Object o1,Object o2) {
 					try {
-						return luan.checkBoolean(Luan.first(luan.call(comp,"comp-arg",new Object[]{o1,o2})));
+						return luan.checkBoolean(Luan.first(comp.call(luan,new Object[]{o1,o2})));
 					} catch(LuanException e) {
 						throw new LuanRuntimeException(e);
 					}
diff -r 894f991baac5 -r 6cc2f047019b core/src/luan/modules/ThreadLuan.java
--- a/core/src/luan/modules/ThreadLuan.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/core/src/luan/modules/ThreadLuan.java	Mon Jul 13 12:31:53 2015 -0600
@@ -20,7 +20,7 @@
 		final Object[] newArgs = cloner.deepClone(args);
 		exec.execute(new Runnable(){public void run() {
 			try {
-				newLuan.call(newFn,"<forked>",newArgs);
+				newFn.call(newLuan,newArgs);
 			} catch(LuanException e) {
 				e.printStackTrace();
 			}
diff -r 894f991baac5 -r 6cc2f047019b http/src/luan/modules/http/HttpServicer.java
--- a/http/src/luan/modules/http/HttpServicer.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/http/src/luan/modules/http/HttpServicer.java	Mon Jul 13 12:31:53 2015 -0600
@@ -73,7 +73,8 @@
 		LuanTable module = (LuanTable)PackageLuan.require(luan,"luan:http/Http");
 
 		// request
-		LuanTable requestTbl = (LuanTable)luan.call( (LuanFunction)module.rawGet("new_request") );
+		LuanFunction newRequestFn = (LuanFunction)module.rawGet("new_request");
+		LuanTable requestTbl = (LuanTable)newRequestFn.call(luan);
 		module.rawPut("request",requestTbl);
 		requestTbl.rawPut("java",request);
 		requestTbl.rawPut("method",request.getMethod());
@@ -151,10 +152,11 @@
 		// response
 		LuanTable responseTbl = new LuanTable();
 		responseTbl.rawPut("java",response);
-		luan.call( (LuanFunction)module.rawGet("new_response"), new Object[]{responseTbl} );
+		LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response");
+		newResponseFn.call( luan, new Object[]{responseTbl} );
 		module.rawPut("response",responseTbl);
 
-		luan.call(fn,"<http>");
+		fn.call(luan);
 		return true;
 	}
 
diff -r 894f991baac5 -r 6cc2f047019b lucene/src/luan/modules/lucene/LuceneIndex.java
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Sun Jul 12 23:04:47 2015 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Mon Jul 13 12:31:53 2015 -0600
@@ -158,7 +158,7 @@
 		boolean commit = !writeLock.isHeldByCurrentThread();
 		writeLock.lock();
 		try {
-			luan.call(fn);
+			fn.call(luan);
 			if(commit) writer.commit();
 		} finally {
 			writeLock.unlock();
@@ -315,7 +315,7 @@
 					@Override public void collect(int doc) {
 						try {
 							docFn.docID = docBase + doc;
-							luan.call(fn,new Object[]{++i,docFn});
+							fn.call(luan,new Object[]{++i,docFn});
 						} catch(LuanException e) {
 							throw new LuanRuntimeException(e);
 						}
@@ -339,7 +339,7 @@
 			DocFn docFn = new DocFn(searcher);
 			for( int i=0; i<scoreDocs.length; i++ ) {
 				docFn.docID = scoreDocs[i].doc;
-				luan.call(fn,new Object[]{i+1,docFn});
+				fn.call(luan,new Object[]{i+1,docFn});
 			}
 			return td.totalHits;
 		} finally {
@@ -354,7 +354,7 @@
 		IndexSearcher searcher = openSearcher();
 		threadLocalSearcher.set(searcher);
 		try {
-			return luan.call(fn);
+			return fn.call(luan);
 		} finally {
 			threadLocalSearcher.set(null);
 			close(searcher);