Mercurial Hosting > luan
diff src/luan/LuanClosure.java @ 1578:c922446f53aa
immutable threading
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 08 Feb 2021 14:16:19 -0700 |
parents | 8fbcc4747091 |
children |
line wrap: on
line diff
--- a/src/luan/LuanClosure.java Sun Jan 31 16:04:39 2021 -0700 +++ b/src/luan/LuanClosure.java Mon Feb 08 14:16:19 2021 -0700 @@ -3,12 +3,11 @@ import luan.impl.Pointer; -public abstract class LuanClosure extends LuanFunction implements LuanCloneable, Cloneable { +public abstract class LuanClosure extends LuanFunction implements LuanMutable { public Pointer[] upValues; public boolean javaOk; public final String sourceName; - private LuanCloner cloner; - private Luan luan; + private boolean immutable = false; public LuanClosure(Pointer[] upValues,boolean javaOk,String sourceName) throws LuanException { this.upValues = upValues; @@ -16,55 +15,18 @@ this.sourceName = sourceName; } - @Override public final LuanClosure shallowClone() { - check(); - try { - return (LuanClosure)clone(); - } catch(CloneNotSupportedException e) { - throw new RuntimeException(e); - } - } - - private void check() { - if( cloner != null ) { - completeClone(this,cloner); - cloner = null; - } + @Override public final boolean isImmutable() { + return immutable; } - private void checkLuan(Luan luan) { - check(); - if( this.luan==null ) { - this.luan = luan; - } else if( this.luan != luan ) { - throw new RuntimeException("wrong luan"); - } - } - - @Override public final void deepenClone(LuanCloneable dc,LuanCloner cloner) { - LuanClosure clone = (LuanClosure)dc; - switch( cloner.type ) { - case COMPLETE: - completeClone(clone,cloner); + @Override public final void makeImmutable() { + if(immutable) return; - case INCREMENTAL: - clone.cloner = cloner; - return; - } - } - - private void completeClone(LuanClosure dc,LuanCloner cloner) { - LuanClosure clone = (LuanClosure)dc; - clone.upValues = (Pointer[])cloner.clone(upValues); - clone.luan = (Luan)cloner.clone(luan); - } - - @Override public final void makeImmutable(LuanImmutabler immutabler) throws LuanException { - immutabler.makeImmutable(upValues); + immutable = true; + LuanMutable.makeImmutable(upValues); } @Override public final Object call(Luan luan,Object... args) throws LuanException { - check(); luan.push(this); try { return doCall(luan,args); @@ -75,7 +37,7 @@ } } - @Override public String toString() { + @Override public final String toString() { return super.toString()+"="+sourceName; }