Mercurial Hosting > luan
changeset 194:08df375e2e5f
remove EnvGetter
git-svn-id: https://luan-java.googlecode.com/svn/trunk@195 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 02 Jul 2014 04:52:25 +0000 |
parents | 66ed8886abc0 |
children | 24ede40ee0aa |
files | core/src/luan/impl/LuanCompiler.java core/src/luan/impl/LuanStateImpl.java core/src/luan/impl/UpValue.java |
diffstat | 3 files changed, 5 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
diff -r 66ed8886abc0 -r 08df375e2e5f core/src/luan/impl/LuanCompiler.java --- a/core/src/luan/impl/LuanCompiler.java Wed Jul 02 03:27:35 2014 +0000 +++ b/core/src/luan/impl/LuanCompiler.java Wed Jul 02 04:52:25 2014 +0000 @@ -13,7 +13,10 @@ private LuanCompiler() {} // never public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env,boolean allowExpr) throws LuanException { - UpValue.Getter envGetter = env!=null ? new UpValue.ValueGetter(env) : new UpValue.EnvGetter(); + boolean passedEnv = env != null; + if( !passedEnv ) + env = new LuanTable(); + UpValue.Getter envGetter = new UpValue.ValueGetter(env); LuanParser parser = new LuanParser(src,envGetter); for( Map.Entry<Object,Object> entry : luan.global() ) { Object key = entry.getKey(); @@ -21,7 +24,7 @@ parser.addVar( (String)key, entry.getValue() ); } FnDef fnDef = parse(luan,parser,allowExpr); - if( env != null ) + if( passedEnv ) return new Closure((LuanStateImpl)luan,fnDef); final Closure c = new Closure((LuanStateImpl)luan,fnDef); return new LuanFunction() {
diff -r 66ed8886abc0 -r 08df375e2e5f core/src/luan/impl/LuanStateImpl.java --- a/core/src/luan/impl/LuanStateImpl.java Wed Jul 02 03:27:35 2014 +0000 +++ b/core/src/luan/impl/LuanStateImpl.java Wed Jul 02 04:52:25 2014 +0000 @@ -57,7 +57,6 @@ private Frame frame = null; Object returnValues; Closure tailFn; - Map<UpValue.EnvGetter,UpValue> envs = new HashMap<UpValue.EnvGetter,UpValue>(); LuanStateImpl() {} @@ -71,15 +70,6 @@ return new LuanStateImpl(this); } - @Override public void deepenClone(LuanState clone,DeepCloner cloner) { - super.deepenClone(clone,cloner); - LuanStateImpl cloneImpl = (LuanStateImpl)clone; - cloneImpl.envs = new HashMap<UpValue.EnvGetter,UpValue>(); - for( Map.Entry<UpValue.EnvGetter,UpValue> entry : envs.entrySet() ) { - cloneImpl.envs.put( entry.getKey(), cloner.deepClone(entry.getValue()) ); - } - } - // returns stack Object[] newFrame(Closure closure, int stackSize, Object[] varArgs) { returnValues = LuanFunction.NOTHING; @@ -118,16 +108,6 @@ return frame.getUpValue(index); } - UpValue getUpValue(UpValue.EnvGetter getter) throws LuanException { - UpValue uv = envs.get(getter); - if( uv == null ) { - LuanTable env = new LuanTable(); - uv = new UpValue(env); - envs.put(getter,uv); - } - return uv; - } - @Override public LuanTable currentEnvironment() { if( frame==null ) return null;
diff -r 66ed8886abc0 -r 08df375e2e5f core/src/luan/impl/UpValue.java --- a/core/src/luan/impl/UpValue.java Wed Jul 02 03:27:35 2014 +0000 +++ b/core/src/luan/impl/UpValue.java Wed Jul 02 04:52:25 2014 +0000 @@ -83,13 +83,6 @@ } } - static final class EnvGetter implements Getter { - - public UpValue get(LuanStateImpl luan) throws LuanException { - return luan.getUpValue(this); - } - } - static final class ValueGetter implements Getter { private final UpValue upValue;