Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace clojure dependency with clj-ds (http://github.com/krukow/clj-ds

…). clj-ds is a clone of clojure's persistent data structures adapted by Karl Krukow.
  • Loading branch information...
commit 9375e3342e268338cc20935dc0aa0a53a04416af 1 parent 5fa72f9
@krestenkrab krestenkrab authored
View
2  .classpath
@@ -5,9 +5,9 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/OtpErlang.jar"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar"/>
- <classpathentry kind="lib" path="lib/clojure-slim.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
<classpathentry kind="lib" path="lib/kilim-0.6-krab.jar" sourcepath="/kilim/src"/>
<classpathentry kind="lib" path="lib/js.jar"/>
+ <classpathentry kind="lib" path="lib/clj-ds.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
4 build.xml
@@ -7,7 +7,7 @@
<pathelement location="lib/kilim-0.6-krab.jar" />
<pathelement location="lib/OtpErlang.jar" />
<pathelement location="lib/junit.jar" />
- <pathelement location="lib/clojure-slim.jar" />
+ <pathelement location="lib/clj-ds.jar" />
<pathelement location="lib/antlr-3.2.jar" />
<pathelement path="${java.class.path}" />
</path>
@@ -16,7 +16,7 @@
<pathelement location="target/test-classes/" />
<pathelement location="lib/kilim-0.6-krab.jar" />
<pathelement location="lib/OtpErlang.jar" />
- <pathelement location="lib/clojure-slim.jar" />
+ <pathelement location="lib/clj-ds.jar" />
<pathelement location="lib/junit.jar" />
<pathelement location="lib/antlr-3.2.jar" />
<pathelement path="${java.class.path}" />
View
BIN  lib/clj-ds.jar
Binary file not shown
View
BIN  lib/clojure-slim.jar
Binary file not shown
View
2  src/main/java/erjang/beam/BeamFunction.java
@@ -20,7 +20,7 @@
import java.util.Set;
-import clojure.lang.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentCollection;
public interface BeamFunction {
View
2  src/main/java/erjang/beam/CompilerVisitor.java
@@ -48,7 +48,7 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.Method;
-import clojure.lang.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentCollection;
import erjang.EAtom;
import erjang.EBinMatchState;
View
8 src/main/java/erjang/beam/analysis/BeamTypeAnalysis.java
@@ -32,10 +32,10 @@
import org.objectweb.asm.Type;
-import clojure.lang.IPersistentCollection;
-import clojure.lang.IPersistentSet;
-import clojure.lang.PersistentHashSet;
-import clojure.lang.PersistentTreeSet;
+import com.trifork.clj_ds.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentSet;
+import com.trifork.clj_ds.PersistentHashSet;
+import com.trifork.clj_ds.PersistentTreeSet;
import erjang.EAtom;
import erjang.EBig;
View
4 src/main/java/erjang/beam/analysis/TypeMap.java
@@ -23,8 +23,8 @@
import org.objectweb.asm.Type;
-import clojure.lang.IPersistentMap;
-import clojure.lang.PersistentHashMap;
+import com.trifork.clj_ds.IPersistentMap;
+import com.trifork.clj_ds.PersistentHashMap;
import erjang.EObject;
import erjang.ETuple;
View
7 src/main/java/erjang/m/ets/EMatchSpec.java
@@ -21,7 +21,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -29,10 +28,8 @@
import java.util.Set;
import java.util.TreeSet;
-import javax.swing.event.ListSelectionEvent;
-
-import clojure.lang.IPersistentCollection;
-import clojure.lang.ISeq;
+import com.trifork.clj_ds.IPersistentCollection;
+import com.trifork.clj_ds.ISeq;
import erjang.EAtom;
import erjang.EBitString;
View
2  src/main/java/erjang/m/ets/EPattern.java
@@ -26,7 +26,7 @@
import java.util.TreeSet;
import java.util.regex.Pattern;
-import clojure.lang.ISeq;
+import com.trifork.clj_ds.ISeq;
import erjang.EAtom;
import erjang.EBitString;
View
39 src/main/java/erjang/m/ets/ETable.java
@@ -20,16 +20,15 @@
import java.lang.ref.WeakReference;
import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicReference;
import kilim.Pausable;
-import clojure.lang.APersistentMap;
-import clojure.lang.IMapEntry;
-import clojure.lang.IPersistentMap;
-import clojure.lang.ISeq;
-import clojure.lang.LockingTransaction;
-import clojure.lang.PersistentTreeMap;
-import clojure.lang.RT;
-import clojure.lang.Ref;
+import com.trifork.clj_ds.APersistentMap;
+import com.trifork.clj_ds.IMapEntry;
+import com.trifork.clj_ds.IPersistentMap;
+import com.trifork.clj_ds.ISeq;
+import com.trifork.clj_ds.PersistentTreeMap;
+import com.trifork.clj_ds.RT;
import erjang.EAtom;
import erjang.EInteger;
import erjang.EInternalPID;
@@ -56,10 +55,6 @@
*/
abstract class ETable implements ExitHook {
- static {
- Object o = RT.IN;
- }
-
public static final EAtom am_stm = EAtom.intern("stm");
@@ -73,7 +68,7 @@
protected final boolean is_named;
protected final EAtom type;
protected final APersistentMap empty;
- private Ref mapRef;
+ private AtomicReference<IPersistentMap<EObject, Object>> mapRef;
private boolean is_fixed;
ETable(EProc owner, EAtom type, EInteger tid, EAtom aname, EAtom access, int keypos,
@@ -88,7 +83,7 @@
this.heirPID = heir_pid;
this.heirData = heir_data;
try {
- this.mapRef = new Ref(map);
+ this.mapRef = new AtomicReference<IPersistentMap<EObject,Object>>(map);
} catch (Exception e) {
throw new ErlangError(am_stm);
}
@@ -221,29 +216,33 @@ EObject get_key(ETuple value) {
}
IPersistentMap deref() {
- return (IPersistentMap) mapRef.deref();
+ return (IPersistentMap) mapRef.get();
}
abstract class WithMap<T> implements Callable<T> {
+ private IPersistentMap orig;
+
@Override
- public final T call() throws Exception {
- return run((IPersistentMap)mapRef.deref());
+ public final T call() {
+ return run(orig = (IPersistentMap)mapRef.get());
}
protected abstract T run(IPersistentMap map);
protected void set(IPersistentMap map) {
- mapRef.set(map);
+ mapRef.compareAndSet(orig, map);
}
}
@SuppressWarnings("unchecked")
- <X> X in_tx(Callable<X> run) {
+ <X> X in_tx(WithMap<X> run) {
try {
- return (X) LockingTransaction.runInTransaction(run);
+ synchronized (ETable.this) {
+ return run.call();
+ }
} catch (Exception e) {
e.printStackTrace();
// STM Failure
View
49 src/main/java/erjang/m/ets/ETableBag.java
@@ -19,25 +19,22 @@
package erjang.m.ets;
import java.util.Map;
-
-import clojure.lang.IMapEntry;
-import clojure.lang.IPersistentCollection;
-import clojure.lang.IPersistentMap;
-import clojure.lang.IPersistentSet;
-import clojure.lang.ISeq;
-import clojure.lang.PersistentHashSet;
-import clojure.lang.PersistentTreeMap;
-import clojure.lang.RT;
-import clojure.lang.Ref;
-import clojure.lang.Seqable;
-import clojure.lang.Var;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.trifork.clj_ds.IMapEntry;
+import com.trifork.clj_ds.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentMap;
+import com.trifork.clj_ds.IPersistentSet;
+import com.trifork.clj_ds.ISeq;
+import com.trifork.clj_ds.PersistentHashSet;
+import com.trifork.clj_ds.PersistentTreeMap;
+import com.trifork.clj_ds.Seqable;
import erjang.EAtom;
import erjang.ECons;
import erjang.EInteger;
import erjang.EInternalPID;
import erjang.EList;
import erjang.EObject;
-import erjang.EPID;
import erjang.EProc;
import erjang.EPseudoTerm;
import erjang.ERT;
@@ -45,20 +42,14 @@
import erjang.ETuple;
import erjang.ETuple2;
import erjang.NotImplemented;
-import erjang.m.ets.ETableSet.ESetCont;
/**
*
*/
public class ETableBag extends ETable {
- static {
- // force loading of the Clojure runtime
- Var in = RT.IN;
- }
-
/** holds an Integer with the bag size */
- Ref sizeRef;
+ AtomicInteger sizeRef;
ETableBag(EProc owner,
EAtom type,
@@ -74,7 +65,7 @@
super(owner, type, tid, aname, access, keypos, isNamed, heirPid,
heirData, PersistentTreeMap.EMPTY);
try {
- sizeRef = new Ref(new Integer(0));
+ sizeRef = new AtomicInteger(0);
} catch (Exception e) {
throw new Error(e);
}
@@ -114,7 +105,7 @@ protected Object run(IPersistentMap map) {
map = map.assoc(key, c.cons(value));
count += 1;
}
- sizeRef.set(count + (Integer)sizeRef.deref());
+ sizeRef.set(count + (Integer)sizeRef.get());
set(map);
return null;
}
@@ -142,7 +133,7 @@ protected Object run(IPersistentMap map) {
(IPersistentCollection) map.valAt(key, empty);
map = map.assoc(key, c.cons(value));
set(map);
- sizeRef.set(1 + (Integer)sizeRef.deref());
+ sizeRef.set(1 + (Integer)sizeRef.get());
return null;
}
});
@@ -191,7 +182,7 @@ protected EObject first() {
@Override
int size() {
- return (Integer)sizeRef.deref();
+ return sizeRef.get();
}
@Override
@@ -268,7 +259,7 @@ protected Object run(IPersistentMap map) {
throw new Error(e);
}
set(map);
- sizeRef.set((Integer)sizeRef.deref() - c.count());
+ sizeRef.addAndGet(- c.count());
return null;
}
});
@@ -312,7 +303,7 @@ protected Object run(IPersistentMap map) {
}
set(map);
- sizeRef.set((Integer)sizeRef.deref() - deleted);
+ sizeRef.addAndGet(-deleted);
return null;
}
});
@@ -410,7 +401,7 @@ protected EInteger select_delete(final EMatchSpec matcher) {
@Override
protected Integer run(IPersistentMap map) {
ESeq vals = ERT.NIL;
- int initial_count = (Integer) sizeRef.deref();
+ int initial_count = sizeRef.get();
EObject key = matcher.getTupleKey(keypos1);
@@ -461,7 +452,7 @@ protected Integer run(IPersistentMap map) {
}
set(map);
- sizeRef.set(new Integer(initial_count-count));
+ sizeRef.set(initial_count-count);
return count;
}});
@@ -474,7 +465,7 @@ protected void delete_all_objects() {
@Override
protected Object run(IPersistentMap map) {
set(empty);
- sizeRef.set(new Integer(0));
+ sizeRef.set(0);
return null;
}
});
View
10 src/main/java/erjang/m/ets/ETableSet.java
@@ -22,11 +22,11 @@
import java.util.Map;
import java.util.Map.Entry;
-import clojure.lang.IMapEntry;
-import clojure.lang.IPersistentMap;
-import clojure.lang.ISeq;
-import clojure.lang.PersistentHashMap;
-import clojure.lang.PersistentTreeMap;
+import com.trifork.clj_ds.IMapEntry;
+import com.trifork.clj_ds.IPersistentMap;
+import com.trifork.clj_ds.ISeq;
+import com.trifork.clj_ds.PersistentHashMap;
+import com.trifork.clj_ds.PersistentTreeMap;
import erjang.EAtom;
import erjang.ECons;
import erjang.EInteger;
View
2  src/main/java/erjang/m/ets/IPersistentBag.java
@@ -19,7 +19,7 @@
package erjang.m.ets;
-import clojure.lang.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentCollection;
/**
*
View
18 src/main/java/erjang/m/ets/PersistentBag.java
@@ -18,13 +18,13 @@
package erjang.m.ets;
-import clojure.lang.IMapEntry;
-import clojure.lang.IPersistentCollection;
-import clojure.lang.IPersistentMap;
-import clojure.lang.ISeq;
-import clojure.lang.PersistentHashMap;
-import clojure.lang.PersistentList;
-import clojure.lang.PersistentTreeMap;
+import com.trifork.clj_ds.IMapEntry;
+import com.trifork.clj_ds.IPersistentCollection;
+import com.trifork.clj_ds.IPersistentMap;
+import com.trifork.clj_ds.ISeq;
+import com.trifork.clj_ds.PersistentHashMap;
+import com.trifork.clj_ds.PersistentList;
+import com.trifork.clj_ds.PersistentTreeMap;
/**
*
@@ -141,7 +141,7 @@ public boolean equiv(Object arg0) {
/*
* (non-Javadoc)
*
- * @see clojure.lang.Seqable#seq()
+ * @see com.trifork.clj_ds.Seqable#seq()
*/
@Override
public ISeq seq() {
@@ -159,7 +159,7 @@ public ISeq seq() {
/*
* (non-Javadoc)
*
- * @see clojure.lang.Seqable#seq()
+ * @see com.trifork.clj_ds.Seqable#seq()
*/
@Override
public ISeq seq() {
Please sign in to comment.
Something went wrong with that request. Please try again.