diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-05-31 20:45:32 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-05-31 20:45:32 +0000 |
commit | 08e27be5bba0400b651ed7877e72ff48bbdd6ccc (patch) | |
tree | 575b3dc4cd7e5e294375d657702c342b7ab2af69 /src | |
parent | 19d311642fa821d51365a551756146336c24a270 (diff) |
added tld to IObj sigs, added TObj
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/runtime/IObj.cs | 18 | ||||
-rw-r--r-- | src/cli/runtime/Keyword.cs | 2 | ||||
-rw-r--r-- | src/cli/runtime/Obj.cs | 6 | ||||
-rw-r--r-- | src/cli/runtime/TObj.cs | 40 | ||||
-rw-r--r-- | src/org/clojure/runtime/IObj.java | 16 | ||||
-rw-r--r-- | src/org/clojure/runtime/Keyword.java | 4 | ||||
-rw-r--r-- | src/org/clojure/runtime/Obj.java | 6 | ||||
-rw-r--r-- | src/org/clojure/runtime/TObj.java | 36 |
8 files changed, 112 insertions, 16 deletions
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);
+}
+}
+}
diff --git a/src/org/clojure/runtime/IObj.java b/src/org/clojure/runtime/IObj.java index 8fddcfe3..e4284aba 100644 --- a/src/org/clojure/runtime/IObj.java +++ b/src/org/clojure/runtime/IObj.java @@ -1,3 +1,13 @@ +/**
+ * 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.
+ **/
+
package org.clojure.runtime;
/**
@@ -8,9 +18,9 @@ package org.clojure.runtime; * To change this template use File | Settings | File Templates.
*/
public interface IObj {
-Object put(Comparable key, Object val);
+Object put(ThreadLocalData tld, Comparable key, Object val) throws Exception;
-Object get(Comparable key);
+Object get(ThreadLocalData tld, Comparable key) throws Exception;
-boolean has(Comparable key);
+boolean has(ThreadLocalData tld, Comparable key) throws Exception;
}
diff --git a/src/org/clojure/runtime/Keyword.java b/src/org/clojure/runtime/Keyword.java index 161e0c88..63ea4d7d 100644 --- a/src/org/clojure/runtime/Keyword.java +++ b/src/org/clojure/runtime/Keyword.java @@ -44,7 +44,7 @@ public Object invoke(ThreadLocalData tld, Object obj) throws Exception { if (obj == null) return null; - return ((IObj)obj).get(this); + return ((IObj)obj).get(tld,this); } /** @@ -58,7 +58,7 @@ public Object invoke(ThreadLocalData tld, Object obj) throws Exception */ public Object invoke(ThreadLocalData tld, Object obj, Object val) throws Exception { - return ((IObj)obj).put(this,val); + return ((IObj)obj).put(tld,this,val); } public Object invoke(ThreadLocalData tld, Object arg1, Object arg2, Object arg3) throws Exception diff --git a/src/org/clojure/runtime/Obj.java b/src/org/clojure/runtime/Obj.java index ce71c736..c8aa532d 100644 --- a/src/org/clojure/runtime/Obj.java +++ b/src/org/clojure/runtime/Obj.java @@ -19,7 +19,7 @@ public class Obj implements IObj { IdentityHashMap attrs; public static final int INITIAL_SIZE = 7; -public Object put(Comparable key, Object val) +public Object put(ThreadLocalData tld, Comparable key, Object val) { if(attrs == null) attrs = new IdentityHashMap(INITIAL_SIZE); @@ -27,14 +27,14 @@ public Object put(Comparable key, Object val) return val; } -public Object get(Comparable key) +public Object get(ThreadLocalData tld, Comparable key) { if(attrs == null) return null; return attrs.get(key); } -public boolean has(Comparable key){ +public boolean has(ThreadLocalData tld, Comparable key){ if(attrs == null) return false; return attrs.containsKey(key); diff --git a/src/org/clojure/runtime/TObj.java b/src/org/clojure/runtime/TObj.java new file mode 100644 index 00000000..8a0acb57 --- /dev/null +++ b/src/org/clojure/runtime/TObj.java @@ -0,0 +1,36 @@ +/**
+ * 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.
+ **/
+
+package org.clojure.runtime;
+
+public class TObj implements IObj{
+TRef attrs;
+
+public TObj(ThreadLocalData tld) throws Exception{
+ this.attrs = Transaction.tref(tld,new RBTree());
+}
+
+public Object put(ThreadLocalData tld, Comparable key, Object val) throws Exception {
+ RBTree t = (RBTree) Transaction.get(tld, attrs);
+ t = t.put(key, val);
+ Transaction.set(tld,attrs,t);
+ return val;
+}
+
+public Object get(ThreadLocalData tld, Comparable key) throws Exception {
+ RBTree t = (RBTree) Transaction.get(tld, attrs);
+ return t.get(key);
+}
+
+public boolean has(ThreadLocalData tld, Comparable key) throws Exception {
+ RBTree t = (RBTree) Transaction.get(tld, attrs);
+ return t.contains(key);
+}
+}
|