summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli/runtime/PersistentArrayIdentityMap.cs9
-rw-r--r--src/cli/runtime/PersistentArrayMap.cs13
-rw-r--r--src/cli/runtime/PersistentHybridIdentityMap.cs2
-rw-r--r--src/cli/runtime/PersistentHybridMap.cs2
-rw-r--r--src/org/clojure/runtime/ISeq.java4
-rw-r--r--src/org/clojure/runtime/ISequential.java2
-rw-r--r--src/org/clojure/runtime/PersistentArrayIdentityMap.java10
-rw-r--r--src/org/clojure/runtime/PersistentArrayMap.java13
-rw-r--r--src/org/clojure/runtime/PersistentHashtableMap.java10
-rw-r--r--src/org/clojure/runtime/PersistentHybridIdentityMap.java2
-rw-r--r--src/org/clojure/runtime/PersistentHybridMap.java4
-rw-r--r--src/org/clojure/runtime/PersistentTree.java4
-rw-r--r--src/org/clojure/runtime/RT.java26
13 files changed, 66 insertions, 35 deletions
diff --git a/src/cli/runtime/PersistentArrayIdentityMap.cs b/src/cli/runtime/PersistentArrayIdentityMap.cs
index b6cc57bc..232a143a 100644
--- a/src/cli/runtime/PersistentArrayIdentityMap.cs
+++ b/src/cli/runtime/PersistentArrayIdentityMap.cs
@@ -16,7 +16,14 @@ namespace org.clojure.runtime
* ArrayMap using identity (==) comparison instead of equals
*/
public class PersistentArrayIdentityMap : PersistentArrayMap {
-public PersistentArrayIdentityMap() {
+
+new public static PersistentArrayIdentityMap EMPTY = new PersistentArrayIdentityMap();
+
+override public IPersistentMap empty() {
+ return EMPTY;
+}
+
+PersistentArrayIdentityMap() {
}
public PersistentArrayIdentityMap(Object[] init) :base(init) {
diff --git a/src/cli/runtime/PersistentArrayMap.cs b/src/cli/runtime/PersistentArrayMap.cs
index f6a30be7..ebb217a4 100644
--- a/src/cli/runtime/PersistentArrayMap.cs
+++ b/src/cli/runtime/PersistentArrayMap.cs
@@ -29,7 +29,9 @@ public class PersistentArrayMap : IPersistentMap, ISequential {
internal readonly Object[] array;
-public PersistentArrayMap(){
+ public static PersistentArrayMap EMPTY = new PersistentArrayMap();
+
+protected PersistentArrayMap(){
this.array = RT.EMPTY_ARRAY;
}
@@ -86,7 +88,10 @@ public IPersistentMap remove(Object key) {
int i = indexOf(key);
if(i >= 0) //have key, will remove
{
- Object[] newArray = new Object[array.Length - 2];
+ int newlen = array.Length - 2;
+ if (newlen == 0)
+ return empty();
+ Object[] newArray = new Object[newlen];
for(int s=0,d=0;s<array.Length;s += 2)
{
if(!equalKey(array[s],key)) //skip removal key
@@ -102,6 +107,10 @@ public IPersistentMap remove(Object key) {
return this;
}
+virtual public IPersistentMap empty() {
+ return EMPTY;
+}
+
public Object get(Object key) {
int i = indexOf(key);
if(i >= 0)
diff --git a/src/cli/runtime/PersistentHybridIdentityMap.cs b/src/cli/runtime/PersistentHybridIdentityMap.cs
index 069a14fb..e1e420e8 100644
--- a/src/cli/runtime/PersistentHybridIdentityMap.cs
+++ b/src/cli/runtime/PersistentHybridIdentityMap.cs
@@ -34,7 +34,7 @@ override public PersistentArrayMap createArrayMap(Object[] init) {
}
override internal IPersistentMap createArrayMap() {
- return new PersistentArrayIdentityMap();
+ return PersistentArrayIdentityMap.EMPTY;
}
override internal IPersistentMap createHashtableMap(Object[] init) {
diff --git a/src/cli/runtime/PersistentHybridMap.cs b/src/cli/runtime/PersistentHybridMap.cs
index 7c0cc88e..67cbfb28 100644
--- a/src/cli/runtime/PersistentHybridMap.cs
+++ b/src/cli/runtime/PersistentHybridMap.cs
@@ -89,7 +89,7 @@ virtual public PersistentArrayMap createArrayMap(Object[] init) {
}
virtual internal IPersistentMap createArrayMap() {
- return new PersistentArrayMap();
+ return PersistentArrayMap.EMPTY;
}
virtual internal IPersistentMap createHashtableMap(Object[] init) {
diff --git a/src/org/clojure/runtime/ISeq.java b/src/org/clojure/runtime/ISeq.java
index 76b70f94..882f404b 100644
--- a/src/org/clojure/runtime/ISeq.java
+++ b/src/org/clojure/runtime/ISeq.java
@@ -18,7 +18,7 @@ package org.clojure.runtime;
*/
public interface ISeq {
-Object first();
+Object first() throws Exception;
-ISeq rest();
+ISeq rest() throws Exception;
}
diff --git a/src/org/clojure/runtime/ISequential.java b/src/org/clojure/runtime/ISequential.java
index 943e44b2..d55a6b3a 100644
--- a/src/org/clojure/runtime/ISequential.java
+++ b/src/org/clojure/runtime/ISequential.java
@@ -13,6 +13,6 @@ package org.clojure.runtime;
public interface ISequential {
-ISeq seq();
+ISeq seq() throws Exception;
}
diff --git a/src/org/clojure/runtime/PersistentArrayIdentityMap.java b/src/org/clojure/runtime/PersistentArrayIdentityMap.java
index 8db6f2a7..681a27cf 100644
--- a/src/org/clojure/runtime/PersistentArrayIdentityMap.java
+++ b/src/org/clojure/runtime/PersistentArrayIdentityMap.java
@@ -14,7 +14,15 @@ package org.clojure.runtime;
* ArrayMap using identity (==) comparison instead of equals
*/
public class PersistentArrayIdentityMap extends PersistentArrayMap {
-public PersistentArrayIdentityMap() {
+
+public static PersistentArrayIdentityMap EMPTY = new PersistentArrayIdentityMap();
+
+
+private PersistentArrayIdentityMap() {
+}
+
+IPersistentMap empty() {
+ return EMPTY;
}
public PersistentArrayIdentityMap(Object[] init) {
diff --git a/src/org/clojure/runtime/PersistentArrayMap.java b/src/org/clojure/runtime/PersistentArrayMap.java
index 36cff950..a2ce4a12 100644
--- a/src/org/clojure/runtime/PersistentArrayMap.java
+++ b/src/org/clojure/runtime/PersistentArrayMap.java
@@ -27,7 +27,9 @@ public class PersistentArrayMap implements IPersistentMap, ISequential {
final Object[] array;
-public PersistentArrayMap(){
+public static PersistentArrayMap EMPTY = new PersistentArrayMap();
+
+protected PersistentArrayMap(){
this.array = RT.EMPTY_ARRAY;
}
@@ -84,7 +86,10 @@ public IPersistentMap remove(Object key) {
int i = indexOf(key);
if(i >= 0) //have key, will remove
{
- Object[] newArray = new Object[array.length - 2];
+ int newlen = array.length - 2;
+ if(newlen == 0)
+ return empty();
+ Object[] newArray = new Object[newlen];
for(int s=0,d=0;s<array.length;s += 2)
{
if(!equalKey(array[s],key)) //skip removal key
@@ -100,6 +105,10 @@ public IPersistentMap remove(Object key) {
return this;
}
+IPersistentMap empty() {
+ return EMPTY;
+}
+
public Object get(Object key) {
int i = indexOf(key);
if(i >= 0)
diff --git a/src/org/clojure/runtime/PersistentHashtableMap.java b/src/org/clojure/runtime/PersistentHashtableMap.java
index 89215197..0fb71b64 100644
--- a/src/org/clojure/runtime/PersistentHashtableMap.java
+++ b/src/org/clojure/runtime/PersistentHashtableMap.java
@@ -145,7 +145,7 @@ public Iterator iterator() {
return new Iter(array);
}
-public ISeq seq() {
+public ISeq seq() throws Exception {
return Seq.create(array);
}
@@ -155,11 +155,11 @@ static class Seq implements ISeq{
ISeq e;
- static public Seq create(PersistentArray buckets) {
+ static public Seq create(PersistentArray buckets) throws Exception {
return next(buckets, -1, null);
}
- static Seq next(PersistentArray buckets, int b, ISeq e) {
+ static Seq next(PersistentArray buckets, int b, ISeq e) throws Exception {
if(e != null && e.rest() != null)
return new Seq(buckets,b,e.rest());
for(b = b+1;b<buckets.length();b++)
@@ -177,11 +177,11 @@ static class Seq implements ISeq{
this.e = e;
}
- public Object first() {
+ public Object first() throws Exception {
return e.first();
}
- public ISeq rest() {
+ public ISeq rest() throws Exception {
return next(buckets,b,e);
}
}
diff --git a/src/org/clojure/runtime/PersistentHybridIdentityMap.java b/src/org/clojure/runtime/PersistentHybridIdentityMap.java
index 6ea9aa2f..2d432146 100644
--- a/src/org/clojure/runtime/PersistentHybridIdentityMap.java
+++ b/src/org/clojure/runtime/PersistentHybridIdentityMap.java
@@ -33,7 +33,7 @@ public PersistentArrayMap createArrayMap(Object[] init) {
}
IPersistentMap createArrayMap() {
- return new PersistentArrayIdentityMap();
+ return PersistentArrayIdentityMap.EMPTY;
}
IPersistentMap createHashtableMap(Object[] init) {
diff --git a/src/org/clojure/runtime/PersistentHybridMap.java b/src/org/clojure/runtime/PersistentHybridMap.java
index 7f517cb6..54e153ed 100644
--- a/src/org/clojure/runtime/PersistentHybridMap.java
+++ b/src/org/clojure/runtime/PersistentHybridMap.java
@@ -87,7 +87,7 @@ public PersistentArrayMap createArrayMap(Object[] init) {
}
IPersistentMap createArrayMap() {
- return new PersistentArrayMap();
+ return PersistentArrayMap.EMPTY;
}
IPersistentMap createHashtableMap(Object[] init) {
@@ -98,7 +98,7 @@ IPersistentMap createHashtableMap(int initialCapacity) {
return new PersistentHashtableMap(initialCapacity);
}
-public ISeq seq() {
+public ISeq seq() throws Exception {
return impl.seq();
}
}
diff --git a/src/org/clojure/runtime/PersistentTree.java b/src/org/clojure/runtime/PersistentTree.java
index 2bd76409..2281f1f2 100644
--- a/src/org/clojure/runtime/PersistentTree.java
+++ b/src/org/clojure/runtime/PersistentTree.java
@@ -628,11 +628,11 @@ static public class Seq implements ISeq{
return stack;
}
- public Object first() {
+ public Object first() throws Exception {
return stack.first();
}
- public ISeq rest() {
+ public ISeq rest() throws Exception {
Node t = (Node)stack.first();
ISeq nextstack = push(asc ? t.right() : t.left(), stack.rest(), asc);
if(nextstack != null)
diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java
index 888e925b..f051f345 100644
--- a/src/org/clojure/runtime/RT.java
+++ b/src/org/clojure/runtime/RT.java
@@ -241,25 +241,23 @@ static public Cons arrayToList(Object[] a){
return ret;
}
-static public int length(ISeq list)
+static public int length(ISeq list) throws Exception {
+int i = 0;
+for(ISeq c = list; c != null; c = c.rest())
{
- int i = 0;
- for(ISeq c = list; c != null; c = c.rest())
- {
- i++;
- }
- return i;
+ i++;
}
+return i;
+}
-static public int boundedLength(ISeq list, int limit)
+static public int boundedLength(ISeq list, int limit) throws Exception {
+int i = 0;
+for(ISeq c = list; c != null && i <= limit; c = c.rest())
{
- int i = 0;
- for(ISeq c = list; c != null && i <= limit; c = c.rest())
- {
- i++;
- }
- return i;
+ i++;
}
+return i;
+}
///////////////////////////////// reader support ////////////////////////////////