Mercurial Hosting > luan
comparison src/luan/interp/Closure.java @ 78:7c08b611125d
better deep cloning
git-svn-id: https://luan-java.googlecode.com/svn/trunk@79 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 15 Feb 2013 22:29:16 +0000 |
parents | 4bf3d0c0b6b9 |
children | 6db8f286fa6c |
comparison
equal
deleted
inserted
replaced
77:4bf3d0c0b6b9 | 78:7c08b611125d |
---|---|
8 import luan.DeepCloneable; | 8 import luan.DeepCloneable; |
9 | 9 |
10 | 10 |
11 final class Closure extends LuanFunction implements DeepCloneable<Closure> { | 11 final class Closure extends LuanFunction implements DeepCloneable<Closure> { |
12 private final Chunk chunk; | 12 private final Chunk chunk; |
13 final UpValue[] upValues; | 13 private UpValue[] upValues; |
14 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; | 14 private final static UpValue[] NO_UP_VALUES = new UpValue[0]; |
15 | 15 |
16 Closure(LuanStateImpl luan,Chunk chunk) { | 16 Closure(LuanStateImpl luan,Chunk chunk) { |
17 this.chunk = chunk; | 17 this.chunk = chunk; |
18 UpValue.Getter[] upValueGetters = chunk.upValueGetters; | 18 UpValue.Getter[] upValueGetters = chunk.upValueGetters; |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 private Closure(Closure c) { | 29 private Closure(Closure c) { |
30 this.chunk = c.chunk; | 30 this.chunk = c.chunk; |
31 this.upValues = c.upValues==NO_UP_VALUES ? NO_UP_VALUES : c.upValues.clone(); | |
32 } | 31 } |
33 | 32 |
34 @Override public Closure shallowClone() { | 33 @Override public Closure shallowClone() { |
35 return new Closure(this); | 34 return new Closure(this); |
36 } | 35 } |
37 | 36 |
38 @Override public void deepenClone(Closure clone,DeepCloner cloner) { | 37 @Override public void deepenClone(Closure clone,DeepCloner cloner) { |
39 cloner.deepenClone(clone.upValues); | 38 clone.upValues = cloner.deepClone(upValues); |
39 } | |
40 | |
41 UpValue[] upValues() { | |
42 return upValues; | |
40 } | 43 } |
41 | 44 |
42 public Object[] call(LuanState luan,Object[] args) throws LuanException { | 45 public Object[] call(LuanState luan,Object[] args) throws LuanException { |
43 return call(this,(LuanStateImpl)luan,args); | 46 return call(this,(LuanStateImpl)luan,args); |
44 } | 47 } |