Mercurial Hosting > luan
diff src/luan/impl/Pointer.java @ 1561:e1a13e707bf3
start immutable
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 20:24:09 -0700 |
parents | 6a7c6879158d |
children | c922446f53aa |
line wrap: on
line diff
--- a/src/luan/impl/Pointer.java Thu Oct 22 00:33:04 2020 -0600 +++ b/src/luan/impl/Pointer.java Thu Nov 05 20:24:09 2020 -0700 @@ -2,10 +2,13 @@ import luan.LuanCloneable; import luan.LuanCloner; +import luan.LuanImmutabler; +import luan.LuanException; public final class Pointer implements LuanCloneable { - public Object o; + private Object o; + private boolean immutable = false; public Pointer() {} @@ -20,4 +23,19 @@ @Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) { ((Pointer)clone).o = cloner.get(o); } + + @Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException { + immutabler.makeImmutable(o); + immutable = true; + } + + public Object get() { + return o; + } + + public void set(Object o) throws LuanException { + if( immutable ) + throw new LuanException("variable is immutable"); + this.o = o; + } }