diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-03-25 18:17:32 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-03-25 18:17:32 +0000 |
commit | 894a0c81075b8f4b64b7f890ab0c8522a7a9986a (patch) | |
tree | 455d8ae00bc1bf8f5dd04391e13516e60819d1c1 /src | |
parent | e54a1ff1ac0d02560e80aad460e77ac353efad49 (diff) |
baseline versions
Diffstat (limited to 'src')
-rw-r--r-- | src/org/clojure/runtime/Cons.java | 26 | ||||
-rw-r--r-- | src/org/clojure/runtime/Symbol.java | 16 | ||||
-rw-r--r-- | src/org/clojure/runtime/ThreadLocalData.java | 72 |
3 files changed, 114 insertions, 0 deletions
diff --git a/src/org/clojure/runtime/Cons.java b/src/org/clojure/runtime/Cons.java new file mode 100644 index 00000000..7b6bbc32 --- /dev/null +++ b/src/org/clojure/runtime/Cons.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Mar 25, 2006 11:01:29 AM */ + +package org.clojure.runtime; + +public class Cons{ + +public Object first; +public Cons rest; + +public Cons(Object first, Cons rest) + { + this.first = first; + this.rest = rest; + } + +} diff --git a/src/org/clojure/runtime/Symbol.java b/src/org/clojure/runtime/Symbol.java new file mode 100644 index 00000000..f115963c --- /dev/null +++ b/src/org/clojure/runtime/Symbol.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Mar 25, 2006 11:42:47 AM */ + +package org.clojure.runtime; + +public class Symbol{ +} diff --git a/src/org/clojure/runtime/ThreadLocalData.java b/src/org/clojure/runtime/ThreadLocalData.java new file mode 100644 index 00000000..a011af39 --- /dev/null +++ b/src/org/clojure/runtime/ThreadLocalData.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Mar 25, 2006 11:45:22 AM */ + +package org.clojure.runtime; + +import java.util.IdentityHashMap; + +public class ThreadLocalData{ + +final public static int MULTIPLE_VALUES_LIMIT = 20; +public int mvCount = 0; +public Object[] mvArray = new Object[MULTIPLE_VALUES_LIMIT]; + +IdentityHashMap dynamicBindings = new IdentityHashMap(); + +final public Cons getDynamicBinding(Symbol sym) + { + return (Cons) dynamicBindings.get(sym); + } + +final public Cons pushDynamicBinding(Symbol sym, Object val) + { + Cons ret = new Cons(val, getDynamicBinding(sym)); + dynamicBindings.put(sym, ret); + return ret; + } + + +final public Cons popDynamicBinding(Symbol sym) + { + return (Cons) dynamicBindings.put(sym, getDynamicBinding(sym).rest); + } + +public ThreadLocalData(IdentityHashMap dynamicBindings) + { + this.mvCount = 0; + this.mvArray = new Object[MULTIPLE_VALUES_LIMIT]; + this.dynamicBindings = dynamicBindings; + } + +public ThreadLocalData() + { + this(new IdentityHashMap()); + } + +public static ThreadLocalData get() + { + return (ThreadLocalData) tld.get(); + } + +static InheritableThreadLocal tld = new InheritableThreadLocal(){ + protected Object childValue(Object object) + { + return new ThreadLocalData((IdentityHashMap) ((ThreadLocalData) object).dynamicBindings.clone()); + } + + protected Object initialValue() + { + return new ThreadLocalData(); + } +}; + +} |