changeset 13:3b22ffbdb83a

minor git-svn-id: https://luan-java.googlecode.com/svn/trunk@14 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 Nov 2012 13:04:03 +0000
parents 9cea1aea5eef
children 2ddf85634d20
files src/luan/interp/ExpList.java src/luan/interp/Expressions.java src/luan/interp/ExpressionsExpr.java src/luan/interp/FnCall.java src/luan/interp/SetStmt.java src/luan/lib/BasicLib.java
diffstat 6 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/interp/ExpList.java
--- a/src/luan/interp/ExpList.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/interp/ExpList.java	Fri Nov 23 13:04:03 2012 +0000
@@ -68,9 +68,11 @@
 		}
 	}
 
+	private static final Object[] EMPTY = new Object[0];
+
 	static final Expressions emptyExpList = new Expressions() {
-		@Override public List eval(LuaState lua) {
-			return Collections.emptyList();
+		@Override public Object[] eval(LuaState lua) {
+			return EMPTY;
 		}
 	};
 
@@ -81,8 +83,8 @@
 			this.expr = expr;
 		}
 
-		@Override public List eval(LuaState lua) throws LuaException {
-			return Collections.singletonList( expr.eval(lua) );
+		@Override public Object[] eval(LuaState lua) throws LuaException {
+			return new Object[]{expr.eval(lua)};
 		}
 	}
 
@@ -92,11 +94,11 @@
 		this.adders = adders;
 	}
 
-	@Override public List eval(LuaState lua) throws LuaException {
+	@Override public Object[] eval(LuaState lua) throws LuaException {
 		List<Object> list = new ArrayList<Object>();
 		for( Adder adder : adders ) {
 			adder.addTo(lua,list);
 		}
-		return list;
+		return list.toArray();
 	}
 }
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/interp/Expressions.java
--- a/src/luan/interp/Expressions.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/interp/Expressions.java	Fri Nov 23 13:04:03 2012 +0000
@@ -1,10 +1,9 @@
 package luan.interp;
 
-import java.util.List;
 import luan.LuaException;
 import luan.LuaState;
 
 
 public interface Expressions {
-	public List eval(LuaState lua) throws LuaException;
+	public Object[] eval(LuaState lua) throws LuaException;
 }
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/interp/ExpressionsExpr.java
--- a/src/luan/interp/ExpressionsExpr.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/interp/ExpressionsExpr.java	Fri Nov 23 13:04:03 2012 +0000
@@ -14,7 +14,7 @@
 	}
 
 	@Override public Object eval(LuaState lua) throws LuaException {
-		List list = expressions.eval(lua);
-		return list.isEmpty() ? null : list.get(0);
+		Object[] a = expressions.eval(lua);
+		return a.length==0 ? null : a[0];
 	}
 }
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/interp/FnCall.java
--- a/src/luan/interp/FnCall.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/interp/FnCall.java	Fri Nov 23 13:04:03 2012 +0000
@@ -1,7 +1,5 @@
 package luan.interp;
 
-import java.util.Arrays;
-import java.util.List;
 import luan.Lua;
 import luan.LuaFunction;
 import luan.LuaException;
@@ -17,8 +15,8 @@
 		this.args = args;
 	}
 
-	@Override public List eval(LuaState lua) throws LuaException {
+	@Override public Object[] eval(LuaState lua) throws LuaException {
 		LuaFunction fn = Lua.checkFunction( fnExpr.eval(lua) );
-		return Arrays.asList( fn.call( lua, args.eval(lua).toArray() ) );
+		return fn.call( lua, args.eval(lua) );
 	}
 }
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/interp/SetStmt.java
--- a/src/luan/interp/SetStmt.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/interp/SetStmt.java	Fri Nov 23 13:04:03 2012 +0000
@@ -28,8 +28,7 @@
 	}
 
 	@Override public void eval(LuaState lua) throws LuaException {
-		List vals = expressions.eval(lua);
-		int n = vals.size();
+		final Object[] vals = expressions.eval(lua);
 		for( int i=0; i<vars.length; i++ ) {
 			Var var = vars[i];
 			Object t = var.table.eval(lua);
@@ -37,7 +36,7 @@
 				throw new LuaException( "attempt to index a " + Lua.type(t) + " value" );
 			LuaTable tbl = (LuaTable)t;
 			Object key = var.key.eval(lua);
-			Object val = i < n ? vals.get(i) : null;
+			Object val = i < vals.length ? vals[i] : null;
 			tbl.set(key,val);
 		}
 	}
diff -r 9cea1aea5eef -r 3b22ffbdb83a src/luan/lib/BasicLib.java
--- a/src/luan/lib/BasicLib.java	Fri Nov 23 10:37:40 2012 +0000
+++ b/src/luan/lib/BasicLib.java	Fri Nov 23 13:04:03 2012 +0000
@@ -57,7 +57,7 @@
 			final Expressions expressions = (Expressions)resultValue;
 			return new LuaFunction() {
 				public Object[] call(LuaState lua,Object... args) throws LuaException {
-					return expressions.eval(lua).toArray();
+					return expressions.eval(lua);
 				}
 			};
 		}