| 18 | |
| 19 | |
| 20 | public final class Var extends ARef implements IFn, IRef, Settable, Serializable{ |
| 21 | |
| 22 | private static final long serialVersionUID = 8368961370796295279L; |
| 23 | |
| 24 | static class TBox{ |
| 25 | |
| 26 | volatile Object val; |
| 27 | final Thread thread; |
| 28 | |
| 29 | public TBox(Thread t, Object val){ |
| 30 | this.thread = t; |
| 31 | this.val = val; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | static public class Unbound extends AFn{ |
| 36 | final public Var v; |
| 37 | |
| 38 | public Unbound(Var v){ |
| 39 | this.v = v; |
| 40 | } |
| 41 | |
| 42 | public String toString(){ |
| 43 | return "Unbound: " + v; |
| 44 | } |
| 45 | |
| 46 | public Object throwArity(int n){ |
| 47 | throw new IllegalStateException("Attempting to call unbound fn: " + v); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static class Frame{ |
| 52 | final static Frame TOP = new Frame(PersistentHashMap.EMPTY, null); |
| 53 | //Var->TBox |
| 54 | Associative bindings; |
| 55 | //Var->val |
| 56 | // Associative frameBindings; |
| 57 | Frame prev; |
| 58 | |
| 59 | public Frame(Associative bindings, Frame prev){ |
| 60 | // this.frameBindings = frameBindings; |
| 61 | this.bindings = bindings; |
| 62 | this.prev = prev; |
| 63 | } |
| 64 | |
| 65 | protected Object clone() { |
| 66 | return new Frame(this.bindings, null); |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |
| 71 | static final ThreadLocal<Frame> dvals = new ThreadLocal<Frame>(){ |
| 72 | |
| 73 | protected Frame initialValue(){ |
| 74 | return Frame.TOP; |
| 75 | } |
| 76 | }; |
| 77 | |