From 08e27be5bba0400b651ed7877e72ff48bbdd6ccc Mon Sep 17 00:00:00 2001 From: Rich Hickey Date: Wed, 31 May 2006 20:45:32 +0000 Subject: added tld to IObj sigs, added TObj --- src/cli/runtime/IObj.cs | 18 ++++++++++++++---- src/cli/runtime/Keyword.cs | 2 +- src/cli/runtime/Obj.cs | 6 +++--- src/cli/runtime/TObj.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/cli/runtime/TObj.cs (limited to 'src/cli') diff --git a/src/cli/runtime/IObj.cs b/src/cli/runtime/IObj.cs index 3362ead2..d3e71ee8 100644 --- a/src/cli/runtime/IObj.cs +++ b/src/cli/runtime/IObj.cs @@ -1,10 +1,20 @@ -using System; +/** + * 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. + **/ + +using System; namespace org.clojure.runtime { interface IObj { - object put(IComparable key, object val); - object get(IComparable key); - bool has(IComparable key); + object put(ThreadLocalData tld, IComparable key, object val); + object get(ThreadLocalData tld, IComparable key); + bool has(ThreadLocalData tld, IComparable key); } } diff --git a/src/cli/runtime/Keyword.cs b/src/cli/runtime/Keyword.cs index 903d8ea4..903a8619 100644 --- a/src/cli/runtime/Keyword.cs +++ b/src/cli/runtime/Keyword.cs @@ -24,7 +24,7 @@ internal Keyword(String name):base(name) { } public Object invoke(ThreadLocal } /** * Indexer implements IFn for attr access * This single arg version is the getter * @param tld * @param obj - must be AMap * @return the value of the attr or nil if not found */ public Object invoke(ThreadLocalData tld, Object obj) /*throws Exception*/ { if (obj == null) return null; - return ((IObj)obj).get(this); } /** * Indexer implements IFn for attr access * This two arg version is the setter * @param tld * @param obj - must be AMap * @param val * @return val */ public Object invoke(ThreadLocalData tld, Object obj, Object val) /*throws Exception*/ { return ((IObj)obj).put(this,val); } + return ((IObj)obj).get(tld,this); } /** * Indexer implements IFn for attr access * This two arg version is the setter * @param tld * @param obj - must be AMap * @param val * @return val */ public Object invoke(ThreadLocalData tld, Object obj, Object val) /*throws Exception*/ { return ((IObj)obj).put(tld,this,val); } public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3) /*throws Exception*/ { diff --git a/src/cli/runtime/Obj.cs b/src/cli/runtime/Obj.cs index 8f73335e..45c5edfa 100644 --- a/src/cli/runtime/Obj.cs +++ b/src/cli/runtime/Obj.cs @@ -22,7 +22,7 @@ public class Obj : IObj HybridDictionary attrs; public static int INITIAL_SIZE = 7; -public Object put(IComparable key, Object val) +public Object put(ThreadLocalData tld, IComparable key, Object val) { if(attrs == null) attrs = new HybridDictionary(INITIAL_SIZE); @@ -30,14 +30,14 @@ public Object put(IComparable key, Object val) return val; } -public Object get(IComparable key) +public Object get(ThreadLocalData tld, IComparable key) { if(attrs == null) return null; return attrs[key]; } -public bool has(IComparable key) +public bool has(ThreadLocalData tld, IComparable key) { if (attrs == null) return false; diff --git a/src/cli/runtime/TObj.cs b/src/cli/runtime/TObj.cs new file mode 100644 index 00000000..125960b5 --- /dev/null +++ b/src/cli/runtime/TObj.cs @@ -0,0 +1,40 @@ +/** + * 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. + **/ + +using System; + +namespace org.clojure.runtime + { + +public class TObj : IObj{ +TRef attrs; + +public TObj(ThreadLocalData tld) { + this.attrs = Transaction.tref(tld,new RBTree()); +} + +public Object put(ThreadLocalData tld, IComparable key, Object val) { + RBTree t = (RBTree) Transaction.get(tld, attrs); + t = t.put(key, val); + Transaction.set(tld,attrs,t); + return val; +} + +public Object get(ThreadLocalData tld, IComparable key) { + RBTree t = (RBTree) Transaction.get(tld, attrs); + return t.get(key); +} + +public bool has(ThreadLocalData tld, IComparable key) { + RBTree t = (RBTree) Transaction.get(tld, attrs); + return t.contains(key); +} +} +} -- cgit v1.2.3-70-g09d2