diff src/luan/interp/LuanStateImpl.java @ 77:4bf3d0c0b6b9

make LuanState cloneable git-svn-id: https://luan-java.googlecode.com/svn/trunk@78 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 15 Feb 2013 09:55:17 +0000
parents 8ede219cd111
children 6db8f286fa6c
line wrap: on
line diff
--- a/src/luan/interp/LuanStateImpl.java	Fri Feb 15 04:52:16 2013 +0000
+++ b/src/luan/interp/LuanStateImpl.java	Fri Feb 15 09:55:17 2013 +0000
@@ -9,19 +9,11 @@
 import luan.MetatableGetter;
 import luan.LuanException;
 import luan.LuanElement;
+import luan.DeepCloner;
 
 
 final class LuanStateImpl extends LuanState {
 
-	final Object arithmetic(LuanElement el,String op,Object o1,Object o2) throws LuanException {
-		LuanFunction fn = getBinHandler(el,op,o1,o2);
-		if( fn != null )
-			return Luan.first(call(fn,el,op,o1,o2));
-		String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2);
-		throw new LuanException(this,el,"attempt to perform arithmetic on a "+type+" value");
-	}
-
-
 	private static class Frame {
 		final Frame previousFrame;
 		final Closure closure;
@@ -64,6 +56,18 @@
 	Object[] returnValues = LuanFunction.EMPTY_RTN;
 	Closure tailFn;
 
+	public LuanStateImpl() {}
+
+	private LuanStateImpl(LuanStateImpl luan) {
+		super(luan);
+	}
+
+	@Override public LuanState shallowClone() {
+		if( frame != null )
+			throw new IllegalStateException("frame isn't null");
+		return new LuanStateImpl(this);
+	}
+
 	// returns stack
 	Object[] newFrame(Closure closure, int stackSize, Object[] varArgs) {
 		frame = new Frame(frame,closure,stackSize,varArgs);
@@ -99,4 +103,14 @@
 	UpValue getUpValue(int index) {
 		return frame.getUpValue(index);
 	}
+
+
+	final Object arithmetic(LuanElement el,String op,Object o1,Object o2) throws LuanException {
+		LuanFunction fn = getBinHandler(el,op,o1,o2);
+		if( fn != null )
+			return Luan.first(call(fn,el,op,o1,o2));
+		String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2);
+		throw new LuanException(this,el,"attempt to perform arithmetic on a "+type+" value");
+	}
+
 }