Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
76:97b03fc807ad | 77:4bf3d0c0b6b9 |
---|---|
7 import luan.LuanTable; | 7 import luan.LuanTable; |
8 import luan.LuanFunction; | 8 import luan.LuanFunction; |
9 import luan.MetatableGetter; | 9 import luan.MetatableGetter; |
10 import luan.LuanException; | 10 import luan.LuanException; |
11 import luan.LuanElement; | 11 import luan.LuanElement; |
12 import luan.DeepCloner; | |
12 | 13 |
13 | 14 |
14 final class LuanStateImpl extends LuanState { | 15 final class LuanStateImpl extends LuanState { |
15 | |
16 final Object arithmetic(LuanElement el,String op,Object o1,Object o2) throws LuanException { | |
17 LuanFunction fn = getBinHandler(el,op,o1,o2); | |
18 if( fn != null ) | |
19 return Luan.first(call(fn,el,op,o1,o2)); | |
20 String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2); | |
21 throw new LuanException(this,el,"attempt to perform arithmetic on a "+type+" value"); | |
22 } | |
23 | |
24 | 16 |
25 private static class Frame { | 17 private static class Frame { |
26 final Frame previousFrame; | 18 final Frame previousFrame; |
27 final Closure closure; | 19 final Closure closure; |
28 final Object[] stack; | 20 final Object[] stack; |
62 | 54 |
63 private Frame frame = null; | 55 private Frame frame = null; |
64 Object[] returnValues = LuanFunction.EMPTY_RTN; | 56 Object[] returnValues = LuanFunction.EMPTY_RTN; |
65 Closure tailFn; | 57 Closure tailFn; |
66 | 58 |
59 public LuanStateImpl() {} | |
60 | |
61 private LuanStateImpl(LuanStateImpl luan) { | |
62 super(luan); | |
63 } | |
64 | |
65 @Override public LuanState shallowClone() { | |
66 if( frame != null ) | |
67 throw new IllegalStateException("frame isn't null"); | |
68 return new LuanStateImpl(this); | |
69 } | |
70 | |
67 // returns stack | 71 // returns stack |
68 Object[] newFrame(Closure closure, int stackSize, Object[] varArgs) { | 72 Object[] newFrame(Closure closure, int stackSize, Object[] varArgs) { |
69 frame = new Frame(frame,closure,stackSize,varArgs); | 73 frame = new Frame(frame,closure,stackSize,varArgs); |
70 return frame.stack; | 74 return frame.stack; |
71 } | 75 } |
97 } | 101 } |
98 | 102 |
99 UpValue getUpValue(int index) { | 103 UpValue getUpValue(int index) { |
100 return frame.getUpValue(index); | 104 return frame.getUpValue(index); |
101 } | 105 } |
106 | |
107 | |
108 final Object arithmetic(LuanElement el,String op,Object o1,Object o2) throws LuanException { | |
109 LuanFunction fn = getBinHandler(el,op,o1,o2); | |
110 if( fn != null ) | |
111 return Luan.first(call(fn,el,op,o1,o2)); | |
112 String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2); | |
113 throw new LuanException(this,el,"attempt to perform arithmetic on a "+type+" value"); | |
114 } | |
115 | |
102 } | 116 } |