repo
string | commit
string | message
string | diff
string |
---|---|---|---|
dido/arcueid
|
103ab82fc0d493901b2fb86f9ab64fd6f5191e3c
|
continuation restoration
|
diff --git a/java/src/org/arcueidarc/nekoarc/HeapContinuation.java b/java/src/org/arcueidarc/nekoarc/HeapContinuation.java
index 565ebb2..ba7cdc9 100644
--- a/java/src/org/arcueidarc/nekoarc/HeapContinuation.java
+++ b/java/src/org/arcueidarc/nekoarc/HeapContinuation.java
@@ -1,57 +1,58 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.types.Vector;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class HeapContinuation extends Vector implements Continuation
{
public static final ArcObject TYPE = Symbol.intern("continuation");
public HeapContinuation(int size)
{
super(size);
}
@Override
/**
* Restore a stack-based continuation.
*/
public void restore(VirtualMachine vm, Callable cc)
{
Fixnum c = Fixnum.get(this.length());
for (int i=0; i<this.length(); i++)
vm.setStackIndex(i, index(i));
+ vm.setSP(this.length());
vm.setCont(c);
vm.restorecont();
}
public static HeapContinuation fromStackCont(VirtualMachine vm, ArcObject sc)
{
int cc = (int)((Fixnum)sc).fixnum;
HeapContinuation c = new HeapContinuation(cc);
for (int i=0; i<cc; i++)
c.setIndex(i, vm.stackIndex(i));
return(c);
}
@Override
public int requiredArgs()
{
return(1);
}
- /** The application of a continuation -- this does all the hard work of call/cc */
+ /** The application of a continuation -- this will set itself as the current continuation,
+ * ready to be restored just as the invokethread terminates. */
@Override
public ArcObject invoke(InvokeThread thr)
{
- // XXX -- fill this in
- return null;
+ thr.vm.setCont(this);
+ return(thr.getenv(0, 0));
}
-
}
|
dido/arcueid
|
cb68996b8930d5c8697d56dbe34885d62290404e
|
pass the caller optionally to the continuation when needed
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index 287e654..fe15033 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -95,563 +95,568 @@ public class VirtualMachine implements Callable
NOINST,
NOINST,
NOINST,
NOINST,
new LDL(), // 0x43
new LDI(), // 0x44
new LDG(), // 0x45
new STG(), // 0x46
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
caller = new CallSync();
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
// // Try to move the current continuation on the stack to the heap
// Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
// cont = nc;
// stackbottom = 0;
stackbottom = (int)((Fixnum)cont).fixnum + 1;
}
// Garbage collection failed to produce memory
if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
while (runnable) {
jmptbl[(int)code[ip++] & 0xff].invoke(this);
}
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
if (sp + 4 > stack.length) {
// Try to do stack gc first. If it fails, nothing for it
stackgc();
if (sp + 4 > stack.length)
throw new NekoArcException("stack overflow while creating continuation");
}
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
- // Restore continuation
public void restorecont()
+ {
+ restorecont(this);
+ }
+
+ // Restore continuation
+ public void restorecont(Callable caller)
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
- setEnv(pop());
+ setenvreg(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
- ((Continuation)cont).restore(this);
+ ((Continuation)cont).restore(this, caller);
} else if (cont.is(Nil.NIL)) {
// If we have no continuation, that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
- public void setEnv(ArcObject env)
+ public void setenvreg(ArcObject env)
{
this.env = env;
}
public int getBP()
{
return bp;
}
public void setBP(int bp)
{
this.bp = bp;
}
public ArcObject getCont()
{
return cont;
}
public void setCont(ArcObject cont)
{
this.cont = cont;
}
@Override
public CallSync sync()
{
return(caller);
}
}
|
dido/arcueid
|
1020c87ff3100e02f6ca71d9c5024aa98e012c94
|
special cases for closure execution from Java
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Closure.java b/java/src/org/arcueidarc/nekoarc/types/Closure.java
index 53a073e..caa7bf3 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Closure.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Closure.java
@@ -1,31 +1,32 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Closure extends Cons
{
public static final ArcObject TYPE = Symbol.intern("closure");
public Closure(ArcObject ca, ArcObject cd)
{
super(ca, cd);
}
/** This is the only place where apply should be overridden */
@Override
public void apply(VirtualMachine vm, Callable caller)
{
ArcObject newenv, newip;
newenv = this.car();
newip = this.cdr();
vm.setIP((int)((Fixnum)newip).fixnum);
- vm.setEnv(newenv);
- // If this is not a call from the vm itself, we need to take the additional step of waking up the VM thread
- // and causing the caller thread to sleep. Unnecessary if this is already a VM thread.
+ vm.setenvreg(newenv);
+ // If this is not a call from the vm itself, some other additional actions need to be taken.
+ // 1. The virtual machine thread should be resumed.
+ // 2. The caller must be suspended until the continuation it created is restored.
if (vm != caller) {
vm.sync().ret(this); // wakes the VM so it begins executing the closure
- vm.setAcc(caller.sync().retval()); // sleeps the caller until its JavaContinuation is restored
+ vm.setAcc(caller.sync().retval()); // sleeps the caller until its own continuation is restored
}
}
}
|
dido/arcueid
|
78d619f774568ab6bef1af9014b89bf274ca38dc
|
vm restore of JavaContinuation must do something special
|
diff --git a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
index 49a82e3..c030fa4 100644
--- a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
+++ b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
@@ -1,28 +1,41 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-public class JavaContinuation extends Continuation
+public class JavaContinuation extends ArcObject implements Continuation
{
+ public static final ArcObject TYPE = Symbol.intern("continuation");
+
private final ArcObject prev;
private final Callable caller;
+ private final ArcObject env;
- public JavaContinuation(Callable c, ArcObject pcont)
+ public JavaContinuation(VirtualMachine vm, Callable c)
{
- super(0);
- prev = pcont;
+ prev = vm.getCont();
caller = c;
+ env = vm.heapenv(); // copy current env to heap
}
@Override
- public void restore(VirtualMachine vm)
+ public void restore(VirtualMachine vm, Callable cc)
{
- // The restoration of a Java continuation should result in the InvokeThread resuming execution while the virtual machine
- // thread waits for it.
- vm.setAcc(caller.sync().retval());
vm.setCont(prev);
- vm.restorecont();
+ vm.setenvreg(env);
+ // This will re-enable the thread represented by this continuation
+ // This will stop the thread which restored this continuation
+ if (vm == cc) {
+ caller.sync().ret(vm.getAcc());
+ vm.setAcc(cc.sync().retval());
+ }
+ }
+
+ @Override
+ public ArcObject type()
+ {
+ return(TYPE);
}
}
|
dido/arcueid
|
ba2163b39c3950f0fc6a0a986c3a9ef21a1baf99
|
sequence of thread execution changed
|
diff --git a/java/src/org/arcueidarc/nekoarc/InvokeThread.java b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
index a3fc79f..5d801a9 100644
--- a/java/src/org/arcueidarc/nekoarc/InvokeThread.java
+++ b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
@@ -1,49 +1,55 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
/** The main reason this class exists is that Java is a weak-sauce language that doesn't have closures or true continuations. We have to
* emulate them using threads. */
-public class InvokeThread implements Runnable
+public class InvokeThread extends Thread
{
public final Callable caller;
public final ArcObject obj;
public final VirtualMachine vm;
public InvokeThread(VirtualMachine v, Callable c, ArcObject o)
{
vm = v;
caller = c;
obj = o;
}
@Override
public void run()
{
- caller.sync().ret(obj.invoke(this));
+ // Perform our function's thing
+ ArcObject ret = obj.invoke(this);
+ // Restore the continuation created by the caller
+ vm.restorecont(caller);
+ // Return the result to our caller's thread, waking them up
+ caller.sync().ret(ret);
+ // and this invoke thread's work is ended
}
public ArcObject getenv(int i, int j)
{
return(vm.getenv(i, j));
}
/** Perform a call to some Arc object. This should prolly work for ANY ArcObject that has a proper invoke method defined. If it is a built-in or
* some function defined in Java, that function will run in its own thread while the current object's thread is suspended. */
public ArcObject apply(ArcObject fn, ArcObject...args)
{
// First, push all of the arguments to the stack
for (ArcObject arg : args)
vm.push(arg);
// new continuation
- vm.setCont(new JavaContinuation(obj, vm.getCont()));
+ vm.setCont(new JavaContinuation(vm, obj));
// Apply the function.
fn.apply(vm, obj);
return(vm.getAcc());
}
}
|
dido/arcueid
|
b448c5412f0c938587d776fecf324dbf5771f2df
|
continuations on the heap
|
diff --git a/java/src/org/arcueidarc/nekoarc/HeapContinuation.java b/java/src/org/arcueidarc/nekoarc/HeapContinuation.java
new file mode 100644
index 0000000..565ebb2
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/HeapContinuation.java
@@ -0,0 +1,57 @@
+package org.arcueidarc.nekoarc;
+
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.types.Fixnum;
+import org.arcueidarc.nekoarc.types.Symbol;
+import org.arcueidarc.nekoarc.types.Vector;
+import org.arcueidarc.nekoarc.util.Callable;
+import org.arcueidarc.nekoarc.vm.VirtualMachine;
+
+public class HeapContinuation extends Vector implements Continuation
+{
+ public static final ArcObject TYPE = Symbol.intern("continuation");
+
+ public HeapContinuation(int size)
+ {
+ super(size);
+ }
+
+
+ @Override
+ /**
+ * Restore a stack-based continuation.
+ */
+ public void restore(VirtualMachine vm, Callable cc)
+ {
+ Fixnum c = Fixnum.get(this.length());
+ for (int i=0; i<this.length(); i++)
+ vm.setStackIndex(i, index(i));
+ vm.setCont(c);
+ vm.restorecont();
+ }
+
+ public static HeapContinuation fromStackCont(VirtualMachine vm, ArcObject sc)
+ {
+ int cc = (int)((Fixnum)sc).fixnum;
+ HeapContinuation c = new HeapContinuation(cc);
+ for (int i=0; i<cc; i++)
+ c.setIndex(i, vm.stackIndex(i));
+ return(c);
+ }
+
+
+ @Override
+ public int requiredArgs()
+ {
+ return(1);
+ }
+
+ /** The application of a continuation -- this does all the hard work of call/cc */
+ @Override
+ public ArcObject invoke(InvokeThread thr)
+ {
+ // XXX -- fill this in
+ return null;
+ }
+
+}
|
dido/arcueid
|
6299211c62c3de914f884b04ca7a890617e4d683
|
Continuation is now an interface
|
diff --git a/java/src/org/arcueidarc/nekoarc/Continuation.java b/java/src/org/arcueidarc/nekoarc/Continuation.java
index 478fd35..de00f28 100644
--- a/java/src/org/arcueidarc/nekoarc/Continuation.java
+++ b/java/src/org/arcueidarc/nekoarc/Continuation.java
@@ -1,54 +1,9 @@
package org.arcueidarc.nekoarc;
-import org.arcueidarc.nekoarc.types.ArcObject;
-import org.arcueidarc.nekoarc.types.Fixnum;
-import org.arcueidarc.nekoarc.types.Symbol;
-import org.arcueidarc.nekoarc.types.Vector;
+import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-public class Continuation extends Vector
+public interface Continuation
{
- public static final ArcObject TYPE = Symbol.intern("continuation");
-
- public Continuation(int size)
- {
- super(size);
- }
-
-
- /**
- * Restore a stack-based continuation.
- */
- public void restore(VirtualMachine vm)
- {
- Fixnum c = Fixnum.get(this.length());
- for (int i=0; i<this.length(); i++)
- vm.setStackIndex(i, index(i));
- vm.setCont(c);
- vm.restorecont();
- }
-
- public static Continuation fromStackCont(VirtualMachine vm, ArcObject sc)
- {
- int cc = (int)((Fixnum)sc).fixnum;
- Continuation c = new Continuation(cc);
- for (int i=0; i<cc; i++)
- c.setIndex(i, vm.stackIndex(i));
- return(c);
- }
-
-
- @Override
- public int requiredArgs()
- {
- return(1);
- }
-
- /** The application of a continuation -- this does all the hard work of call/cc */
- @Override
- public ArcObject invoke(InvokeThread thr)
- {
- // XXX -- fill this in
- return null;
- }
+ public void restore(VirtualMachine vm, Callable caller);
}
|
dido/arcueid
|
8e3709b83918bc96433d02622902e059aebf9b84
|
change to calling sequence in apply
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
index 119baad..a45c575 100644
--- a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
+++ b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
@@ -1,123 +1,122 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.util.CallSync;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public abstract class ArcObject implements Callable
{
private final CallSync caller = new CallSync();
public ArcObject car()
{
throw new NekoArcException("Can't take car of " + this.type());
}
public ArcObject cdr()
{
throw new NekoArcException("Can't take cdr of " + this.type());
}
public ArcObject scar(ArcObject ncar)
{
throw new NekoArcException("Can't set car of " + this.type());
}
public ArcObject scdr(ArcObject ncar)
{
throw new NekoArcException("Can't set cdr of " + this.type());
}
public ArcObject sref(ArcObject value, ArcObject index)
{
throw new NekoArcException("Can't sref" + this + "( a " + this.type() + "), other args were " + value + ", " + index);
}
public ArcObject add(ArcObject other)
{
throw new NekoArcException("add not implemented for " + this.type() + " " + this);
}
public long len()
{
throw new NekoArcException("len: expects one string, list, or hash argument");
}
public abstract ArcObject type();
public int requiredArgs()
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public int optionalArgs()
{
return(0);
}
public int extraArgs()
{
return(0);
}
public boolean variadicP()
{
return(false);
}
/** The basic apply. This should normally not be overridden. Only Closure should probably override it because it runs completely within the vm. */
public void apply(VirtualMachine vm, Callable caller)
{
int minenv, dsenv, optenv;
minenv = requiredArgs();
dsenv = extraArgs();
optenv = optionalArgs();
if (variadicP()) {
int i;
vm.argcheck(minenv, -1);
ArcObject rest = Nil.NIL;
for (i = vm.argc(); i>(minenv + optenv); i--)
rest = new Cons(vm.pop(), rest);
vm.mkenv(i, minenv + optenv - i + dsenv + 1);
/* store the rest parameter */
vm.setenv(0, minenv + optenv + dsenv, rest);
} else {
vm.argcheck(minenv, minenv + optenv);
vm.mkenv(vm.argc(), minenv + optenv - vm.argc() + dsenv);
}
// Start the invoke thread
InvokeThread thr = new InvokeThread(vm, caller, this);
new Thread(thr).start();
// Suspend the caller's thread until the invoke thread returns
vm.setAcc(caller.sync().retval());
- vm.restorecont();
}
public ArcObject invoke(InvokeThread vm)
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public String toString()
{
throw new NekoArcException("Type " + type() + " has no string representation");
}
// default implementation
public boolean is(ArcObject other)
{
return(this == other);
}
@Override
public CallSync sync()
{
return(caller );
}
}
|
dido/arcueid
|
8b8c6a83ff4b2102371ef1cb3d1713f5564b991f
|
Java to Arc call test
|
diff --git a/java/test/org/arcueidarc/nekoarc/vm/Java2ArcTest.java b/java/test/org/arcueidarc/nekoarc/vm/Java2ArcTest.java
new file mode 100644
index 0000000..de500cf
--- /dev/null
+++ b/java/test/org/arcueidarc/nekoarc/vm/Java2ArcTest.java
@@ -0,0 +1,58 @@
+package org.arcueidarc.nekoarc.vm;
+
+import static org.junit.Assert.*;
+
+import org.arcueidarc.nekoarc.InvokeThread;
+import org.arcueidarc.nekoarc.Nil;
+import org.arcueidarc.nekoarc.functions.Builtin;
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.types.Closure;
+import org.arcueidarc.nekoarc.types.Fixnum;
+import org.junit.Test;
+
+/** Test for Java to Arc bytecode calls */
+public class Java2ArcTest
+{
+
+ @Test
+ public void test()
+ {
+ Builtin builtin = new Builtin("test", 1, 0, 0, false)
+ {
+ @Override
+ public ArcObject invoke(InvokeThread thr)
+ {
+ ArcObject arg = thr.getenv(0, 0);
+ return(thr.apply(arg, Fixnum.get(1)));
+ }
+ };
+ // Apply the above builtin
+ // env 0 0 0; ldl 0; push; ldl 1; apply 1; ret;
+ // to (fn (x) (+ x 1))
+ // env 1 0 0; lde0 0; push; ldi 1; add; ret
+ byte inst[] = { (byte)0xca, 0x00, 0x00, 0x00, // env 0 0 0
+ 0x43, 0x00, 0x00, 0x00, 0x00, // ldl 0
+ 0x01, // push
+ 0x43, 0x01, 0x00, 0x00, 0x00, // ldl 0
+ 0x4c, 0x01, // apply 1
+ 0x0d, // ret
+ (byte)0xca, 0x01, 0x00, 0x00, // env 1 0 0
+ 0x69, 0x00, // lde0 0
+ 0x01, // push
+ 0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
+ 0x15, // add
+ 0x0d // ret
+ };
+ VirtualMachine vm = new VirtualMachine(1024);
+ ArcObject literals[] = new ArcObject[2];
+ literals[0] = new Closure(Nil.NIL, Fixnum.get(18)); // position of second
+ literals[1] = builtin;
+ vm.load(inst, 0, literals);
+ vm.setargc(0);
+ assertTrue(vm.runnable());
+ vm.run();
+ assertFalse(vm.runnable());
+ assertEquals(2, ((Fixnum)vm.getAcc()).fixnum);
+ }
+
+}
|
dido/arcueid
|
098e84767d24ec4fc5a63d0b394c9c5c081cd9b9
|
rename the call synchronisation classes and methods to better names
|
diff --git a/java/src/org/arcueidarc/nekoarc/InvokeThread.java b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
index 8f62997..a3fc79f 100644
--- a/java/src/org/arcueidarc/nekoarc/InvokeThread.java
+++ b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
@@ -1,49 +1,49 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
/** The main reason this class exists is that Java is a weak-sauce language that doesn't have closures or true continuations. We have to
* emulate them using threads. */
public class InvokeThread implements Runnable
{
public final Callable caller;
public final ArcObject obj;
public final VirtualMachine vm;
public InvokeThread(VirtualMachine v, Callable c, ArcObject o)
{
vm = v;
caller = c;
obj = o;
}
@Override
public void run()
{
- caller.caller().put(obj.invoke(this));
+ caller.sync().ret(obj.invoke(this));
}
public ArcObject getenv(int i, int j)
{
return(vm.getenv(i, j));
}
/** Perform a call to some Arc object. This should prolly work for ANY ArcObject that has a proper invoke method defined. If it is a built-in or
* some function defined in Java, that function will run in its own thread while the current object's thread is suspended. */
public ArcObject apply(ArcObject fn, ArcObject...args)
{
// First, push all of the arguments to the stack
for (ArcObject arg : args)
vm.push(arg);
// new continuation
vm.setCont(new JavaContinuation(obj, vm.getCont()));
// Apply the function.
fn.apply(vm, obj);
return(vm.getAcc());
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
index 8950f9a..49a82e3 100644
--- a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
+++ b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
@@ -1,28 +1,28 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class JavaContinuation extends Continuation
{
private final ArcObject prev;
private final Callable caller;
public JavaContinuation(Callable c, ArcObject pcont)
{
super(0);
prev = pcont;
caller = c;
}
@Override
public void restore(VirtualMachine vm)
{
// The restoration of a Java continuation should result in the InvokeThread resuming execution while the virtual machine
// thread waits for it.
- vm.setAcc(caller.caller().ret());
+ vm.setAcc(caller.sync().retval());
vm.setCont(prev);
vm.restorecont();
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
index 76536e1..119baad 100644
--- a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
+++ b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
@@ -1,123 +1,123 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.util.Callable;
-import org.arcueidarc.nekoarc.util.Caller;
+import org.arcueidarc.nekoarc.util.CallSync;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public abstract class ArcObject implements Callable
{
- private final Caller caller = new Caller();
+ private final CallSync caller = new CallSync();
public ArcObject car()
{
throw new NekoArcException("Can't take car of " + this.type());
}
public ArcObject cdr()
{
throw new NekoArcException("Can't take cdr of " + this.type());
}
public ArcObject scar(ArcObject ncar)
{
throw new NekoArcException("Can't set car of " + this.type());
}
public ArcObject scdr(ArcObject ncar)
{
throw new NekoArcException("Can't set cdr of " + this.type());
}
public ArcObject sref(ArcObject value, ArcObject index)
{
throw new NekoArcException("Can't sref" + this + "( a " + this.type() + "), other args were " + value + ", " + index);
}
public ArcObject add(ArcObject other)
{
throw new NekoArcException("add not implemented for " + this.type() + " " + this);
}
public long len()
{
throw new NekoArcException("len: expects one string, list, or hash argument");
}
public abstract ArcObject type();
public int requiredArgs()
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public int optionalArgs()
{
return(0);
}
public int extraArgs()
{
return(0);
}
public boolean variadicP()
{
return(false);
}
/** The basic apply. This should normally not be overridden. Only Closure should probably override it because it runs completely within the vm. */
public void apply(VirtualMachine vm, Callable caller)
{
int minenv, dsenv, optenv;
minenv = requiredArgs();
dsenv = extraArgs();
optenv = optionalArgs();
if (variadicP()) {
int i;
vm.argcheck(minenv, -1);
ArcObject rest = Nil.NIL;
for (i = vm.argc(); i>(minenv + optenv); i--)
rest = new Cons(vm.pop(), rest);
vm.mkenv(i, minenv + optenv - i + dsenv + 1);
/* store the rest parameter */
vm.setenv(0, minenv + optenv + dsenv, rest);
} else {
vm.argcheck(minenv, minenv + optenv);
vm.mkenv(vm.argc(), minenv + optenv - vm.argc() + dsenv);
}
// Start the invoke thread
InvokeThread thr = new InvokeThread(vm, caller, this);
new Thread(thr).start();
// Suspend the caller's thread until the invoke thread returns
- vm.setAcc(caller.caller().ret());
+ vm.setAcc(caller.sync().retval());
vm.restorecont();
}
public ArcObject invoke(InvokeThread vm)
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public String toString()
{
throw new NekoArcException("Type " + type() + " has no string representation");
}
// default implementation
public boolean is(ArcObject other)
{
return(this == other);
}
@Override
- public Caller caller()
+ public CallSync sync()
{
return(caller );
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/types/Closure.java b/java/src/org/arcueidarc/nekoarc/types/Closure.java
index 5739271..53a073e 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Closure.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Closure.java
@@ -1,31 +1,31 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Closure extends Cons
{
public static final ArcObject TYPE = Symbol.intern("closure");
public Closure(ArcObject ca, ArcObject cd)
{
super(ca, cd);
}
/** This is the only place where apply should be overridden */
@Override
public void apply(VirtualMachine vm, Callable caller)
{
ArcObject newenv, newip;
newenv = this.car();
newip = this.cdr();
vm.setIP((int)((Fixnum)newip).fixnum);
vm.setEnv(newenv);
// If this is not a call from the vm itself, we need to take the additional step of waking up the VM thread
// and causing the caller thread to sleep. Unnecessary if this is already a VM thread.
if (vm != caller) {
- vm.caller().put(this); // wakes the VM so it begins executing the closure
- vm.setAcc(caller.caller().ret()); // sleeps the caller until its JavaContinuation is restored
+ vm.sync().ret(this); // wakes the VM so it begins executing the closure
+ vm.setAcc(caller.sync().retval()); // sleeps the caller until its JavaContinuation is restored
}
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/util/Caller.java b/java/src/org/arcueidarc/nekoarc/util/CallSync.java
similarity index 81%
rename from java/src/org/arcueidarc/nekoarc/util/Caller.java
rename to java/src/org/arcueidarc/nekoarc/util/CallSync.java
index f1654b9..83ede6b 100644
--- a/java/src/org/arcueidarc/nekoarc/util/Caller.java
+++ b/java/src/org/arcueidarc/nekoarc/util/CallSync.java
@@ -1,34 +1,34 @@
package org.arcueidarc.nekoarc.util;
import java.util.concurrent.SynchronousQueue;
import org.arcueidarc.nekoarc.types.ArcObject;
-public class Caller
+public class CallSync
{
private final SynchronousQueue<ArcObject> syncqueue;
- public Caller()
+ public CallSync()
{
syncqueue = new SynchronousQueue<ArcObject>();
}
- public void put(ArcObject retval)
+ public void ret(ArcObject retval)
{
for (;;) {
try {
syncqueue.put(retval);
return;
} catch (InterruptedException e) { }
}
}
- public ArcObject ret()
+ public ArcObject retval()
{
for (;;) {
try {
return(syncqueue.take());
} catch (InterruptedException e) { }
}
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/util/Callable.java b/java/src/org/arcueidarc/nekoarc/util/Callable.java
index 06433d1..98e85ef 100644
--- a/java/src/org/arcueidarc/nekoarc/util/Callable.java
+++ b/java/src/org/arcueidarc/nekoarc/util/Callable.java
@@ -1,6 +1,6 @@
package org.arcueidarc.nekoarc.util;
public interface Callable
{
- public Caller caller();
+ public CallSync sync();
}
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index 97aced5..287e654 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -1,657 +1,657 @@
package org.arcueidarc.nekoarc.vm;
import org.arcueidarc.nekoarc.Continuation;
import org.arcueidarc.nekoarc.HeapEnv;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.Unbound;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
-import org.arcueidarc.nekoarc.util.Caller;
+import org.arcueidarc.nekoarc.util.CallSync;
import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.util.ObjectMap;
import org.arcueidarc.nekoarc.vm.instruction.*;
public class VirtualMachine implements Callable
{
private int sp; // stack pointer
private int bp; // base pointer
private ArcObject env; // environment pointer
private ArcObject cont; // continuation pointer
private ArcObject[] stack; // stack
- private final Caller caller;
+ private final CallSync caller;
private int ip; // instruction pointer
private byte[] code;
private boolean runnable;
private ArcObject acc; // accumulator
private ArcObject[] literals;
private int argc; // argument counter for current function
private static final INVALID NOINST = new INVALID();
private static final Instruction[] jmptbl = {
new NOP(), // 0x00
new PUSH(), // 0x01
new POP(), // 0x02
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new RET(), // 0x0d
NOINST,
NOINST,
NOINST,
new NO(), // 0x11
new TRUE(), // 0x12
new NIL(), // 0x13
new HLT(), // 0x14
new ADD(), // 0x15
new SUB(), // 0x16
new MUL(), // 0x17
new DIV(), // 0x18
new CONS(), // 0x19
new CAR(), // 0x1a
new CDR(), // 0x1b
new SCAR(), // 0x1c
new SCDR(), // 0x1d
NOINST,
new IS(), // 0x1f
NOINST,
NOINST,
new DUP(), // 0x22
NOINST, // 0x23
new CONSR(), // 0x24
NOINST,
new DCAR(), // 0x26
new DCDR(), // 0x27
new SPL(), // 0x28
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDL(), // 0x43
new LDI(), // 0x44
new LDG(), // 0x45
new STG(), // 0x46
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
- caller = new Caller();
+ caller = new CallSync();
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
// // Try to move the current continuation on the stack to the heap
// Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
// cont = nc;
// stackbottom = 0;
stackbottom = (int)((Fixnum)cont).fixnum + 1;
}
// Garbage collection failed to produce memory
if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
while (runnable) {
jmptbl[(int)code[ip++] & 0xff].invoke(this);
}
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
if (sp + 4 > stack.length) {
// Try to do stack gc first. If it fails, nothing for it
stackgc();
if (sp + 4 > stack.length)
throw new NekoArcException("stack overflow while creating continuation");
}
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
// Restore continuation
public void restorecont()
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
setEnv(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
((Continuation)cont).restore(this);
} else if (cont.is(Nil.NIL)) {
// If we have no continuation, that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
public void setEnv(ArcObject env)
{
this.env = env;
}
public int getBP()
{
return bp;
}
public void setBP(int bp)
{
this.bp = bp;
}
public ArcObject getCont()
{
return cont;
}
public void setCont(ArcObject cont)
{
this.cont = cont;
}
@Override
- public Caller caller()
+ public CallSync sync()
{
return(caller);
}
}
|
dido/arcueid
|
7f5de7e145981260f6878d0452d6a06ca03800a2
|
cause the applicant thread to become runnable when continuation is restored
|
diff --git a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
index 4537041..8950f9a 100644
--- a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
+++ b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
@@ -1,27 +1,28 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class JavaContinuation extends Continuation
{
private final ArcObject prev;
- private final InvokeThread inv;
+ private final Callable caller;
- public JavaContinuation(InvokeThread thr, ArcObject pcont)
+ public JavaContinuation(Callable c, ArcObject pcont)
{
super(0);
prev = pcont;
- inv = thr;
+ caller = c;
}
@Override
public void restore(VirtualMachine vm)
{
// The restoration of a Java continuation should result in the InvokeThread resuming execution while the virtual machine
// thread waits for it.
- vm.setAcc(inv.sync());
+ vm.setAcc(caller.caller().ret());
vm.setCont(prev);
vm.restorecont();
}
}
|
dido/arcueid
|
e6f4956cdf630b11c0f2d65fc9ff053e16abd4ea
|
changes to handle synchronisation
|
diff --git a/java/src/org/arcueidarc/nekoarc/InvokeThread.java b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
index 81c2c4f..8f62997 100644
--- a/java/src/org/arcueidarc/nekoarc/InvokeThread.java
+++ b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
@@ -1,71 +1,49 @@
package org.arcueidarc.nekoarc;
-import java.util.concurrent.SynchronousQueue;
-
import org.arcueidarc.nekoarc.types.ArcObject;
-import org.arcueidarc.nekoarc.types.Closure;
+import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-/** The main reason this class exists is that Java is a weak-sauce language that doesn't have closures */
+/** The main reason this class exists is that Java is a weak-sauce language that doesn't have closures or true continuations. We have to
+ * emulate them using threads. */
public class InvokeThread implements Runnable
{
- public final SynchronousQueue<ArcObject> syncqueue;
- public final VirtualMachine vm;
+ public final Callable caller;
public final ArcObject obj;
+ public final VirtualMachine vm;
- public InvokeThread(VirtualMachine vm, ArcObject obj)
+ public InvokeThread(VirtualMachine v, Callable c, ArcObject o)
{
- syncqueue = new SynchronousQueue<ArcObject>();
- this.vm = vm;
- this.obj = obj;
+ vm = v;
+ caller = c;
+ obj = o;
}
@Override
public void run()
{
- put(obj.invoke(this));
+ caller.caller().put(obj.invoke(this));
}
public ArcObject getenv(int i, int j)
{
return(vm.getenv(i, j));
}
- public void put(ArcObject val)
- {
- for (;;) {
- try {
- syncqueue.put(val);
- break;
- } catch (InterruptedException e) {}
- }
- }
-
- /** Synchronise invoke thread and virtual machine thread */
- public ArcObject sync()
- {
- for (;;) {
- try {
- return(syncqueue.take());
- } catch (InterruptedException e) {}
- }
- }
-
- /** Perform a call to some Arc object */
- public ArcObject apply(Closure fn, ArcObject...args)
+ /** Perform a call to some Arc object. This should prolly work for ANY ArcObject that has a proper invoke method defined. If it is a built-in or
+ * some function defined in Java, that function will run in its own thread while the current object's thread is suspended. */
+ public ArcObject apply(ArcObject fn, ArcObject...args)
{
// First, push all of the arguments to the stack
for (ArcObject arg : args)
vm.push(arg);
+
// new continuation
- vm.setCont(new JavaContinuation(this, vm.getCont()));
- // apply the closure
- fn.apply(vm);
- // Create a continuation that will cause the vm to begin execution right then and there
- vm.makecont(0);
- // cause the virtual machine thread to begin executing
- put(fn);
- // suspend this invoke thread until the virtual machine restores the JavaContinuation
- return(sync());
+ vm.setCont(new JavaContinuation(obj, vm.getCont()));
+
+ // Apply the function.
+ fn.apply(vm, obj);
+
+ return(vm.getAcc());
}
}
|
dido/arcueid
|
77f36f2032fa719431d352452096d0a25a022df8
|
synchronising apply
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
index f914beb..76536e1 100644
--- a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
+++ b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
@@ -1,111 +1,123 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
+import org.arcueidarc.nekoarc.util.Callable;
+import org.arcueidarc.nekoarc.util.Caller;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-public abstract class ArcObject
+public abstract class ArcObject implements Callable
{
+ private final Caller caller = new Caller();
+
public ArcObject car()
{
throw new NekoArcException("Can't take car of " + this.type());
}
public ArcObject cdr()
{
throw new NekoArcException("Can't take cdr of " + this.type());
}
public ArcObject scar(ArcObject ncar)
{
throw new NekoArcException("Can't set car of " + this.type());
}
public ArcObject scdr(ArcObject ncar)
{
throw new NekoArcException("Can't set cdr of " + this.type());
}
public ArcObject sref(ArcObject value, ArcObject index)
{
throw new NekoArcException("Can't sref" + this + "( a " + this.type() + "), other args were " + value + ", " + index);
}
public ArcObject add(ArcObject other)
{
throw new NekoArcException("add not implemented for " + this.type() + " " + this);
}
public long len()
{
throw new NekoArcException("len: expects one string, list, or hash argument");
}
public abstract ArcObject type();
public int requiredArgs()
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public int optionalArgs()
{
return(0);
}
public int extraArgs()
{
return(0);
}
public boolean variadicP()
{
return(false);
}
/** The basic apply. This should normally not be overridden. Only Closure should probably override it because it runs completely within the vm. */
- public void apply(VirtualMachine vm)
+ public void apply(VirtualMachine vm, Callable caller)
{
int minenv, dsenv, optenv;
minenv = requiredArgs();
dsenv = extraArgs();
optenv = optionalArgs();
if (variadicP()) {
int i;
vm.argcheck(minenv, -1);
ArcObject rest = Nil.NIL;
for (i = vm.argc(); i>(minenv + optenv); i--)
rest = new Cons(vm.pop(), rest);
vm.mkenv(i, minenv + optenv - i + dsenv + 1);
/* store the rest parameter */
vm.setenv(0, minenv + optenv + dsenv, rest);
} else {
vm.argcheck(minenv, minenv + optenv);
vm.mkenv(vm.argc(), minenv + optenv - vm.argc() + dsenv);
}
- InvokeThread thr = new InvokeThread(vm, this);
+ // Start the invoke thread
+ InvokeThread thr = new InvokeThread(vm, caller, this);
+ new Thread(thr).start();
- // Suspend the virtual machine thread until the invoke thread returns
- vm.setAcc(thr.sync());
+ // Suspend the caller's thread until the invoke thread returns
+ vm.setAcc(caller.caller().ret());
vm.restorecont();
}
public ArcObject invoke(InvokeThread vm)
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public String toString()
{
throw new NekoArcException("Type " + type() + " has no string representation");
}
// default implementation
public boolean is(ArcObject other)
{
return(this == other);
}
+
+ @Override
+ public Caller caller()
+ {
+ return(caller );
+ }
}
|
dido/arcueid
|
2c96b540d1bfb073696ddf69f5310ccc08da3a1e
|
calling sequence additional steps if this is not a vm internal call
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Closure.java b/java/src/org/arcueidarc/nekoarc/types/Closure.java
index 57af2ac..5739271 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Closure.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Closure.java
@@ -1,24 +1,31 @@
package org.arcueidarc.nekoarc.types;
+import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Closure extends Cons
{
public static final ArcObject TYPE = Symbol.intern("closure");
public Closure(ArcObject ca, ArcObject cd)
{
super(ca, cd);
}
/** This is the only place where apply should be overridden */
@Override
- public void apply(VirtualMachine vm)
+ public void apply(VirtualMachine vm, Callable caller)
{
ArcObject newenv, newip;
newenv = this.car();
newip = this.cdr();
vm.setIP((int)((Fixnum)newip).fixnum);
vm.setEnv(newenv);
+ // If this is not a call from the vm itself, we need to take the additional step of waking up the VM thread
+ // and causing the caller thread to sleep. Unnecessary if this is already a VM thread.
+ if (vm != caller) {
+ vm.caller().put(this); // wakes the VM so it begins executing the closure
+ vm.setAcc(caller.caller().ret()); // sleeps the caller until its JavaContinuation is restored
+ }
}
}
|
dido/arcueid
|
c01aabf7c7ec75b2680f0bb2efaf111b5394d62a
|
change to Callable object
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index 4575a54..97aced5 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -1,647 +1,657 @@
package org.arcueidarc.nekoarc.vm;
import org.arcueidarc.nekoarc.Continuation;
import org.arcueidarc.nekoarc.HeapEnv;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.Unbound;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
+import org.arcueidarc.nekoarc.util.Caller;
+import org.arcueidarc.nekoarc.util.Callable;
import org.arcueidarc.nekoarc.util.ObjectMap;
import org.arcueidarc.nekoarc.vm.instruction.*;
-public class VirtualMachine
+public class VirtualMachine implements Callable
{
private int sp; // stack pointer
private int bp; // base pointer
private ArcObject env; // environment pointer
private ArcObject cont; // continuation pointer
private ArcObject[] stack; // stack
+ private final Caller caller;
private int ip; // instruction pointer
private byte[] code;
private boolean runnable;
private ArcObject acc; // accumulator
private ArcObject[] literals;
private int argc; // argument counter for current function
private static final INVALID NOINST = new INVALID();
private static final Instruction[] jmptbl = {
new NOP(), // 0x00
new PUSH(), // 0x01
new POP(), // 0x02
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new RET(), // 0x0d
NOINST,
NOINST,
NOINST,
new NO(), // 0x11
new TRUE(), // 0x12
new NIL(), // 0x13
new HLT(), // 0x14
new ADD(), // 0x15
new SUB(), // 0x16
new MUL(), // 0x17
new DIV(), // 0x18
new CONS(), // 0x19
new CAR(), // 0x1a
new CDR(), // 0x1b
new SCAR(), // 0x1c
new SCDR(), // 0x1d
NOINST,
new IS(), // 0x1f
NOINST,
NOINST,
new DUP(), // 0x22
NOINST, // 0x23
new CONSR(), // 0x24
NOINST,
new DCAR(), // 0x26
new DCDR(), // 0x27
new SPL(), // 0x28
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDL(), // 0x43
new LDI(), // 0x44
new LDG(), // 0x45
new STG(), // 0x46
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
+ caller = new Caller();
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
// // Try to move the current continuation on the stack to the heap
// Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
// cont = nc;
// stackbottom = 0;
stackbottom = (int)((Fixnum)cont).fixnum + 1;
}
// Garbage collection failed to produce memory
if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
while (runnable) {
jmptbl[(int)code[ip++] & 0xff].invoke(this);
}
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
if (sp + 4 > stack.length) {
// Try to do stack gc first. If it fails, nothing for it
stackgc();
if (sp + 4 > stack.length)
throw new NekoArcException("stack overflow while creating continuation");
}
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
// Restore continuation
public void restorecont()
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
setEnv(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
((Continuation)cont).restore(this);
} else if (cont.is(Nil.NIL)) {
// If we have no continuation, that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
public void setEnv(ArcObject env)
{
this.env = env;
}
public int getBP()
{
return bp;
}
public void setBP(int bp)
{
this.bp = bp;
}
public ArcObject getCont()
{
return cont;
}
public void setCont(ArcObject cont)
{
this.cont = cont;
}
+
+ @Override
+ public Caller caller()
+ {
+ return(caller);
+ }
}
|
dido/arcueid
|
69846fd8c685f1e4df305e9438b8e6dbd2a35f35
|
Caller class (wrapper around SynchronousQueue)
|
diff --git a/java/src/org/arcueidarc/nekoarc/util/Caller.java b/java/src/org/arcueidarc/nekoarc/util/Caller.java
new file mode 100644
index 0000000..f1654b9
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/util/Caller.java
@@ -0,0 +1,34 @@
+package org.arcueidarc.nekoarc.util;
+
+import java.util.concurrent.SynchronousQueue;
+
+import org.arcueidarc.nekoarc.types.ArcObject;
+
+public class Caller
+{
+ private final SynchronousQueue<ArcObject> syncqueue;
+
+ public Caller()
+ {
+ syncqueue = new SynchronousQueue<ArcObject>();
+ }
+
+ public void put(ArcObject retval)
+ {
+ for (;;) {
+ try {
+ syncqueue.put(retval);
+ return;
+ } catch (InterruptedException e) { }
+ }
+ }
+
+ public ArcObject ret()
+ {
+ for (;;) {
+ try {
+ return(syncqueue.take());
+ } catch (InterruptedException e) { }
+ }
+ }
+}
|
dido/arcueid
|
fe859f3027f69b24154dfd60b6da8e9515b80fe4
|
Callable interface for anything that can be called
|
diff --git a/java/src/org/arcueidarc/nekoarc/util/Callable.java b/java/src/org/arcueidarc/nekoarc/util/Callable.java
new file mode 100644
index 0000000..06433d1
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/util/Callable.java
@@ -0,0 +1,6 @@
+package org.arcueidarc.nekoarc.util;
+
+public interface Callable
+{
+ public Caller caller();
+}
|
dido/arcueid
|
c86f84e3f40d5dda4d6e52b0c3a1d805ec379847
|
extra arg for apply
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/instruction/APPLY.java b/java/src/org/arcueidarc/nekoarc/vm/instruction/APPLY.java
index 60798ee..6dc865b 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/instruction/APPLY.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/instruction/APPLY.java
@@ -1,16 +1,16 @@
package org.arcueidarc.nekoarc.vm.instruction;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.vm.Instruction;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class APPLY implements Instruction
{
@Override
public void invoke(VirtualMachine vm) throws NekoArcException
{
vm.setargc(vm.smallInstArg());
- vm.getAcc().apply(vm);
+ vm.getAcc().apply(vm, vm);
}
}
|
dido/arcueid
|
c324a7f5ee226c5db0ef88e1a5d088a69fc0a847
|
invocation threads for running Java code
|
diff --git a/java/src/org/arcueidarc/nekoarc/InvokeThread.java b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
new file mode 100644
index 0000000..81c2c4f
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/InvokeThread.java
@@ -0,0 +1,71 @@
+package org.arcueidarc.nekoarc;
+
+import java.util.concurrent.SynchronousQueue;
+
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.types.Closure;
+import org.arcueidarc.nekoarc.vm.VirtualMachine;
+
+/** The main reason this class exists is that Java is a weak-sauce language that doesn't have closures */
+public class InvokeThread implements Runnable
+{
+ public final SynchronousQueue<ArcObject> syncqueue;
+ public final VirtualMachine vm;
+ public final ArcObject obj;
+
+ public InvokeThread(VirtualMachine vm, ArcObject obj)
+ {
+ syncqueue = new SynchronousQueue<ArcObject>();
+ this.vm = vm;
+ this.obj = obj;
+ }
+
+ @Override
+ public void run()
+ {
+ put(obj.invoke(this));
+ }
+
+ public ArcObject getenv(int i, int j)
+ {
+ return(vm.getenv(i, j));
+ }
+
+ public void put(ArcObject val)
+ {
+ for (;;) {
+ try {
+ syncqueue.put(val);
+ break;
+ } catch (InterruptedException e) {}
+ }
+ }
+
+ /** Synchronise invoke thread and virtual machine thread */
+ public ArcObject sync()
+ {
+ for (;;) {
+ try {
+ return(syncqueue.take());
+ } catch (InterruptedException e) {}
+ }
+ }
+
+ /** Perform a call to some Arc object */
+ public ArcObject apply(Closure fn, ArcObject...args)
+ {
+ // First, push all of the arguments to the stack
+ for (ArcObject arg : args)
+ vm.push(arg);
+ // new continuation
+ vm.setCont(new JavaContinuation(this, vm.getCont()));
+ // apply the closure
+ fn.apply(vm);
+ // Create a continuation that will cause the vm to begin execution right then and there
+ vm.makecont(0);
+ // cause the virtual machine thread to begin executing
+ put(fn);
+ // suspend this invoke thread until the virtual machine restores the JavaContinuation
+ return(sync());
+ }
+}
|
dido/arcueid
|
302dbc366617c4a6302c5e63e48b22224fee3458
|
continuation restoration made more consistent
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index 2a0f544..4575a54 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -101,548 +101,547 @@ public class VirtualMachine
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
// // Try to move the current continuation on the stack to the heap
// Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
// cont = nc;
// stackbottom = 0;
stackbottom = (int)((Fixnum)cont).fixnum + 1;
}
// Garbage collection failed to produce memory
if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
while (runnable) {
jmptbl[(int)code[ip++] & 0xff].invoke(this);
}
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
if (sp + 4 > stack.length) {
// Try to do stack gc first. If it fails, nothing for it
stackgc();
if (sp + 4 > stack.length)
throw new NekoArcException("stack overflow while creating continuation");
}
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
// Restore continuation
public void restorecont()
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
setEnv(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
- cont = ((Continuation)cont).restore(this);
- restorecont(); // heap continuation is now a stack continuation
+ ((Continuation)cont).restore(this);
} else if (cont.is(Nil.NIL)) {
- // If we have no continuation that was an attempt to return from the topmost
+ // If we have no continuation, that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
public void setEnv(ArcObject env)
{
this.env = env;
}
public int getBP()
{
return bp;
}
public void setBP(int bp)
{
this.bp = bp;
}
public ArcObject getCont()
{
return cont;
}
public void setCont(ArcObject cont)
{
this.cont = cont;
}
}
|
dido/arcueid
|
81d7c0223676c7dc522cc0560570f3d6b96842e2
|
continuations in Java
|
diff --git a/java/src/org/arcueidarc/nekoarc/JavaContinuation.java b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
new file mode 100644
index 0000000..4537041
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/JavaContinuation.java
@@ -0,0 +1,27 @@
+package org.arcueidarc.nekoarc;
+
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.vm.VirtualMachine;
+
+public class JavaContinuation extends Continuation
+{
+ private final ArcObject prev;
+ private final InvokeThread inv;
+
+ public JavaContinuation(InvokeThread thr, ArcObject pcont)
+ {
+ super(0);
+ prev = pcont;
+ inv = thr;
+ }
+
+ @Override
+ public void restore(VirtualMachine vm)
+ {
+ // The restoration of a Java continuation should result in the InvokeThread resuming execution while the virtual machine
+ // thread waits for it.
+ vm.setAcc(inv.sync());
+ vm.setCont(prev);
+ vm.restorecont();
+ }
+}
|
dido/arcueid
|
39e1ca7757eff573ba202ac17eef77a6189c6812
|
new invoke sig
|
diff --git a/java/src/org/arcueidarc/nekoarc/functions/Builtin.java b/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
index eda67b9..f22306b 100644
--- a/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
+++ b/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
@@ -1,55 +1,55 @@
package org.arcueidarc.nekoarc.functions;
+import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Symbol;
-import org.arcueidarc.nekoarc.vm.VirtualMachine;
public abstract class Builtin extends ArcObject
{
public static final Symbol TYPE = (Symbol) Symbol.intern("fn");
protected final String name;
protected final int rargs, eargs, oargs;
protected final boolean variadic;
protected Builtin(String name, int req, int opt, int extra, boolean va)
{
this.name = name;
rargs = req;
eargs = extra;
oargs = opt;
variadic = va;
}
protected Builtin(String name, int req)
{
this(name, req, 0, 0, false);
}
@Override
public int requiredArgs()
{
return(rargs);
}
public int optionalArgs()
{
return(oargs);
}
public int extraArgs()
{
return(eargs);
}
public boolean variadicP()
{
return(variadic);
}
- abstract protected ArcObject invoke(VirtualMachine vm);
+ public abstract ArcObject invoke(InvokeThread vm);
public ArcObject type()
{
return(TYPE);
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/functions/CCC.java b/java/src/org/arcueidarc/nekoarc/functions/CCC.java
index b1a4e76..26516bd 100644
--- a/java/src/org/arcueidarc/nekoarc/functions/CCC.java
+++ b/java/src/org/arcueidarc/nekoarc/functions/CCC.java
@@ -1,29 +1,20 @@
package org.arcueidarc.nekoarc.functions;
-import org.arcueidarc.nekoarc.Continuation;
+import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.types.ArcObject;
-import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class CCC extends Builtin
{
protected CCC()
{
super("ccc", 1);
}
@Override
- protected ArcObject invoke(VirtualMachine vm)
+ public ArcObject invoke(InvokeThread vm)
{
- ArcObject cont = vm.getCont();
- if (cont instanceof Continuation)
- return(cont);
- // Convert the stack continuation into a heap continuation and apply it to the closure arg
- cont = Continuation.fromStackCont(vm, cont);
- vm.setargc(1);
- vm.push(cont);
- vm.getenv(0, 0).apply(vm);
- // We should not get here if the passed argument was a closure. If it was another built-in, we might get here.
- return(vm.getAcc());
+ // XXX - todo
+ return null;
}
}
|
dido/arcueid
|
28f06d878c391e63b49b83dec4379e6e97092871
|
use new invoke sig
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Cons.java b/java/src/org/arcueidarc/nekoarc/types/Cons.java
index f2d5e99..2027ae6 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Cons.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Cons.java
@@ -1,99 +1,99 @@
package org.arcueidarc.nekoarc.types;
+import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
-import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Cons extends ArcObject
{
public static final ArcObject TYPE = Symbol.intern("cons");
private ArcObject car;
private ArcObject cdr;
public Cons()
{
}
public Cons(ArcObject car, ArcObject cdr)
{
this.car = car;
this.cdr = cdr;
}
@Override
public ArcObject type()
{
return(TYPE);
}
@Override
public ArcObject car()
{
return(car);
}
@Override
public ArcObject cdr()
{
return(cdr);
}
@Override
public ArcObject scar(ArcObject ncar)
{
this.car = ncar;
return(ncar);
}
@Override
public ArcObject scdr(ArcObject ncdr)
{
this.cdr = ncdr;
return(ncdr);
}
@Override
public ArcObject sref(ArcObject value, ArcObject idx)
{
Fixnum index = Fixnum.cast(idx, this);
return(nth(index.fixnum).scar(value));
}
@SuppressWarnings("serial")
static class OOB extends RuntimeException {
}
public Cons nth(long idx)
{
try {
return((Cons)nth(this, idx));
} catch (OOB oob) {
throw new NekoArcException("Error: index " + idx + " too large for list " + this);
}
}
private static ArcObject nth(ArcObject c, long idx)
{
while (idx > 0) {
if (c.cdr() instanceof Nil)
throw new OOB();
c = c.cdr();
idx--;
}
return(c);
}
@Override
public int requiredArgs()
{
return(1);
}
@Override
- protected ArcObject invoke(VirtualMachine vm)
+ public ArcObject invoke(InvokeThread thr)
{
- Fixnum idx = Fixnum.cast(vm.getenv(0, 0), this);
+ Fixnum idx = Fixnum.cast(thr.getenv(0, 0), this);
return(this.nth(idx.fixnum).car());
}
}
|
dido/arcueid
|
0f0ec10e87886af2f6be56f9978a1850ed3850b3
|
use invokethreads to run Java code on apply
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
index c0b30f4..f914beb 100644
--- a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
+++ b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
@@ -1,132 +1,111 @@
package org.arcueidarc.nekoarc.types;
-import java.util.concurrent.SynchronousQueue;
-
+import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-public abstract class ArcObject implements Runnable
+public abstract class ArcObject
{
- private SynchronousQueue<ArcObject> queue;
- private VirtualMachine vm;
-
public ArcObject car()
{
throw new NekoArcException("Can't take car of " + this.type());
}
public ArcObject cdr()
{
throw new NekoArcException("Can't take cdr of " + this.type());
}
public ArcObject scar(ArcObject ncar)
{
throw new NekoArcException("Can't set car of " + this.type());
}
public ArcObject scdr(ArcObject ncar)
{
throw new NekoArcException("Can't set cdr of " + this.type());
}
public ArcObject sref(ArcObject value, ArcObject index)
{
throw new NekoArcException("Can't sref" + this + "( a " + this.type() + "), other args were " + value + ", " + index);
}
public ArcObject add(ArcObject other)
{
throw new NekoArcException("add not implemented for " + this.type() + " " + this);
}
public long len()
{
throw new NekoArcException("len: expects one string, list, or hash argument");
}
public abstract ArcObject type();
public int requiredArgs()
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public int optionalArgs()
{
return(0);
}
public int extraArgs()
{
return(0);
}
public boolean variadicP()
{
return(false);
}
- /** The basic apply. This should normally not be overridden. Only Closure should probably override it because it sets up environments itself. */
+ /** The basic apply. This should normally not be overridden. Only Closure should probably override it because it runs completely within the vm. */
public void apply(VirtualMachine vm)
{
int minenv, dsenv, optenv;
minenv = requiredArgs();
dsenv = extraArgs();
optenv = optionalArgs();
if (variadicP()) {
int i;
vm.argcheck(minenv, -1);
ArcObject rest = Nil.NIL;
for (i = vm.argc(); i>(minenv + optenv); i--)
rest = new Cons(vm.pop(), rest);
vm.mkenv(i, minenv + optenv - i + dsenv + 1);
/* store the rest parameter */
vm.setenv(0, minenv + optenv + dsenv, rest);
} else {
vm.argcheck(minenv, minenv + optenv);
vm.mkenv(vm.argc(), minenv + optenv - vm.argc() + dsenv);
}
- queue = new SynchronousQueue<ArcObject>();
- this.vm = vm;
- // start the invoker thread
- new Thread(this).start();
- // Suspend the virtual machine thread until the invoke thread returns
- for (;;) {
- try {
- vm.setAcc(queue.take());
- vm.restorecont();
- break;
- } catch (InterruptedException e) {}
- }
- }
- public void run()
- {
- for (;;) {
- try {
- queue.put(invoke(this.vm));
- break;
- } catch (InterruptedException e) {
- }
- }
+ InvokeThread thr = new InvokeThread(vm, this);
+
+ // Suspend the virtual machine thread until the invoke thread returns
+ vm.setAcc(thr.sync());
+ vm.restorecont();
}
- protected ArcObject invoke(VirtualMachine vm)
+ public ArcObject invoke(InvokeThread vm)
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public String toString()
{
throw new NekoArcException("Type " + type() + " has no string representation");
}
// default implementation
public boolean is(ArcObject other)
{
return(this == other);
}
}
|
dido/arcueid
|
4d89f0d5c227af444aad8779550409cd2a7f3782
|
use new sig
|
diff --git a/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java b/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
index 9ba2773..4490862 100644
--- a/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
+++ b/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
@@ -1,24 +1,22 @@
package org.arcueidarc.nekoarc.functions.arith;
+import org.arcueidarc.nekoarc.InvokeThread;
import org.arcueidarc.nekoarc.functions.Builtin;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
-import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Add extends Builtin
{
public Add()
{
super("+", 0, 0, 0, true);
}
@Override
- protected ArcObject invoke(VirtualMachine vm)
+ public ArcObject invoke(InvokeThread vm)
{
- ArcObject sum = Fixnum.ZERO;
- for (int i=0; i<vm.argc(); i++)
- sum.add(vm.getenv(0, i));
- return(sum);
+ // XXX - fixme
+ return(Fixnum.get(0));
}
}
|
dido/arcueid
|
54a05543c95d911f421fe09529b0cdb57a65beb8
|
clean up continuation restoration
|
diff --git a/java/src/org/arcueidarc/nekoarc/Continuation.java b/java/src/org/arcueidarc/nekoarc/Continuation.java
index 3263b78..478fd35 100644
--- a/java/src/org/arcueidarc/nekoarc/Continuation.java
+++ b/java/src/org/arcueidarc/nekoarc/Continuation.java
@@ -1,53 +1,54 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.types.Vector;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Continuation extends Vector
{
public static final ArcObject TYPE = Symbol.intern("continuation");
public Continuation(int size)
{
super(size);
}
/**
* Restore a stack-based continuation.
*/
- public Fixnum restore(VirtualMachine vm)
+ public void restore(VirtualMachine vm)
{
Fixnum c = Fixnum.get(this.length());
for (int i=0; i<this.length(); i++)
vm.setStackIndex(i, index(i));
- return(c);
+ vm.setCont(c);
+ vm.restorecont();
}
public static Continuation fromStackCont(VirtualMachine vm, ArcObject sc)
{
int cc = (int)((Fixnum)sc).fixnum;
Continuation c = new Continuation(cc);
for (int i=0; i<cc; i++)
c.setIndex(i, vm.stackIndex(i));
return(c);
}
@Override
public int requiredArgs()
{
return(1);
}
/** The application of a continuation -- this does all the hard work of call/cc */
@Override
- protected ArcObject invoke(VirtualMachine vm)
+ public ArcObject invoke(InvokeThread thr)
{
- vm.setCont(this);
- return(vm.getenv(0, 0));
+ // XXX -- fill this in
+ return null;
}
}
|
dido/arcueid
|
fd11cde21db78567c01cb4e650069c60f787e197
|
methods to manipulate continuations
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index 9a4b901..2a0f544 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -1,634 +1,648 @@
package org.arcueidarc.nekoarc.vm;
import org.arcueidarc.nekoarc.Continuation;
import org.arcueidarc.nekoarc.HeapEnv;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.Unbound;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.util.ObjectMap;
import org.arcueidarc.nekoarc.vm.instruction.*;
public class VirtualMachine
{
private int sp; // stack pointer
private int bp; // base pointer
private ArcObject env; // environment pointer
private ArcObject cont; // continuation pointer
private ArcObject[] stack; // stack
private int ip; // instruction pointer
private byte[] code;
private boolean runnable;
private ArcObject acc; // accumulator
private ArcObject[] literals;
private int argc; // argument counter for current function
private static final INVALID NOINST = new INVALID();
private static final Instruction[] jmptbl = {
new NOP(), // 0x00
new PUSH(), // 0x01
new POP(), // 0x02
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new RET(), // 0x0d
NOINST,
NOINST,
NOINST,
new NO(), // 0x11
new TRUE(), // 0x12
new NIL(), // 0x13
new HLT(), // 0x14
new ADD(), // 0x15
new SUB(), // 0x16
new MUL(), // 0x17
new DIV(), // 0x18
new CONS(), // 0x19
new CAR(), // 0x1a
new CDR(), // 0x1b
new SCAR(), // 0x1c
new SCDR(), // 0x1d
NOINST,
new IS(), // 0x1f
NOINST,
NOINST,
new DUP(), // 0x22
NOINST, // 0x23
new CONSR(), // 0x24
NOINST,
new DCAR(), // 0x26
new DCDR(), // 0x27
new SPL(), // 0x28
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDL(), // 0x43
new LDI(), // 0x44
new LDG(), // 0x45
new STG(), // 0x46
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
- // Try to move the current continuation on the stack to the heap
- Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
- cont = nc;
- stackbottom = 0;
+// // Try to move the current continuation on the stack to the heap
+// Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
+// cont = nc;
+// stackbottom = 0;
+ stackbottom = (int)((Fixnum)cont).fixnum + 1;
}
// Garbage collection failed to produce memory
if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
- while (runnable)
+ while (runnable) {
jmptbl[(int)code[ip++] & 0xff].invoke(this);
+ }
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
if (sp + 4 > stack.length) {
// Try to do stack gc first. If it fails, nothing for it
stackgc();
if (sp + 4 > stack.length)
throw new NekoArcException("stack overflow while creating continuation");
}
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
// Restore continuation
public void restorecont()
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
setEnv(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
cont = ((Continuation)cont).restore(this);
restorecont(); // heap continuation is now a stack continuation
} else if (cont.is(Nil.NIL)) {
// If we have no continuation that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
public void setEnv(ArcObject env)
{
this.env = env;
}
- public int getBP() {
+ public int getBP()
+ {
return bp;
}
- public void setBP(int bp) {
+ public void setBP(int bp)
+ {
this.bp = bp;
}
+
+ public ArcObject getCont()
+ {
+ return cont;
+ }
+
+ public void setCont(ArcObject cont)
+ {
+ this.cont = cont;
+ }
}
|
dido/arcueid
|
e3b746266838becfc2be64cf91c25c04cb0349b9
|
add method overrides to give arity and such values
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Cons.java b/java/src/org/arcueidarc/nekoarc/types/Cons.java
index a439e50..f2d5e99 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Cons.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Cons.java
@@ -1,96 +1,99 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Cons extends ArcObject
{
public static final ArcObject TYPE = Symbol.intern("cons");
private ArcObject car;
private ArcObject cdr;
public Cons()
{
}
public Cons(ArcObject car, ArcObject cdr)
{
this.car = car;
this.cdr = cdr;
}
@Override
public ArcObject type()
{
return(TYPE);
}
@Override
public ArcObject car()
{
return(car);
}
@Override
public ArcObject cdr()
{
return(cdr);
}
@Override
public ArcObject scar(ArcObject ncar)
{
this.car = ncar;
return(ncar);
}
@Override
public ArcObject scdr(ArcObject ncdr)
{
this.cdr = ncdr;
return(ncdr);
}
@Override
public ArcObject sref(ArcObject value, ArcObject idx)
{
Fixnum index = Fixnum.cast(idx, this);
return(nth(index.fixnum).scar(value));
}
@SuppressWarnings("serial")
static class OOB extends RuntimeException {
}
public Cons nth(long idx)
{
try {
return((Cons)nth(this, idx));
} catch (OOB oob) {
throw new NekoArcException("Error: index " + idx + " too large for list " + this);
}
}
private static ArcObject nth(ArcObject c, long idx)
{
while (idx > 0) {
if (c.cdr() instanceof Nil)
throw new OOB();
c = c.cdr();
idx--;
}
return(c);
}
@Override
- public void apply(VirtualMachine vm)
+ public int requiredArgs()
+ {
+ return(1);
+ }
+
+ @Override
+ protected ArcObject invoke(VirtualMachine vm)
{
- vm.argcheck(1);
- vm.mkenv(1, 0);
Fixnum idx = Fixnum.cast(vm.getenv(0, 0), this);
- vm.setAcc(this.nth(idx.fixnum).car());
- vm.restorecont();
+ return(this.nth(idx.fixnum).car());
}
}
|
dido/arcueid
|
ee7ab45ea058abdd84f9c606e8b18ee256b0e2ec
|
closure application cleanup
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Closure.java b/java/src/org/arcueidarc/nekoarc/types/Closure.java
index 437dc69..57af2ac 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Closure.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Closure.java
@@ -1,23 +1,24 @@
package org.arcueidarc.nekoarc.types;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Closure extends Cons
{
public static final ArcObject TYPE = Symbol.intern("closure");
public Closure(ArcObject ca, ArcObject cd)
{
super(ca, cd);
}
+ /** This is the only place where apply should be overridden */
@Override
public void apply(VirtualMachine vm)
{
ArcObject newenv, newip;
newenv = this.car();
newip = this.cdr();
vm.setIP((int)((Fixnum)newip).fixnum);
vm.setEnv(newenv);
}
}
|
dido/arcueid
|
43f031dc3f1571881315c5e1814edb5a03dff7e6
|
run invoke in a separate thread
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
index ae3638d..c0b30f4 100644
--- a/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
+++ b/java/src/org/arcueidarc/nekoarc/types/ArcObject.java
@@ -1,61 +1,132 @@
package org.arcueidarc.nekoarc.types;
+import java.util.concurrent.SynchronousQueue;
+
import org.arcueidarc.nekoarc.NekoArcException;
+import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
-public abstract class ArcObject
+public abstract class ArcObject implements Runnable
{
+ private SynchronousQueue<ArcObject> queue;
+ private VirtualMachine vm;
+
public ArcObject car()
{
throw new NekoArcException("Can't take car of " + this.type());
}
public ArcObject cdr()
{
throw new NekoArcException("Can't take cdr of " + this.type());
}
public ArcObject scar(ArcObject ncar)
{
throw new NekoArcException("Can't set car of " + this.type());
}
public ArcObject scdr(ArcObject ncar)
{
throw new NekoArcException("Can't set cdr of " + this.type());
}
public ArcObject sref(ArcObject value, ArcObject index)
{
throw new NekoArcException("Can't sref" + this + "( a " + this.type() + "), other args were " + value + ", " + index);
}
public ArcObject add(ArcObject other)
{
throw new NekoArcException("add not implemented for " + this.type() + " " + this);
}
public long len()
{
throw new NekoArcException("len: expects one string, list, or hash argument");
}
public abstract ArcObject type();
+ public int requiredArgs()
+ {
+ throw new NekoArcException("Cannot invoke object of type " + type());
+ }
+
+ public int optionalArgs()
+ {
+ return(0);
+ }
+
+ public int extraArgs()
+ {
+ return(0);
+ }
+
+ public boolean variadicP()
+ {
+ return(false);
+ }
+
+ /** The basic apply. This should normally not be overridden. Only Closure should probably override it because it sets up environments itself. */
public void apply(VirtualMachine vm)
+ {
+ int minenv, dsenv, optenv;
+ minenv = requiredArgs();
+ dsenv = extraArgs();
+ optenv = optionalArgs();
+ if (variadicP()) {
+ int i;
+ vm.argcheck(minenv, -1);
+ ArcObject rest = Nil.NIL;
+ for (i = vm.argc(); i>(minenv + optenv); i--)
+ rest = new Cons(vm.pop(), rest);
+ vm.mkenv(i, minenv + optenv - i + dsenv + 1);
+ /* store the rest parameter */
+ vm.setenv(0, minenv + optenv + dsenv, rest);
+ } else {
+ vm.argcheck(minenv, minenv + optenv);
+ vm.mkenv(vm.argc(), minenv + optenv - vm.argc() + dsenv);
+ }
+ queue = new SynchronousQueue<ArcObject>();
+ this.vm = vm;
+ // start the invoker thread
+ new Thread(this).start();
+ // Suspend the virtual machine thread until the invoke thread returns
+ for (;;) {
+ try {
+ vm.setAcc(queue.take());
+ vm.restorecont();
+ break;
+ } catch (InterruptedException e) {}
+ }
+ }
+
+ public void run()
+ {
+ for (;;) {
+ try {
+ queue.put(invoke(this.vm));
+ break;
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ protected ArcObject invoke(VirtualMachine vm)
{
throw new NekoArcException("Cannot invoke object of type " + type());
}
public String toString()
{
throw new NekoArcException("Type " + type() + " has no string representation");
}
// default implementation
public boolean is(ArcObject other)
{
return(this == other);
}
}
|
dido/arcueid
|
813a96113b1961f62233c8ab3cd009a4c9c8187d
|
need to check to see if this is really all that is needed for application of continuations
|
diff --git a/java/src/org/arcueidarc/nekoarc/Continuation.java b/java/src/org/arcueidarc/nekoarc/Continuation.java
index 5cf87f6..3263b78 100644
--- a/java/src/org/arcueidarc/nekoarc/Continuation.java
+++ b/java/src/org/arcueidarc/nekoarc/Continuation.java
@@ -1,37 +1,53 @@
package org.arcueidarc.nekoarc;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.types.Vector;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Continuation extends Vector
{
public static final ArcObject TYPE = Symbol.intern("continuation");
public Continuation(int size)
{
super(size);
}
/**
* Restore a stack-based continuation.
*/
public Fixnum restore(VirtualMachine vm)
{
Fixnum c = Fixnum.get(this.length());
for (int i=0; i<this.length(); i++)
vm.setStackIndex(i, index(i));
return(c);
}
- public static Continuation fromStackCont(VirtualMachine vm, Fixnum sc)
+ public static Continuation fromStackCont(VirtualMachine vm, ArcObject sc)
{
- Continuation c = new Continuation((int)sc.fixnum);
- for (int i=0; i<sc.fixnum; i++)
+ int cc = (int)((Fixnum)sc).fixnum;
+ Continuation c = new Continuation(cc);
+ for (int i=0; i<cc; i++)
c.setIndex(i, vm.stackIndex(i));
return(c);
}
+
+
+ @Override
+ public int requiredArgs()
+ {
+ return(1);
+ }
+
+ /** The application of a continuation -- this does all the hard work of call/cc */
+ @Override
+ protected ArcObject invoke(VirtualMachine vm)
+ {
+ vm.setCont(this);
+ return(vm.getenv(0, 0));
+ }
}
|
dido/arcueid
|
0d578a4e9f257e41a4d4a613e5d10a83ca16c119
|
(incomplete) call/cc
|
diff --git a/java/src/org/arcueidarc/nekoarc/functions/CCC.java b/java/src/org/arcueidarc/nekoarc/functions/CCC.java
new file mode 100644
index 0000000..b1a4e76
--- /dev/null
+++ b/java/src/org/arcueidarc/nekoarc/functions/CCC.java
@@ -0,0 +1,29 @@
+package org.arcueidarc.nekoarc.functions;
+
+import org.arcueidarc.nekoarc.Continuation;
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.vm.VirtualMachine;
+
+public class CCC extends Builtin
+{
+ protected CCC()
+ {
+ super("ccc", 1);
+ }
+
+ @Override
+ protected ArcObject invoke(VirtualMachine vm)
+ {
+ ArcObject cont = vm.getCont();
+ if (cont instanceof Continuation)
+ return(cont);
+ // Convert the stack continuation into a heap continuation and apply it to the closure arg
+ cont = Continuation.fromStackCont(vm, cont);
+ vm.setargc(1);
+ vm.push(cont);
+ vm.getenv(0, 0).apply(vm);
+ // We should not get here if the passed argument was a closure. If it was another built-in, we might get here.
+ return(vm.getAcc());
+ }
+
+}
|
dido/arcueid
|
bd107548636a97d505f35728cefcd2e27efa39eb
|
clean up apply/invoke functions
|
diff --git a/java/src/org/arcueidarc/nekoarc/functions/Builtin.java b/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
index 678cf4b..eda67b9 100644
--- a/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
+++ b/java/src/org/arcueidarc/nekoarc/functions/Builtin.java
@@ -1,29 +1,55 @@
package org.arcueidarc.nekoarc.functions;
import org.arcueidarc.nekoarc.types.ArcObject;
-import org.arcueidarc.nekoarc.types.Cons;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.vm.VirtualMachine;
public abstract class Builtin extends ArcObject
{
public static final Symbol TYPE = (Symbol) Symbol.intern("fn");
protected final String name;
+ protected final int rargs, eargs, oargs;
+ protected final boolean variadic;
- protected Builtin(String name)
+ protected Builtin(String name, int req, int opt, int extra, boolean va)
{
this.name = name;
+ rargs = req;
+ eargs = extra;
+ oargs = opt;
+ variadic = va;
}
- abstract protected ArcObject invoke(Cons args);
+ protected Builtin(String name, int req)
+ {
+ this(name, req, 0, 0, false);
+ }
+
+ @Override
+ public int requiredArgs()
+ {
+ return(rargs);
+ }
+
+ public int optionalArgs()
+ {
+ return(oargs);
+ }
+
+ public int extraArgs()
+ {
+ return(eargs);
+ }
- public void invoke(VirtualMachine vm, Cons args)
+ public boolean variadicP()
{
- vm.setAcc(invoke(args));
+ return(variadic);
}
+ abstract protected ArcObject invoke(VirtualMachine vm);
+
public ArcObject type()
{
return(TYPE);
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java b/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
index 1bc3b29..9ba2773 100644
--- a/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
+++ b/java/src/org/arcueidarc/nekoarc/functions/arith/Add.java
@@ -1,30 +1,24 @@
package org.arcueidarc.nekoarc.functions.arith;
-import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.functions.Builtin;
import org.arcueidarc.nekoarc.types.ArcObject;
-import org.arcueidarc.nekoarc.types.Cons;
import org.arcueidarc.nekoarc.types.Fixnum;
+import org.arcueidarc.nekoarc.vm.VirtualMachine;
public class Add extends Builtin
{
public Add()
{
- super("+");
+ super("+", 0, 0, 0, true);
}
-
+
@Override
- protected ArcObject invoke(Cons args)
+ protected ArcObject invoke(VirtualMachine vm)
{
- if (args instanceof Nil)
- return(Fixnum.ZERO);
- ArcObject result = args.car();
- ArcObject rest = args.cdr();
- while (!(rest instanceof Nil)) {
- result = result.add(rest.car());
- rest = rest.cdr();
- }
- return(result);
+ ArcObject sum = Fixnum.ZERO;
+ for (int i=0; i<vm.argc(); i++)
+ sum.add(vm.getenv(0, i));
+ return(sum);
}
}
|
dido/arcueid
|
f08af3f6fe228d9c21c043f3be0d9c2212017abe
|
no need to get cute with these phantom references &c.
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Fixnum.java b/java/src/org/arcueidarc/nekoarc/types/Fixnum.java
index 12e0ffa..93183b3 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Fixnum.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Fixnum.java
@@ -1,118 +1,99 @@
package org.arcueidarc.nekoarc.types;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import org.arcueidarc.nekoarc.NekoArcException;
-import org.arcueidarc.nekoarc.util.IndexPhantomReference;
import org.arcueidarc.nekoarc.util.LongMap;
public class Fixnum extends Numeric
{
public final ArcObject TYPE = Symbol.intern("fixnum");
public final long fixnum;
private static final LongMap<WeakReference<Fixnum>> table = new LongMap<WeakReference<Fixnum>>();
private static final ReferenceQueue<Fixnum> rq = new ReferenceQueue<Fixnum>();
public static final Fixnum ZERO = get(0);
public static final Fixnum ONE = get(1);
public static final Fixnum TEN = get(10);
- static {
- // Thread that removes phantom references to fixnums
- new Thread() {
- public void run()
- {
- for (;;) {
- try {
- @SuppressWarnings("unchecked")
- IndexPhantomReference<Fixnum> ipr = (IndexPhantomReference<Fixnum>) rq.remove();
- table.remove(ipr.index);
- } catch (InterruptedException e) {
- }
- }
- }
- }.start();
- }
-
private Fixnum(long x)
{
fixnum = x;
}
public static Fixnum get(long x)
{
Fixnum f;
if (table.containsKey(x)) {
WeakReference<Fixnum> wrf = table.get(x);
f = wrf.get();
if (f != null)
return(f);
}
f = new Fixnum(x);
table.put(x, new WeakReference<Fixnum>(f, rq));
- new IndexPhantomReference<Fixnum>(f, rq, x);
return(f);
}
@Override
public ArcObject type()
{
return(TYPE);
}
public static Fixnum cast(ArcObject arg, ArcObject caller)
{
if (arg instanceof Flonum) {
return(Fixnum.get((long)((Flonum)arg).flonum));
} else if (arg instanceof Fixnum) {
return((Fixnum)arg);
}
throw new NekoArcException("Wrong argument type, caller " + caller + " expected a Fixnum, got " + arg);
}
@Override
public ArcObject add(ArcObject ae)
{
if (ae instanceof Flonum) {
Flonum fnum = Flonum.cast(this, this);
return(fnum.add(ae));
}
Fixnum addend = Fixnum.cast(ae, this);
return(Fixnum.get(this.fixnum + addend.fixnum));
}
@Override
public Numeric negate()
{
return(Fixnum.get(-this.fixnum));
}
@Override
public Numeric mul(Numeric factor)
{
if (factor instanceof Flonum) {
Flonum self = Flonum.cast(this, this);
return(self.mul(factor));
}
// note: multiplying large fixnums may have unexpected results!
Fixnum ffactor = Fixnum.cast(factor, this);
return(Fixnum.get(this.fixnum * ffactor.fixnum));
}
@Override
public Numeric div(Numeric divisor)
{
if (divisor instanceof Flonum) {
Flonum self = Flonum.cast(this, this);
return(self.div(divisor));
}
Fixnum fdivisor = Fixnum.cast(divisor, this);
return(Fixnum.get(this.fixnum / fdivisor.fixnum));
}
@Override
public String toString()
{
return(String.valueOf(fixnum));
}
}
diff --git a/java/src/org/arcueidarc/nekoarc/types/Symbol.java b/java/src/org/arcueidarc/nekoarc/types/Symbol.java
index af980e6..944418b 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Symbol.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Symbol.java
@@ -1,85 +1,64 @@
package org.arcueidarc.nekoarc.types;
-import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.True;
-import org.arcueidarc.nekoarc.util.IndexPhantomReference;
import org.arcueidarc.nekoarc.util.LongMap;
import org.arcueidarc.nekoarc.util.MurmurHash;
public class Symbol extends Atom
{
public final String symbol;
private static final LongMap<WeakReference<Symbol>> symtable = new LongMap<WeakReference<Symbol>>();
- private static final ReferenceQueue<Symbol> rq = new ReferenceQueue<Symbol>();
public static final ArcObject TYPE = Symbol.intern("sym");
- static {
- // Thread that removes phantom references to fixnums
- new Thread() {
- public void run()
- {
- for (;;) {
- try {
- @SuppressWarnings("unchecked")
- IndexPhantomReference<Symbol> ipr = (IndexPhantomReference<Symbol>) rq.remove();
- symtable.remove(ipr.index);
- } catch (InterruptedException e) {
- }
- }
- }
- }.start();
- }
-
private Symbol(String s)
{
symbol = s;
}
private static long hash(String s)
{
// return((long)s.hashCode());
return(MurmurHash.hash(s));
}
public long hash()
{
return(hash(this.symbol));
}
public static ArcObject intern(String s)
{
Symbol sym;
long hc = hash(s);
if (s.equals("t"))
return(True.T);
if (s.equals("nil"))
return(Nil.NIL);
if (symtable.containsKey(hc)) {
WeakReference<Symbol> wref = symtable.get(hc);
sym = wref.get();
if (sym != null)
return(sym);
}
sym = new Symbol(s);
symtable.put(hc, new WeakReference<Symbol>(sym));
- new IndexPhantomReference<Symbol>(sym, rq, hc);
return(sym);
}
@Override
public ArcObject type()
{
return(TYPE);
}
@Override
public String toString()
{
return(this.symbol);
}
}
|
dido/arcueid
|
cbb67e2921af9eee1566424dc71ed24df62ae6ae
|
recursive Fibonacci test
|
diff --git a/java/test/org/arcueidarc/nekoarc/vm/FibonacciTest.java b/java/test/org/arcueidarc/nekoarc/vm/FibonacciTest.java
new file mode 100644
index 0000000..b47a4dd
--- /dev/null
+++ b/java/test/org/arcueidarc/nekoarc/vm/FibonacciTest.java
@@ -0,0 +1,72 @@
+package org.arcueidarc.nekoarc.vm;
+
+import static org.junit.Assert.*;
+
+import org.arcueidarc.nekoarc.types.ArcObject;
+import org.arcueidarc.nekoarc.types.Fixnum;
+import org.arcueidarc.nekoarc.types.Closure;
+import org.arcueidarc.nekoarc.Nil;
+import org.junit.Test;
+
+public class FibonacciTest
+{
+
+ /* This is a recursive Fibonacci test, essentially (afn (x) (if (is x 0) 1 (is x 1) 1 (+ (self (- x 1)) (self (- x 2)))))
+ * Since this isn't tail recursive it runs in exponential time and will use up a lot of stack space for continuations.
+ * If we don't migrate continuations to the heap this will very quickly use up stack space if it's set low enough.
+ */
+ @Test
+ public void test()
+ {
+ // env 1 0 0; lde0 0; push; ldi 0; is; jf xxx; ldi 1; ret; lde0 0; push ldi 1; is; jf xxx; ldi 1; ret;
+ // cont xxx; lde0 0; push; ldi 1; sub; push; ldl 0; apply 1; push;
+ // cont xxx; lde0 0; push; ldi 2; sub; push; ldl 0; apply 1; add; ret
+ byte inst[] = { (byte)0xca, 0x01, 0x00, 0x00, // env 1 0 0
+ 0x69, 0x00, // lde0 0
+ 0x01, // push
+ 0x44, 0x00, 0x00, 0x00, 0x00, // ldi 0
+ 0x1f, // is
+ 0x50, 0x06, 0x00, 0x00, 0x00, // jf L1 (6)
+ 0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
+ 0x0d, // ret
+ 0x69, 0x00, // L1: lde0 0
+ 0x01, // push
+ 0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
+ 0x1f, // is
+ 0x50, 0x06, 0x00, 0x00, 0x00, // jf L2 (6)
+ 0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
+ 0x0d, // ret
+ (byte)0x89, 0x11, 0x00, 0x00, 0x00, // L2: cont L3 (0x11)
+ 0x69, 0x00, // lde0 0
+ 0x01, // push
+ 0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
+ 0x16, // sub
+ 0x01, // push
+ 0x43, 0x00, 0x00, 0x00, 0x00, // ldl 0
+ 0x4c, 0x01, // apply 1
+ 0x01, // L3: push
+ (byte)0x89, 0x11, 0x00, 0x00, 0x00, // cont L4 (0x11)
+ 0x69, 0x00, // lde0 0
+ 0x01, // push
+ 0x44, 0x02, 0x00, 0x00, 0x00, // ldi 2
+ 0x16, // sub
+ 0x01, // push
+ 0x43, 0x00, 0x00, 0x00, 0x00, // ldl 0
+ 0x4c, 0x01, // apply 1
+ 0x15, // add
+ 0x0d // ret
+ };
+ VirtualMachine vm = new VirtualMachine(12);
+ ArcObject literals[] = new ArcObject[1];
+ literals[0] = new Closure(Nil.NIL, Fixnum.get(0));
+ vm.load(inst, 0, literals);
+ vm.setargc(1);
+ vm.push(Fixnum.get(8));
+ vm.setAcc(Nil.NIL);
+ assertTrue(vm.runnable());
+ vm.run();
+ assertFalse(vm.runnable());
+ assertEquals(34, ((Fixnum)vm.getAcc()).fixnum);
+ }
+
+}
|
dido/arcueid
|
33b48bb3a7115102fc64592bfa827f8964016aef
|
try to do something about continuations on the heap
|
diff --git a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
index d2b0a8e..9a4b901 100644
--- a/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
+++ b/java/src/org/arcueidarc/nekoarc/vm/VirtualMachine.java
@@ -1,625 +1,634 @@
package org.arcueidarc.nekoarc.vm;
import org.arcueidarc.nekoarc.Continuation;
import org.arcueidarc.nekoarc.HeapEnv;
import org.arcueidarc.nekoarc.NekoArcException;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.Unbound;
import org.arcueidarc.nekoarc.types.ArcObject;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.arcueidarc.nekoarc.types.Symbol;
import org.arcueidarc.nekoarc.util.ObjectMap;
import org.arcueidarc.nekoarc.vm.instruction.*;
public class VirtualMachine
{
private int sp; // stack pointer
private int bp; // base pointer
private ArcObject env; // environment pointer
private ArcObject cont; // continuation pointer
private ArcObject[] stack; // stack
private int ip; // instruction pointer
private byte[] code;
private boolean runnable;
private ArcObject acc; // accumulator
private ArcObject[] literals;
private int argc; // argument counter for current function
private static final INVALID NOINST = new INVALID();
private static final Instruction[] jmptbl = {
new NOP(), // 0x00
new PUSH(), // 0x01
new POP(), // 0x02
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new RET(), // 0x0d
NOINST,
NOINST,
NOINST,
new NO(), // 0x11
new TRUE(), // 0x12
new NIL(), // 0x13
new HLT(), // 0x14
new ADD(), // 0x15
new SUB(), // 0x16
new MUL(), // 0x17
new DIV(), // 0x18
new CONS(), // 0x19
new CAR(), // 0x1a
new CDR(), // 0x1b
new SCAR(), // 0x1c
new SCDR(), // 0x1d
NOINST,
new IS(), // 0x1f
NOINST,
NOINST,
new DUP(), // 0x22
NOINST, // 0x23
new CONSR(), // 0x24
NOINST,
new DCAR(), // 0x26
new DCDR(), // 0x27
new SPL(), // 0x28
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDL(), // 0x43
new LDI(), // 0x44
new LDG(), // 0x45
new STG(), // 0x46
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new APPLY(), // 0x4c
new CLS(), // 0x4d,
new JMP(), // 0x4e
new JT(), // 0x4f
new JF(), // 0x50
new JBND(), // 0x51
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new MENV(), // 0x65
NOINST,
NOINST,
NOINST,
new LDE0(), // 0x69
new STE0(), // 0x6a
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new LDE(), // 0x87
new STE(), // 0x88
new CONT(), // 0x89
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
new ENV(), // 0xca
new ENVR(), // 0xcb
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
NOINST,
};
private ObjectMap<Symbol, ArcObject> genv = new ObjectMap<Symbol, ArcObject>();
public VirtualMachine(int stacksize)
{
sp = bp = 0;
stack = new ArcObject[stacksize];
ip = 0;
code = null;
runnable = true;
env = Nil.NIL;
cont = Nil.NIL;
setAcc(Nil.NIL);
}
public void load(final byte[] instructions, int ip, final ArcObject[] literals)
{
this.code = instructions;
this.literals = literals;
this.ip = ip;
}
public void load(final byte[] instructions, int ip)
{
load(instructions, ip, null);
}
public void halt()
{
runnable = false;
}
public void nextI()
{
ip++;
}
/**
* Attempt to garbage collect the stack, after Richard A. Kelsey, "Tail Recursive Stack Disciplines for an Interpreter"
* Basically, the only things on the stack that are garbage collected are environments and continuations.
* The algorithm here works by copying all environments and continuations from the stack to the heap. When that's done it will move the stack pointer
* to the top of the stack.
* 1. Start with the environment register. Move that environment and all of its children to the heap.
* 2. Continue with the continuation register. Copy the current continuation into the heap.
* 3. Compact the stack by moving the remainder of the non-stack/non-continuation elements to the heap.
*/
private void stackgc()
{
int stackbottom = -1;
if (env instanceof Fixnum) {
int si = (int)((Fixnum)env).fixnum;
stackbottom = (int)((Fixnum)stackIndex(si)).fixnum;
env = HeapEnv.fromStackEnv(this, si);
}
if (cont instanceof Fixnum) {
- stackbottom = (int)((Fixnum)cont).fixnum + 1;
+ // Try to move the current continuation on the stack to the heap
+ Continuation nc = Continuation.fromStackCont(this, (Fixnum)cont);
+ cont = nc;
+ stackbottom = 0;
}
// Garbage collection failed to produce memory
- if (stackbottom < 0 || stackbottom == bp)
+ if (stackbottom < 0 || stackbottom > stack.length || stackbottom == bp)
return;
// move what we can of the used portion of the stack to the bottom.
for (int i=0; i<sp - bp - 1; i++)
setStackIndex(stackbottom + i, stackIndex(bp + i));
sp = stackbottom + (sp - bp - 1);
bp = stackbottom;
}
public void push(ArcObject obj)
{
for (;;) {
try {
stack[sp++] = obj;
return;
} catch (ArrayIndexOutOfBoundsException e) {
// We can try to garbage collect the stack
stackgc();
if (sp >= stack.length)
throw new NekoArcException("stack overflow");
}
}
}
public ArcObject pop()
{
return(stack[--sp]);
}
public void run()
throws NekoArcException
{
while (runnable)
jmptbl[(int)code[ip++] & 0xff].invoke(this);
}
// Four-byte instruction arguments (most everything else). Little endian.
public int instArg()
{
long val = 0;
int data;
for (int i=0; i<4; i++) {
data = (((int)code[ip++]) & 0xff);
val |= data << i*8;
}
return((int)((val << 1) >> 1));
}
// one-byte instruction arguments (LDE/STE/ENV, etc.)
public byte smallInstArg()
{
return(code[ip++]);
}
public ArcObject getAcc()
{
return acc;
}
public void setAcc(ArcObject acc)
{
this.acc = acc;
}
public boolean runnable()
{
return(this.runnable);
}
public ArcObject literal(int offset)
{
return(literals[offset]);
}
public int getIP()
{
return ip;
}
public void setIP(int ip)
{
this.ip = ip;
}
public int getSP()
{
return(sp);
}
// add or replace a global binding
public ArcObject bind(Symbol sym, ArcObject binding)
{
genv.put(sym, binding);
return(binding);
}
public ArcObject value(Symbol sym)
{
if (!genv.containsKey(sym))
throw new NekoArcException("Unbound symbol " + sym);
return(genv.get(sym));
}
public int argc()
{
return(argc);
}
public int setargc(int ac)
{
return(argc = ac);
}
public void argcheck(int minarg, int maxarg)
{
if (argc() < minarg)
throw new NekoArcException("too few arguments, at least " + minarg + " required, " + argc() + " passed");
if (maxarg >= 0 && argc() > maxarg)
throw new NekoArcException("too many arguments, at most " + maxarg + " allowed, " + argc() + " passed");
}
public void argcheck(int arg)
{
argcheck(arg, arg);
}
/* Create an environment. If there is enough space on the stack, that environment will be there,
* if not, it will be created in the heap. */
public void mkenv(int prevsize, int extrasize)
{
if (sp + extrasize + 3 > stack.length) {
mkheapenv(prevsize, extrasize);
return;
}
// If there is enough space on the stack, create the environment there.
// Add the extra environment entries
for (int i=0; i<extrasize; i++)
push(Unbound.UNBOUND);
int count = prevsize + extrasize;
int envstart = sp - count;
/* Stack environments are basically Fixnum pointers into the stack. */
int envptr = sp;
push(Fixnum.get(envstart)); // envptr
push(Fixnum.get(count)); // envptr + 1
push(env); // envptr + 2
env = Fixnum.get(envptr);
bp = sp;
}
private void mkheapenv(int prevsize, int extrasize)
{
// First, convert the parent environment to a heap environment if it is not already one
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
int envstart = sp - prevsize;
// Create new heap environment and copy the environment values from the stack into it
HeapEnv nenv = new HeapEnv(prevsize + extrasize, env);
for (int i=0; i<prevsize; i++)
nenv.setEnv(i, stackIndex(envstart + i));
// Fill in extra environment entries with UNBOUND
for (int i=prevsize; i<prevsize+extrasize; i++)
nenv.setEnv(i, Unbound.UNBOUND);
bp = sp;
env = nenv;
}
/** move current environment to heap if needed */
public ArcObject heapenv()
{
if (env instanceof Fixnum)
env = HeapEnv.fromStackEnv(this, (int)((Fixnum)env).fixnum);
return(env);
}
private ArcObject findenv(int depth)
{
ArcObject cenv = env;
while (depth-- > 0 && !cenv.is(Nil.NIL)) {
if (cenv instanceof Fixnum) {
int index = (int)((Fixnum)cenv).fixnum;
cenv = stackIndex(index+2);
} else {
HeapEnv e = (HeapEnv)cenv;
cenv = e.prevEnv();
}
}
return(cenv);
}
public ArcObject getenv(int depth, int index)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(stackIndex(start+index));
}
return(((HeapEnv)cenv).getEnv(index));
}
public ArcObject setenv(int depth, int index, ArcObject value)
{
ArcObject cenv = findenv(depth);
if (cenv == Nil.NIL)
throw new NekoArcException("environment depth exceeded");
if (cenv instanceof Fixnum) {
int si = (int)((Fixnum)cenv).fixnum;
int start = (int)((Fixnum)stackIndex(si)).fixnum;
int size = (int)((Fixnum)stackIndex(si+1)).fixnum;
if (index > size)
throw new NekoArcException("stack environment index exceeded");
return(setStackIndex(start+index, value));
}
return(((HeapEnv)cenv).setEnv(index,value));
}
public ArcObject stackIndex(int index)
{
return(stack[index]);
}
public ArcObject setStackIndex(int index, ArcObject value)
{
return(stack[index] = value);
}
// Make a continuation on the stack. The new continuation is saved in the continuation register.
public void makecont(int ipoffset)
{
+ if (sp + 4 > stack.length) {
+ // Try to do stack gc first. If it fails, nothing for it
+ stackgc();
+ if (sp + 4 > stack.length)
+ throw new NekoArcException("stack overflow while creating continuation");
+ }
int newip = ip + ipoffset;
push(Fixnum.get(newip));
push(Fixnum.get(bp));
push(env);
push(cont);
cont = Fixnum.get(sp);
}
// Restore continuation
public void restorecont()
{
if (cont instanceof Fixnum) {
sp = (int)((Fixnum)cont).fixnum;
cont = pop();
setEnv(pop());
setBP((int)((Fixnum)pop()).fixnum);
setIP((int)((Fixnum)pop()).fixnum);
} else if (cont instanceof Continuation) {
cont = ((Continuation)cont).restore(this);
restorecont(); // heap continuation is now a stack continuation
} else if (cont.is(Nil.NIL)) {
// If we have no continuation that was an attempt to return from the topmost
// level and we should halt the machine.
halt();
} else {
throw new NekoArcException("invalid continuation");
}
}
public void setEnv(ArcObject env)
{
this.env = env;
}
public int getBP() {
return bp;
}
public void setBP(int bp) {
this.bp = bp;
}
}
|
dido/arcueid
|
838ffa9415f666b02c0225af6708831e95e1ddfd
|
toString added
|
diff --git a/java/src/org/arcueidarc/nekoarc/types/Vector.java b/java/src/org/arcueidarc/nekoarc/types/Vector.java
index f4704d5..9e5887a 100644
--- a/java/src/org/arcueidarc/nekoarc/types/Vector.java
+++ b/java/src/org/arcueidarc/nekoarc/types/Vector.java
@@ -1,34 +1,40 @@
package org.arcueidarc.nekoarc.types;
public class Vector extends ArcObject
{
public static final ArcObject TYPE = Symbol.intern("vector");
private ArcObject[] vec;
public Vector(int length)
{
vec = new ArcObject[length];
}
public ArcObject index(int i)
{
return(vec[i]);
}
public ArcObject setIndex(int i, ArcObject val)
{
return(vec[i] = val);
}
public int length()
{
return(vec.length);
}
@Override
public ArcObject type()
{
return(TYPE);
}
+ @Override
+ public String toString()
+ {
+ return("<" + type().toString() + ">");
+ }
+
}
|
dido/arcueid
|
d40cba1002e7ad4b60e44c031e7f6ee88256c9bd
|
refine the test further
|
diff --git a/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java b/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
index 9b2efee..61f5c3f 100644
--- a/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
+++ b/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
@@ -1,67 +1,67 @@
package org.arcueidarc.nekoarc.vm;
import static org.junit.Assert.*;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.junit.Test;
public class TailRecursionTest
{
/* This is a simple test for tail recursion. Essentially (fn (x y t) (+ ((afn (acc z) (if (is z 0) acc (self (+ acc x) (- z 1)))) 0 y) t))
* For large enough values of y the stack would overflow with garbage environments unless we do tail recursion properly. */
@Test
public void test()
{
// env 3 1 0; cont 19; ldi 0; push; lde0 1; push; cls 7; ste0 3; apply 2; push; lde0 2; add; ret;
// (note that there are no cont instructions in the second function because all calls are tail calls)
// env 2 0 0; lde0 1; push; ldi 0; is; jf xxx; lde0 0; ret; lde0 0; push; lde 1 0; add; push; lde0 1; push; ldi 1; sub; push; lde 1 2; apply 2; ret
byte inst[] = { (byte)0xca, 0x03, 0x01, 0x00, // env 3 1 0
(byte)0x89, 0x12, 0x00, 0x00, 0x00, // cont 18
0x44, 0x00, 0x00, 0x00, 0x00, // ldi 0
0x01, // push
0x69, 0x01, // lde0 1
0x01, // push
0x4d, 0x09, 0x00, 0x00, 0x00, // cls 9
0x6a, 0x03, // ste0 3
0x4c, 0x02, // apply 2
0x01, // push
0x69, 0x02, // lde0 2
0x15, // add
0x0d, // ret
(byte)0xca, 0x02, 0x00, 0x00, // env 2 0 0
0x69, 0x01, // lde0 1
0x01, // push
0x44, 0x00, 0x00, 0x00, 0x00, // ldi 0
0x1f, // is
0x50, 0x03, 0x00, 0x00, 0x00, // jf 3
0x69, 0x00, // lde0 0
0x0d, // ret
0x69, 0x00, // lde0 0
0x01, // push
(byte)0x87, 0x01, 0x00, // lde 1 0
0x15, // add
0x01, // push
0x69, 0x01, // lde0 1
0x01, // push
0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
0x16, // sub
0x01, // push
(byte)0x87, 0x01, 0x03, // lde 1 3
0x4c, 0x02, // apply 2
0x0d // ret
};
- VirtualMachine vm = new VirtualMachine(20);
+ VirtualMachine vm = new VirtualMachine(14);
vm.load(inst, 0);
vm.setargc(3);
vm.push(Fixnum.get(1)); // x
- vm.push(Fixnum.get(10000)); // y
+ vm.push(Fixnum.get(50000)); // y
vm.push(Fixnum.get(1)); // t
vm.setAcc(Nil.NIL);
assertTrue(vm.runnable());
vm.run();
assertFalse(vm.runnable());
- assertEquals(10001, ((Fixnum)vm.getAcc()).fixnum);
+ assertEquals(50001, ((Fixnum)vm.getAcc()).fixnum);
}
}
|
dido/arcueid
|
7ee8ca5b59954e15a9e08738491d8cf0cc26ca6b
|
small stack but do tail recursion a large number of times
|
diff --git a/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java b/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
index 20958ce..9b2efee 100644
--- a/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
+++ b/java/test/org/arcueidarc/nekoarc/vm/TailRecursionTest.java
@@ -1,67 +1,67 @@
package org.arcueidarc.nekoarc.vm;
import static org.junit.Assert.*;
import org.arcueidarc.nekoarc.Nil;
import org.arcueidarc.nekoarc.types.Fixnum;
import org.junit.Test;
public class TailRecursionTest
{
/* This is a simple test for tail recursion. Essentially (fn (x y t) (+ ((afn (acc z) (if (is z 0) acc (self (+ acc x) (- z 1)))) 0 y) t))
* For large enough values of y the stack would overflow with garbage environments unless we do tail recursion properly. */
@Test
public void test()
{
// env 3 1 0; cont 19; ldi 0; push; lde0 1; push; cls 7; ste0 3; apply 2; push; lde0 2; add; ret;
// (note that there are no cont instructions in the second function because all calls are tail calls)
// env 2 0 0; lde0 1; push; ldi 0; is; jf xxx; lde0 0; ret; lde0 0; push; lde 1 0; add; push; lde0 1; push; ldi 1; sub; push; lde 1 2; apply 2; ret
byte inst[] = { (byte)0xca, 0x03, 0x01, 0x00, // env 3 1 0
(byte)0x89, 0x12, 0x00, 0x00, 0x00, // cont 18
0x44, 0x00, 0x00, 0x00, 0x00, // ldi 0
0x01, // push
0x69, 0x01, // lde0 1
0x01, // push
0x4d, 0x09, 0x00, 0x00, 0x00, // cls 9
0x6a, 0x03, // ste0 3
0x4c, 0x02, // apply 2
0x01, // push
0x69, 0x02, // lde0 2
0x15, // add
0x0d, // ret
(byte)0xca, 0x02, 0x00, 0x00, // env 2 0 0
0x69, 0x01, // lde0 1
0x01, // push
0x44, 0x00, 0x00, 0x00, 0x00, // ldi 0
0x1f, // is
0x50, 0x03, 0x00, 0x00, 0x00, // jf 3
0x69, 0x00, // lde0 0
0x0d, // ret
0x69, 0x00, // lde0 0
0x01, // push
(byte)0x87, 0x01, 0x00, // lde 1 0
0x15, // add
0x01, // push
0x69, 0x01, // lde0 1
0x01, // push
0x44, 0x01, 0x00, 0x00, 0x00, // ldi 1
0x16, // sub
0x01, // push
(byte)0x87, 0x01, 0x03, // lde 1 3
0x4c, 0x02, // apply 2
0x0d // ret
};
- VirtualMachine vm = new VirtualMachine(21);
+ VirtualMachine vm = new VirtualMachine(20);
vm.load(inst, 0);
vm.setargc(3);
vm.push(Fixnum.get(1)); // x
- vm.push(Fixnum.get(2)); // y
+ vm.push(Fixnum.get(10000)); // y
vm.push(Fixnum.get(1)); // t
vm.setAcc(Nil.NIL);
assertTrue(vm.runnable());
vm.run();
assertFalse(vm.runnable());
- assertEquals(3, ((Fixnum)vm.getAcc()).fixnum);
+ assertEquals(10001, ((Fixnum)vm.getAcc()).fixnum);
}
}
|
perigrin/sac_camp
|
3bee487abcdb44d52f51c1cf657b7b1a1239e3e9
|
add flyer, and update signup form
|
diff --git a/2009_summer_camp_flyer.psd b/2009_summer_camp_flyer.psd
new file mode 100644
index 0000000..2c20a50
Binary files /dev/null and b/2009_summer_camp_flyer.psd differ
diff --git a/signup_form.mdown b/signup_form.mdown
index d92e55c..9c68ea9 100644
--- a/signup_form.mdown
+++ b/signup_form.mdown
@@ -1,172 +1,172 @@
<style>
body { width: 8.5in; height: 11in; }
label {
width: 8em;
float: left;
margin-right: 0.5em;
display: block;
}
input {
border: 0px;
border-bottom: 1px solid;
}
p { margin: 0px;}
legend { font-size: 125%; font-weight: bold;}
#mother_info {
width: 4in;
float: left;
}
#father_info {
width: 4in;
float: right;
}
fieldset { margin-top: 1ex; border: 1px solid silver }
th { text-align: left;}
td { margin-top: 5em;}
h3 { margin: 0px;}
</style>
# Weekly Signup Form
Complete this form to notify us of the weeks your child will be attending
camp. There is no limit on the number of weeks your child can attend.
<fieldset>
<label for="child's_name">Child's Name</label>
<input type="text" name="child's_name" value="" id="child's_name">
</fieldset>
## Camp Schedule
<fieldset>
<table width="90%">
<tr>
<th>Dates</th>
<th>Description</th>
<th style="text-align: center">Initials</th>
</tr>
<tr>
<td>Jun 8-12</td>
<td style="width: 30em">
<h3>Board Game Design</h3>
<p> We will explore different board game concepts and will design
our own from the pieces to the box. </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Jun 15-19</td>
<td style="width: 30em">
<h3>History through Art, Print and Drawing</h3>
- <p>Explore artists and their techiques. This calss will take an
+ <p>Explore artists and their techniques. This class will take an
exploratory approach to art history and appreciation as we learn
- old and new techniques for making art.</p>
+ old and new techniques for making art. </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Jun 22-26</td>
<td style="width: 30em">
<h3>Potter's Wheel and Sculpture</h3>
<p> Explore the potter's wheel as well as sculpture in this
exciting week of spin spin spinning! We will start with the bowl
form on the wheel. More experienced students will have the
opportunity to learn more advanced forms. In sculpture we will
explore hand building with clay as well as other mediums. </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Jun 29-July 3</td>
<td style="width: 30em">
<h3>Mosaic Art</h3>
<p> Learn the ancient art of mosaics, incorporating broken pottery
and other recycled materials. This class will explore different
mosaic techniques.</p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>July 6 - 10</td>
<td style="width: 30em">
<h3>Book Design, Print Making, Drawing</h3>
<p>Write, design and bind your own book Work with artists to combine
your ideas, images, and stories into amazing one of a kind books.
This camp will include elements of writing, design, drawing and
printmaking.</p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>July 13 - 17</td>
<td style="width: 30em">
<h3>Board Game Design</h3>
<p> We will explore different board game concepts and will design
our own from the pieces to the box. </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>July 20-24</td>
<td style="width: 30em">
<h3>History through Art, Print and Drawing</h3>
- <p>Explore artists and their techiques. This calss will take an
+ <p>Explore artists and their techniques. This class will take an
exploratory approach to art history and appreciation as we learn
- old and new techniques for making art.</p>
+ old and new techniques for making art. </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>July 27-31</td>
<td style="width: 30em">
<h3>Potter's Wheel and Clay Boxes</h3>
<p> Explore the potter's wheel as well as sculpture in this
exciting week of spin spin spinning! We will start with the bowl
form on the wheel. More experienced students will have the
opportunity to learn more advanced forms. In boxes kids will
sculpt boxes out of slabs for all their cool stuff! </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Aug 3-7</td>
<td style="width: 30em">
<h3>Book Design, Print Making, Drawing</h3>
<p>Write, design and bind your own book Work with artists to combine
your ideas, images, and stories into amazing one of a kind books.
This camp will include elements of writing, design, drawing and
printmaking.</p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Aug 10-14</td>
<td style="width: 30em">
<h3>Mosaic Art</h3>
<p> Learn the ancient art of mosaics, incorporating broken pottery
and other recycled materials. This class will explore different
mosaic techniques.</p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
<tr>
<td>Aug 17-21</td>
<td style="width: 30em">
<h3>Potter's Wheel and Jars</h3>
<p> Explore the potter's wheel as well as sculpture in this
exciting week of spin spin spinning! We will start with the bowl
form on the wheel. More experienced students will have the
opportunity to learn more advanced forms. In boxes kids will
sculpt jars out of pinch pot coils the way the ancients did! </p>
</td>
<td valign="bottom" align="center"><input type="text" name="inital" value="" size="3" id="inital"></td>
</tr>
</table>
</fieldset>
<fieldset>
<p><label for="signature">Signature</label><input type="text/submit/hidden/button" name="signature" value="" id="signature"></p>
<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
<p><label for="witness">Witness Signature</label><input type="text/submit/hidden/button" name="witness" value="" id="witness"></p>
<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
</fieldset>
\ No newline at end of file
|
perigrin/sac_camp
|
2919b9b130cbecb690012d3cff0d7f18b12f6958
|
changes from jamie
|
diff --git a/injury_illness_form.mdown b/injury_illness_form.mdown
index a1aacad..f5c1d65 100644
--- a/injury_illness_form.mdown
+++ b/injury_illness_form.mdown
@@ -1,63 +1,63 @@
<style>
body { width: 8.5in; height: 11in; }
label {
width: 8em;
float: left;
text-align: right;
margin-right: 0.5em;
display: block;
}
-
input {
border: 0px;
border-bottom: 1px solid;
}
p { margin: 0px;}
legend { font-size: 125%; font-weight: bold;}
#mother_info {
width: 4in;
float: left;
}
#father_info {
width: 4in;
float: right;
}
fieldset { margin-top: 1ex; border: 1px solid silver }
</style>
+
<fieldset>
<label for="child's_name">Child's Name</label>
<input type="text" name="child's_name" value="" id="child's_name">
</fieldset>
# Injury/Illness Form
Thank you for participating in our Summer Camp program this year! An
-accidnet/ndicent report will be completed for ***All*** illness and injuries.
-__A copy of this report will be attached to your child's registration card so
-that you will have it for your records__
+accident/incident report will be completed for ***All*** illness and injuries.
+*A copy of this report will be attached to your child's registration card so
+that you will have it for your records*
## Contact Information
Numbers will be called in the order they appear here:
<fieldset>
<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
</fieldset>
<fieldset>
<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
</fieldset>
<fieldset>
<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
</fieldset>
<fieldset>
<p><label for="signature">Signature</label><input type="text/submit/hidden/button" name="signature" value="" id="signature"></p>
<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
<p><label for="witness">Witness Signature</label><input type="text/submit/hidden/button" name="witness" value="" id="witness"></p>
<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
</fieldset>
\ No newline at end of file
diff --git a/minor_waver.mdown b/minor_waver.mdown
index 6b8da44..3b09582 100644
--- a/minor_waver.mdown
+++ b/minor_waver.mdown
@@ -1,36 +1,40 @@
+<style>
+input {
+ border: 0px;
+ border-bottom: 1px solid;
+}
+</style>
# Minor Child Agreement and Waver
-> The undersigned parent (or legal guardian) of ______________________ , a
+> The undersigned parent (or legal guardian) of <input type="text"> , a
> minor child, herby consents to participation of said child in all
-> Super Awesome Cool activities (Programs(s)), including but not limited
-> to, [x] and field trips with our without transportation provided by
-> Super Awesome Cool. I do hereby acknowledge and agree that the named
-> minor child must be ____ (__) years old or older to participated in any
-> Program. In the event that the minor child should sustain emergency injuries
-> or illness while participating in the programs, I do hear by
-> authorized Super Awesome Cool to administer, or cause to be
-> administered such first aid or other treatment as may be necessary
-> under the circumstances, to include treatment by a physician or
-> hospital if the parent or guardian is not available. Any such firs aid
-> or treatment is expressly limited to emergency situations and is
-> expressly understood that, except as provided herein, Super Awesome Cool
-> will not provide, or be responsible for the provision of, medicine of
-> any kind to the minor child.
+> Super Awesome Cool activities (Programs(s)) I do hereby acknowledge and
+> agree that the named minor child must be <input type="text" size="2">
+> years old or older to participated in any Program. In the event that
+> the minor child should sustain emergency injuries or illness while
+> participating in the programs, I do hear by authorized Super Awesome
+> Cool to administer, or cause to be administered such first aid or
+> other treatment as may be necessary under the circumstances, to
+> include treatment by a physician or hospital if the parent or guardian
+> is not available. Any such first aid or treatment is expressly limited
+> to emergency situations and is expressly understood that, except as
+> provided herein, Super Awesome Cool will not provide, or be
+> responsible for the provision of, medicine of any kind to the minor child.
> In consideration of the services to be performed by Super Awesome Cool and the
> participation of the minor child in Programs, the parent/legal guardian, on
> behalf of himself an the minor child, their heirs, assigns and agents does
> hereby agree to indemnify and hold harmless Super Awesome Cool, it's
> employees, officers, agents, servants and volunteers from and against any and
> all claims demands or liability for loss, expense, damage or injury of any
> nature, kind or amount whatsoever to person or property resulting in any way
> form or fashion and arising directly or indirectly from or connected with any
> and all participation in the Programs. I further authorize agree and consent
> to the use by Super Awesome Cool or its assigns and agents, of any
> photographs, recordings, video or pictures of any kind depicting the minor
> child participating in the Programs.
-Initial: ___ I have received and will read the information contained in the
-2009 camp manual which includes the registration and payment policy. I will
-review this information with my child and we will abide by the polices set by
-Super Awesome Cool.
\ No newline at end of file
+Initial: <input type="text" size="3"> I have received and will read the
+information contained in the 2009 camp manual which includes the registration
+and payment policy. I will review this information with my child and we will
+abide by the polices set by Super Awesome Cool.
\ No newline at end of file
diff --git a/registration_packet_fees.mdown b/registration_packet_fees.mdown
index 43e4957..ed8c0e8 100644
--- a/registration_packet_fees.mdown
+++ b/registration_packet_fees.mdown
@@ -1,154 +1,135 @@
# Registration
Super Awesome Cool program participants under the age of 18 ***must*** have a
waiver signed by a parent or legal guardian. Court sealed guardianship papers
or notarized Power of Attorney forms are acceptable forms of legal
guardianship. Stepparents, grandparents, etc., without and acceptable form of
documentation, will not be allowed to register under-age participants. If
there are any changes in your family's information during the camp, please let
us know so we may update our records.
# Fees
Weekly/Child
-* 1st Child - $70.00
-* 2nd Child - $65.0
-* 3rd or More - $60.00
+* 1st Child - $90.00
+* 2nd Child - $81.0
-Each child picked up after 6pm is subject to a late fee: The time of pickup is
+Each child picked up after 12 pm is subject to a late fee: The time of pickup is
noted by the Supervisor on duty and is official Super Awesome Cool time.
-6:01 - 6:15pm -- you owe $10.00/child
-6:16 - 6:30pm -- you owe $20.00/child
-6:31 - 6:45pm -- you owe $30.00/child
-6:46 - 7:00pm -- you owe $40.00/child
+If your child is picked up after 12:10 the person picking them up is subject to a $1 a minute late fee
Late fees must be paid at the time of pick up and is payable directly to to
the counselor. Determination of the late fees will be based on the Super
Awesome Cool time clock. We understand that some situations, such as traffic
or emergencies, are beyond your control. Unfortunately, we have to charge a
late fee on ***ALL*** late pick-ups, no exceptions. Please make sure you have
people listed on your child's registration card that you authorized to pick up
your child if you are running late.
-## Refunds and Transfers
-
-Requests for refunds or transfers are limited to ***family or medical
-emergecies or summer school ONLY*** and need to be submitted in writing along
-with the appropriate documentation. A $10.00 administratoive fee will be
-retained from all refunds.
-
-***We will not issue refunds or transfers for suspension or expulson. No
-Exception.***
# Hours of Operation
-[% Hours Table %]
+[% 9am-12pm %]
# Sign In and Sign Out
All youth campers must be **signed in** and **out** by their
-parents/guardians. Teen campers may sign themselves in but must be signed out
-by an adult listed on their card. Sign out is for the safety of all the
-children. if there is ANY chance of someone picking up your child the MUSt be
+parents/guardians. Sign out is for the safety of all the
+children. if there is ANY chance of someone picking up your child they mustt be
listed on the registration card.
***NO CAMPER WILL BE RELEASED TO A PERSON THAT IS NOT LISTED ON THE
REGISTRATION CARD***
**We require photo I.D. from everyone picking up a camper. Make sure you have
your I.D . ready.**
# What to Wear and What to Bring
-During a typical camp day, group swill rotate indoors and outdoors through
+During a typical camp day, groups will rotate indoors and outdoors through
variety of activities. It is recommended that your child wear old clothing due
-to the arts and crafts nature of our program. Hats are encouraged for outdoor
+to the messy nature of our program. Hats are encouraged for outdoor
activities. If your child(ren) has brought extra clothing, towels, etc.
please be sure to take them home daily.
-**Please give your child a water bottle with your child's name written on i
-tin permanent ink.** We want to be sure all campers stay properly hydrated in
+**Please give your child a water bottle with your child's name written on it
+in permanent ink.** We want to be sure all campers stay properly hydrated in
the summer heat.
**For the safey and well being of all, participants in the summer camp
programs will follow the guidelines set below:**
1. All clothing shall be neat, clean and acceptable in repair and appearance
and shall be worn within the bounds of decency and good taste.
2. Articles of clothing which display profanity, products or slogans which
promote controlled substances, are sexual in nature or are in any other way
distracting, are prohibited.
3. Excessively baggy or tight clothing and clothing which advertises gang
symbols or affiliation is prohibited.
4. Items of clothing which expose bare midriffs, bare chests, undergarments or
are transparent (see-through) are prohibited. Tank tops with straps wider
than one inch are permitted. Please be advised that spaghetti straps,
shirts which expose a bare back, halter tops, and tube tops are prohibited.
5. Excessive accessories such as hanging chains and hanging suspenders are not
allowed.
6. All shoes must fully cover the toe and heel. Sandals, flip-flops, clogs, or
other styles that do not completely cover the foot are not allowed.
Tennis/athletic style shoes must be worn daily.
8. Any item of clothing deemed unsuitable for Camp by a member of staff is
prohibited.
If any camper is not following the dress code, the parent/guardian will be
called for a change of clothes. Repeated violations of the dress code can
result in suspension and/or expulsion from camp.
# Items Not Allowed at Camp
Super Awesome Cool assumes no responsbility for the loss of camper's
-belongings. Lost and found items will be disposed of ***EVERY FRIDAY***. Pleae
+belongings. Lost and found items will be disposed of ***EVERY FRIDAY***. Please
check your child's backpack to ensure that they are not bringing inappropriate
items to camp. **We reserve the right to search children's belongings**
***Please do not allow your child(ren) to bring any items including but not
limited to***:
* Radios, CD Players, MP3 players, iPods, or CDs.
* Hand-held games (Gameboy, PSP, etc)
* Skateboards or skates
* NO SHOES WITH WHEELS PERMITTED AT ANY TIME
* Purses, wallets
* Valuable jewelry
-* Toys of any ind
+* Toys of any kind
* collector cards
* Gum
* NO MONEY ALLOWED AT ANY TIME
* Any item that may cause harm to another person
* Any item of value
***PLEASE DO NOT SEND CHILDREN TO CAMP WITH CELL PHONES***
***All Cellphones will be taken away immediately***
Cell phones are a high cost item and there is no need for them. Staff members
will always be able to contact each other at all times. Should your child
*need* to contact you, a phone will be available. If there is an emergency,
-please contact [???].
-
-# Movies
-**We will show movies at camp that are rated G and PG.**
+please contact [407-452-2452].
-If there are any movies you do not feel comfortable letting your child watch,
-please let us know.
# Medicine
-Neccessary prescription medications can be brought to camp and given directly to [???] for safe storage and administration. Over the counter medication **will not** be accepted.
+Neccessary prescription medications can be brought to camp and given directly to The lead councelro for safe storage and administration. Over the counter medication **will not** be accepted.
Medication must adhere to the following guidelines:
1. Medications must be in the original container
2. Medications must be labeled with the child's name, physician's name, and
prescribed dosage or written orders from the physician.
3. Medications must be brought to camp and picked up by parent or responsible
adult
4. Appropriate authorization form must be completed before medication will be
administered.
\ No newline at end of file
|
perigrin/sac_camp
|
e42abe8ad708300ead1a1dc9b9b5d2608c4c6082
|
finish up the forms
|
diff --git a/injury_illness_form.mdown b/injury_illness_form.mdown
new file mode 100644
index 0000000..a1aacad
--- /dev/null
+++ b/injury_illness_form.mdown
@@ -0,0 +1,63 @@
+<style>
+ body { width: 8.5in; height: 11in; }
+ label {
+ width: 8em;
+ float: left;
+ text-align: right;
+ margin-right: 0.5em;
+ display: block;
+ }
+
+ input {
+ border: 0px;
+ border-bottom: 1px solid;
+ }
+ p { margin: 0px;}
+
+ legend { font-size: 125%; font-weight: bold;}
+ #mother_info {
+ width: 4in;
+ float: left;
+ }
+ #father_info {
+ width: 4in;
+ float: right;
+ }
+ fieldset { margin-top: 1ex; border: 1px solid silver }
+</style>
+<fieldset>
+<label for="child's_name">Child's Name</label>
+<input type="text" name="child's_name" value="" id="child's_name">
+</fieldset>
+# Injury/Illness Form
+
+Thank you for participating in our Summer Camp program this year! An
+accidnet/ndicent report will be completed for ***All*** illness and injuries.
+__A copy of this report will be attached to your child's registration card so
+that you will have it for your records__
+
+## Contact Information
+Numbers will be called in the order they appear here:
+
+<fieldset>
+<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
+<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
+<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
+</fieldset>
+<fieldset>
+<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
+<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
+<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
+</fieldset>
+<fieldset>
+<p><label for="name">Name</label><input type="text/submit/hidden/button" name="name" value="" id="name"></p>
+<p><label for="phone">Phone</label><input type="text/submit/hidden/button" name="phone" value="" id="phone"></p>
+<p><label for="relationship">Relationship</label><input type="text/submit/hidden/button" name="relationship" value="" id="relationship"></p>
+</fieldset>
+
+<fieldset>
+<p><label for="signature">Signature</label><input type="text/submit/hidden/button" name="signature" value="" id="signature"></p>
+<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
+<p><label for="witness">Witness Signature</label><input type="text/submit/hidden/button" name="witness" value="" id="witness"></p>
+<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
+</fieldset>
\ No newline at end of file
diff --git a/registration_packet_fees.mdown b/registration_packet_fees.mdown
index 8368303..43e4957 100644
--- a/registration_packet_fees.mdown
+++ b/registration_packet_fees.mdown
@@ -1,34 +1,154 @@
# Registration
Super Awesome Cool program participants under the age of 18 ***must*** have a
waiver signed by a parent or legal guardian. Court sealed guardianship papers
or notarized Power of Attorney forms are acceptable forms of legal
guardianship. Stepparents, grandparents, etc., without and acceptable form of
documentation, will not be allowed to register under-age participants. If
there are any changes in your family's information during the camp, please let
us know so we may update our records.
# Fees
Weekly/Child
* 1st Child - $70.00
* 2nd Child - $65.0
* 3rd or More - $60.00
Each child picked up after 6pm is subject to a late fee: The time of pickup is
noted by the Supervisor on duty and is official Super Awesome Cool time.
6:01 - 6:15pm -- you owe $10.00/child
6:16 - 6:30pm -- you owe $20.00/child
6:31 - 6:45pm -- you owe $30.00/child
6:46 - 7:00pm -- you owe $40.00/child
Late fees must be paid at the time of pick up and is payable directly to to
the counselor. Determination of the late fees will be based on the Super
Awesome Cool time clock. We understand that some situations, such as traffic
or emergencies, are beyond your control. Unfortunately, we have to charge a
late fee on ***ALL*** late pick-ups, no exceptions. Please make sure you have
people listed on your child's registration card that you authorized to pick up
-your child if you are running late.
\ No newline at end of file
+your child if you are running late.
+
+
+## Refunds and Transfers
+
+Requests for refunds or transfers are limited to ***family or medical
+emergecies or summer school ONLY*** and need to be submitted in writing along
+with the appropriate documentation. A $10.00 administratoive fee will be
+retained from all refunds.
+
+***We will not issue refunds or transfers for suspension or expulson. No
+Exception.***
+
+# Hours of Operation
+
+[% Hours Table %]
+
+# Sign In and Sign Out
+
+All youth campers must be **signed in** and **out** by their
+parents/guardians. Teen campers may sign themselves in but must be signed out
+by an adult listed on their card. Sign out is for the safety of all the
+children. if there is ANY chance of someone picking up your child the MUSt be
+listed on the registration card.
+
+***NO CAMPER WILL BE RELEASED TO A PERSON THAT IS NOT LISTED ON THE
+REGISTRATION CARD***
+
+**We require photo I.D. from everyone picking up a camper. Make sure you have
+your I.D . ready.**
+
+# What to Wear and What to Bring
+
+During a typical camp day, group swill rotate indoors and outdoors through
+variety of activities. It is recommended that your child wear old clothing due
+to the arts and crafts nature of our program. Hats are encouraged for outdoor
+activities. If your child(ren) has brought extra clothing, towels, etc.
+please be sure to take them home daily.
+
+**Please give your child a water bottle with your child's name written on i
+tin permanent ink.** We want to be sure all campers stay properly hydrated in
+the summer heat.
+
+**For the safey and well being of all, participants in the summer camp
+programs will follow the guidelines set below:**
+
+1. All clothing shall be neat, clean and acceptable in repair and appearance
+ and shall be worn within the bounds of decency and good taste.
+2. Articles of clothing which display profanity, products or slogans which
+ promote controlled substances, are sexual in nature or are in any other way
+ distracting, are prohibited.
+3. Excessively baggy or tight clothing and clothing which advertises gang
+ symbols or affiliation is prohibited.
+4. Items of clothing which expose bare midriffs, bare chests, undergarments or
+ are transparent (see-through) are prohibited. Tank tops with straps wider
+ than one inch are permitted. Please be advised that spaghetti straps,
+ shirts which expose a bare back, halter tops, and tube tops are prohibited.
+5. Excessive accessories such as hanging chains and hanging suspenders are not
+ allowed.
+6. All shoes must fully cover the toe and heel. Sandals, flip-flops, clogs, or
+ other styles that do not completely cover the foot are not allowed.
+ Tennis/athletic style shoes must be worn daily.
+8. Any item of clothing deemed unsuitable for Camp by a member of staff is
+ prohibited.
+
+If any camper is not following the dress code, the parent/guardian will be
+called for a change of clothes. Repeated violations of the dress code can
+result in suspension and/or expulsion from camp.
+
+# Items Not Allowed at Camp
+
+Super Awesome Cool assumes no responsbility for the loss of camper's
+belongings. Lost and found items will be disposed of ***EVERY FRIDAY***. Pleae
+check your child's backpack to ensure that they are not bringing inappropriate
+items to camp. **We reserve the right to search children's belongings**
+
+***Please do not allow your child(ren) to bring any items including but not
+limited to***:
+
+* Radios, CD Players, MP3 players, iPods, or CDs.
+* Hand-held games (Gameboy, PSP, etc)
+* Skateboards or skates
+* NO SHOES WITH WHEELS PERMITTED AT ANY TIME
+* Purses, wallets
+* Valuable jewelry
+* Toys of any ind
+* collector cards
+* Gum
+* NO MONEY ALLOWED AT ANY TIME
+* Any item that may cause harm to another person
+* Any item of value
+
+***PLEASE DO NOT SEND CHILDREN TO CAMP WITH CELL PHONES***
+***All Cellphones will be taken away immediately***
+
+Cell phones are a high cost item and there is no need for them. Staff members
+will always be able to contact each other at all times. Should your child
+*need* to contact you, a phone will be available. If there is an emergency,
+please contact [???].
+
+# Movies
+**We will show movies at camp that are rated G and PG.**
+
+If there are any movies you do not feel comfortable letting your child watch,
+please let us know.
+
+# Medicine
+
+Neccessary prescription medications can be brought to camp and given directly to [???] for safe storage and administration. Over the counter medication **will not** be accepted.
+
+Medication must adhere to the following guidelines:
+
+1. Medications must be in the original container
+2. Medications must be labeled with the child's name, physician's name, and
+ prescribed dosage or written orders from the physician.
+3. Medications must be brought to camp and picked up by parent or responsible
+ adult
+4. Appropriate authorization form must be completed before medication will be
+ administered.
+
+
\ No newline at end of file
diff --git a/signup_form.mdown b/signup_form.mdown
new file mode 100644
index 0000000..e41debc
--- /dev/null
+++ b/signup_form.mdown
@@ -0,0 +1,60 @@
+<style>
+ body { width: 8.5in; height: 11in; }
+ label {
+ width: 8em;
+ float: left;
+ text-align: right;
+ margin-right: 0.5em;
+ display: block;
+ }
+
+ input {
+ border: 0px;
+ border-bottom: 1px solid;
+ }
+ p { margin: 0px;}
+
+ legend { font-size: 125%; font-weight: bold;}
+ #mother_info {
+ width: 4in;
+ float: left;
+ }
+ #father_info {
+ width: 4in;
+ float: right;
+ }
+ fieldset { margin-top: 1ex; border: 1px solid silver }
+</style>
+<fieldset>
+<label for="child's_name">Child's Name</label>
+<input type="text" name="child's_name" value="" id="child's_name">
+</fieldset>
+# Weekly Signup Form
+
+Complete this form to notify us of the weeks your child will be attending
+camp. There is no limit on the number of weeks your child can attend.
+
+<table width="90%">
+ <tr>
+ <th>Week</th>
+ <th>Dates</th>
+ <th>Initial</th>
+ </tr>
+ <tr>
+ <td>1</td>
+ <td>[% dates %]</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>2</td>
+ <td>[% dates %]</td>
+ <td></td>
+ </tr>
+</table>
+
+<fieldset>
+<p><label for="signature">Signature</label><input type="text/submit/hidden/button" name="signature" value="" id="signature"></p>
+<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
+<p><label for="witness">Witness Signature</label><input type="text/submit/hidden/button" name="witness" value="" id="witness"></p>
+<p><label for="date">Date</label><input type="text/submit/hidden/button" name="date" value="" id="date"></p>
+</fieldset>
\ No newline at end of file
|
perigrin/sac_camp
|
941e0c12eb201071534e93340f712e3993289127
|
add registration & fees document
|
diff --git a/registration_packet_fees.mdown b/registration_packet_fees.mdown
new file mode 100644
index 0000000..8368303
--- /dev/null
+++ b/registration_packet_fees.mdown
@@ -0,0 +1,34 @@
+# Registration
+
+Super Awesome Cool program participants under the age of 18 ***must*** have a
+waiver signed by a parent or legal guardian. Court sealed guardianship papers
+or notarized Power of Attorney forms are acceptable forms of legal
+guardianship. Stepparents, grandparents, etc., without and acceptable form of
+documentation, will not be allowed to register under-age participants. If
+there are any changes in your family's information during the camp, please let
+us know so we may update our records.
+
+# Fees
+
+
+Weekly/Child
+
+* 1st Child - $70.00
+* 2nd Child - $65.0
+* 3rd or More - $60.00
+
+Each child picked up after 6pm is subject to a late fee: The time of pickup is
+noted by the Supervisor on duty and is official Super Awesome Cool time.
+
+6:01 - 6:15pm -- you owe $10.00/child
+6:16 - 6:30pm -- you owe $20.00/child
+6:31 - 6:45pm -- you owe $30.00/child
+6:46 - 7:00pm -- you owe $40.00/child
+
+Late fees must be paid at the time of pick up and is payable directly to to
+the counselor. Determination of the late fees will be based on the Super
+Awesome Cool time clock. We understand that some situations, such as traffic
+or emergencies, are beyond your control. Unfortunately, we have to charge a
+late fee on ***ALL*** late pick-ups, no exceptions. Please make sure you have
+people listed on your child's registration card that you authorized to pick up
+your child if you are running late.
\ No newline at end of file
|
perigrin/sac_camp
|
28b2a3a726050be7a059c4ea0a0dacc5888346cc
|
add britannic bold version
|
diff --git a/sac_card_britannic.psd b/sac_card_britannic.psd
new file mode 100644
index 0000000..0978ed3
Binary files /dev/null and b/sac_card_britannic.psd differ
|
perigrin/sac_camp
|
48cc90bccd10bd38a72fe8ef49d3904d4292dcdc
|
add sac card
|
diff --git a/sac_card.psd b/sac_card.psd
new file mode 100644
index 0000000..cf4cb00
Binary files /dev/null and b/sac_card.psd differ
|
perigrin/sac_camp
|
f2bbce223f0bd248660afe6f632c397b3650054e
|
add registration card
|
diff --git a/registraion_card.mdown b/registraion_card.mdown
new file mode 100644
index 0000000..f97abc2
--- /dev/null
+++ b/registraion_card.mdown
@@ -0,0 +1,43 @@
+# Information Waver Card - PLEASE PRINT
+<style>
+ body { width: 8.5in; height: 5.5in; }
+ label { display: run-in; padding-right: 3ex; }
+ input { border: 0px; border-bottom: 1px solid; }
+ h2 { font-size: 100%;}
+ #mother_info { float: left; width: 45%; border-right: 1px solid; margin-right: 2%;}
+
+</style>
+
+<label for="camper_name">Camper Name</label><input type="text/submit/hidden/button" name="camper_name" value="" id="camper_name">
+Male: <input type="radio" name="camper_male" group="gender" value="" id="camper_male">
+Female: <input type="radio" name="camper_female" group="gender" value="" id="camper_female">
+<label for="camper_birthdate">Camper Birthdate</label><input type="text" name="camper_birthdate" value="01/01/01" width="8" id="camper_birthdate">
+<label for="resides_with">Child Resides With</label> <input type="text" name="resides_with" value="" id="resides_with">
+
+<div id="mother_info">
+<h2>Mother's Information</h2>
+<label for="mother_name">Mother's Name</label><input type="text" name="mother_name" value="" id="mother_name">
+<label for="mother_dob">Birth Date</label><input type="text" name="mother_dob" value="" id="mother_dob">
+<label for="mother_address">Address</label><input type="text" name="mother_address" value="" id="mother_address">
+<label for="mother_city">City</label><input type="text" name="mother_city" value="" id="mother_city">
+<label for="mother_state">State</label><input type="text" name="mother_state" value="" id="mother_state">
+<label for="mother_zip">Zip</label><input type="text" name="mother_zip" value="" id="mother_zip">
+<label for="mother_home_phone">Home Phone</label><input type="text" name="mother_home_phone" value="" id="mother_home_phone">
+<label for="mother_work_phone">Work Phone</label><input type="text" name="mother_work_phone" value="" id="mother_work_phone">
+<label for="mother_cell_phone">Cell Phone</label><input type="text" name="mother_cell_phone" value="" id="mother_cell_phone">
+<label for="mother_email">Email</label><input type="text" name="mother_email" value="" id="mother_email">
+</div>
+
+<div id="father_info">
+<h2>Father's Information</h2>
+<label for="father_name">Father's Name</label><input type="text" name="father_name" value="" id="father_name">
+<label for="father_dob">Birth Date</label><input type="text" name="father_dob" value="" id="father_dob">
+<label for="father_address">Address</label><input type="text" name="father_address" value="" id="father_address">
+<label for="father_city">City</label><input type="text" name="father_city" value="" id="father_city">
+<label for="father_state">State</label><input type="text" name="father_state" value="" id="father_state">
+<label for="father_zip">Zip</label><input type="text" name="father_zip" value="" id="father_zip">
+<label for="father_home_phone">Home Phone</label><input type="text" name="father_home_phone" value="" id="father_home_phone">
+<label for="father_work_phone">Work Phone</label><input type="text" name="father_work_phone" value="" id="father_work_phone">
+<label for="father_cell_phone">Cell Phone</label><input type="text" name="father_cell_phone" value="" id="father_cell_phone">
+<label for="father_email">Email</label><input type="text" name="father_email" value="" id="father_email">
+</div>
\ No newline at end of file
|
perigrin/sac_camp
|
81232709ed06d441732fc11f44e60907877d0166
|
add minor waver
|
diff --git a/minor_waver.mdown b/minor_waver.mdown
new file mode 100644
index 0000000..6b8da44
--- /dev/null
+++ b/minor_waver.mdown
@@ -0,0 +1,36 @@
+# Minor Child Agreement and Waver
+
+> The undersigned parent (or legal guardian) of ______________________ , a
+> minor child, herby consents to participation of said child in all
+> Super Awesome Cool activities (Programs(s)), including but not limited
+> to, [x] and field trips with our without transportation provided by
+> Super Awesome Cool. I do hereby acknowledge and agree that the named
+> minor child must be ____ (__) years old or older to participated in any
+> Program. In the event that the minor child should sustain emergency injuries
+> or illness while participating in the programs, I do hear by
+> authorized Super Awesome Cool to administer, or cause to be
+> administered such first aid or other treatment as may be necessary
+> under the circumstances, to include treatment by a physician or
+> hospital if the parent or guardian is not available. Any such firs aid
+> or treatment is expressly limited to emergency situations and is
+> expressly understood that, except as provided herein, Super Awesome Cool
+> will not provide, or be responsible for the provision of, medicine of
+> any kind to the minor child.
+
+> In consideration of the services to be performed by Super Awesome Cool and the
+> participation of the minor child in Programs, the parent/legal guardian, on
+> behalf of himself an the minor child, their heirs, assigns and agents does
+> hereby agree to indemnify and hold harmless Super Awesome Cool, it's
+> employees, officers, agents, servants and volunteers from and against any and
+> all claims demands or liability for loss, expense, damage or injury of any
+> nature, kind or amount whatsoever to person or property resulting in any way
+> form or fashion and arising directly or indirectly from or connected with any
+> and all participation in the Programs. I further authorize agree and consent
+> to the use by Super Awesome Cool or its assigns and agents, of any
+> photographs, recordings, video or pictures of any kind depicting the minor
+> child participating in the Programs.
+
+Initial: ___ I have received and will read the information contained in the
+2009 camp manual which includes the registration and payment policy. I will
+review this information with my child and we will abide by the polices set by
+Super Awesome Cool.
\ No newline at end of file
|
perigrin/sac_camp
|
a367747af48b7e5df05c19ebf1c7cc2173ef8b37
|
add authorization and medication form
|
diff --git a/authorized_pickup_medication_form.mdown b/authorized_pickup_medication_form.mdown
new file mode 100644
index 0000000..bbb17bc
--- /dev/null
+++ b/authorized_pickup_medication_form.mdown
@@ -0,0 +1,32 @@
+# AUTHORIZED TO REMOVE CHILD (print) LIST ANYONE OTHER THAN YOURSELF
+
+Please attach any an all legal documents relating to removal or non-removal of a child from program if applicable and outline any and all directions relating to said documents.
+
+Anyone not listed below will not be authorized to sign your child out from the program.
+
+Name: <input type="text" name="name1" value="" id="name1">
+Phone:<input type="text" name="phone1" value="" id="phone1">
+
+Name: <input type="text" name="name2" value="" id="name2">
+Phone:<input type="text" name="phone2" value="" id="phone2">
+
+Name: <input type="text" name="name3" value="" id="name3">
+Phone:<input type="text" name="phone3" value="" id="phone3">
+
+Name: <input type="text" name="name4" value="" id="name4">
+Phone:<input type="text" name="phone4" value="" id="phone4">
+
+# Medical / Emotional Conditions
+
+List any *medical* or *emotional* conditions your child has (i.e.. ADHD, Mild Autism, Bi-Polar) Please be specific, this will only help us better understand your child.
+
+<textarea name="medical_conditions" rows="8" cols="60"></textarea>
+
+List any medications the child may be taking. Any medications to be administered during Camp hours require a separate authorization form.
+
+<textarea name="medications" rows="8" cols="60"></textarea>
+
+List any allergies or allergic reactions your child might have (i.e: bee sting, poison ivy, foods).
+
+<textarea name="allergies" rows="8" cols="60"></textarea>
+
|
mccv/Cassidy
|
e77399599d8e91a7728a7dcd4d081226564f4276
|
commenting code a bit
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 40374e6..9375879 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,262 +1,284 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
import scala.collection.mutable.{Map,HashMap}
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
def /(keyspace : String) = new KeySpace(this,keyspace,obtainedAt,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(keyspace, key, columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
def |(keyspace : String, key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(keyspace,key,colPath,consistencyLevel)
def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
client.get(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper) : Unit =
++|^(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
--(keyspace,key,columnPath,timestamp,consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
}
+/**
+ * BatchSession coalesces inserts into a set of BatchMutation and/or BatchMutationSuper objects.
+ * When flush() is called these batch operations are applied.
+ */
trait BatchSession extends Session {
+ // keep track of the various batch operations we'll eventually commit
val batchMap = HashMap[String,Map[String,BatchMutation]]()
val superBatchMap = HashMap[String,Map[String,BatchMutationSuper]]()
import scala.collection.jcl.Conversions._
override def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) = {
if(columnPath != null && columnPath.column != null && columnPath.column_family != null){
+ // normal and super columns get handled differently
if(columnPath.super_column == null){
insertNormal(keyspace,key,columnPath,value,timestamp)
} else {
insertSuper(keyspace,key,columnPath,value,timestamp)
}
}else{
- throw new IllegalArgumentException("malformed column path " + columnPath)
+ throw new IllegalArgumentException("incomplete column path " + columnPath)
}
}
def insertNormal(keyspace: String, id: String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) = {
+ // add an entry to batchMap... this feels overly convoluted
val keyspaceMap = batchMap.getOrElseUpdate(keyspace,HashMap[String,BatchMutation]())
val batch = keyspaceMap.getOrElseUpdate(id,new BatchMutation())
+
+ // make sure we get a good, initialized BatchMutation out of our map
batch.key = id
if(batch.cfmap == null){
batch.cfmap = new java.util.HashMap[java.lang.String,java.util.List[Column]]()
}
if(batch.cfmap.get(columnPath.column_family) == null){
batch.cfmap.put(columnPath.column_family, new java.util.ArrayList[Column]())
}
+
+ // now add our new column to the list
val colTList = batch.cfmap.get(columnPath.column_family)
val colT = new Column()
colT.name = columnPath.column
colT.timestamp = timestamp
colT.value = value
colTList.add(colT)
}
- def flush():Unit = {
- batchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutation]]) => {
- keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutation]) => {
- /*println("batch mutation for keyspace " + keyspaceEntry._1)
- println("batch mutation key " + entry._2.key)
- entry._2.cfmap.foreach((cfmap) => {
- cfmap._2.foreach((col) => {
- println("\tcol name = " + col.name)
- println("\tcol value = " + new String(col.value))
- println("\tcol ts = " + col.timestamp)
- })
- })*/
- ++|(keyspaceEntry._1,entry._2,consistencyLevel)
- })
- })
- batchMap.clear()
- superBatchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutationSuper]]) => {
- keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutationSuper]) => {
- ++|^(keyspaceEntry._1,entry._2,consistencyLevel)
- })
- })
- superBatchMap.clear()
- }
def insertSuper(keyspace: String, id: String, columnPath : ColumnPath, value: Array[Byte], timestamp: Long) = {
-
+ // if insertNormal feels overly convoluted, this one reeks of overconvolution
val keyspaceMap = superBatchMap.getOrElseUpdate(keyspace,Map[String,BatchMutationSuper]())
val batch = keyspaceMap.getOrElseUpdate(id,new BatchMutationSuper())
+
+ // make sure we get a good, initilazed BatchMutationSuper out of our map
batch.key = id
if(batch.cfmap == null){
batch.cfmap = new java.util.HashMap[java.lang.String,java.util.List[SuperColumn]]()
}
if(batch.cfmap.get(columnPath.column_family) == null){
batch.cfmap.put(columnPath.column_family, new java.util.ArrayList[SuperColumn]())
}
+ // now make sure we get a good SuperColumn out of our BatchMutationSuper
val superColTList = batch.cfmap.get(columnPath.column_family)
val superColT = superColTList.find(_.name == columnPath.super_column) match {
case Some(superCol) => superCol
case None => {
val superCol = new SuperColumn()
superCol.name = columnPath.super_column
superCol.columns = new java.util.ArrayList[Column]()
superColTList.add(superCol)
superCol
}
}
+ // and finally, add our new column
val colT = new Column
colT.name = columnPath.column
colT.timestamp = timestamp
colT.value = value
superColT.columns.add(colT)
}
+ /**
+ * applies all batch operations in batchMap and superBatchMap, then clears out
+ * those maps
+ */
+ def flush():Unit = {
+ batchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutation]]) => {
+ keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutation]) => {
+ /*println("batch mutation for keyspace " + keyspaceEntry._1)
+ println("batch mutation key " + entry._2.key)
+ entry._2.cfmap.foreach((cfmap) => {
+ cfmap._2.foreach((col) => {
+ println("\tcol name = " + col.name)
+ println("\tcol value = " + new String(col.value))
+ println("\tcol ts = " + col.timestamp)
+ })
+ })*/
+ ++|(keyspaceEntry._1,entry._2,consistencyLevel)
+ })
+ })
+ batchMap.clear()
+ superBatchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutationSuper]]) => {
+ keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutationSuper]) => {
+ ++|^(keyspaceEntry._1,entry._2,consistencyLevel)
+ })
+ })
+ superBatchMap.clear()
+ }
+
+
+
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def newBatchSession : Session = newBatchSession(defConsistency)
def newBatchSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new BatchSession
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
override def flush = {super.flush(); t.flush()}
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R):R = {
val s = newSession
doWork(s,work)
}
def doBatchWork[R](work : (Session) => R):R = {
val s = newBatchSession
doWork(s,work)
}
protected def doWork[R](s : Session, work : (Session) => R):R = {
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
|
mccv/Cassidy
|
b67b62df14f0f191f68eccd2d14540efd5d4ff9a
|
adding batch sugar
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index c17c885..40374e6 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,143 +1,262 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
+import scala.collection.mutable.{Map,HashMap}
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
def /(keyspace : String) = new KeySpace(this,keyspace,obtainedAt,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(keyspace, key, columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
def |(keyspace : String, key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(keyspace,key,colPath,consistencyLevel)
def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
client.get(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper) : Unit =
++|^(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
--(keyspace,key,columnPath,timestamp,consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
}
+trait BatchSession extends Session {
+ val batchMap = HashMap[String,Map[String,BatchMutation]]()
+ val superBatchMap = HashMap[String,Map[String,BatchMutationSuper]]()
+
+ import scala.collection.jcl.Conversions._
+
+ override def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) = {
+ if(columnPath != null && columnPath.column != null && columnPath.column_family != null){
+ if(columnPath.super_column == null){
+ insertNormal(keyspace,key,columnPath,value,timestamp)
+ } else {
+ insertSuper(keyspace,key,columnPath,value,timestamp)
+ }
+ }else{
+ throw new IllegalArgumentException("malformed column path " + columnPath)
+ }
+ }
+
+ def insertNormal(keyspace: String, id: String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) = {
+ val keyspaceMap = batchMap.getOrElseUpdate(keyspace,HashMap[String,BatchMutation]())
+ val batch = keyspaceMap.getOrElseUpdate(id,new BatchMutation())
+ batch.key = id
+ if(batch.cfmap == null){
+ batch.cfmap = new java.util.HashMap[java.lang.String,java.util.List[Column]]()
+ }
+ if(batch.cfmap.get(columnPath.column_family) == null){
+ batch.cfmap.put(columnPath.column_family, new java.util.ArrayList[Column]())
+ }
+ val colTList = batch.cfmap.get(columnPath.column_family)
+ val colT = new Column()
+ colT.name = columnPath.column
+ colT.timestamp = timestamp
+ colT.value = value
+ colTList.add(colT)
+ }
+
+ def flush():Unit = {
+ batchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutation]]) => {
+ keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutation]) => {
+ /*println("batch mutation for keyspace " + keyspaceEntry._1)
+ println("batch mutation key " + entry._2.key)
+ entry._2.cfmap.foreach((cfmap) => {
+ cfmap._2.foreach((col) => {
+ println("\tcol name = " + col.name)
+ println("\tcol value = " + new String(col.value))
+ println("\tcol ts = " + col.timestamp)
+ })
+ })*/
+ ++|(keyspaceEntry._1,entry._2,consistencyLevel)
+ })
+ })
+ batchMap.clear()
+ superBatchMap.foreach((keyspaceEntry:Tuple2[String,Map[String,BatchMutationSuper]]) => {
+ keyspaceEntry._2.foreach((entry:Tuple2[String,BatchMutationSuper]) => {
+ ++|^(keyspaceEntry._1,entry._2,consistencyLevel)
+ })
+ })
+ superBatchMap.clear()
+ }
+
+ def insertSuper(keyspace: String, id: String, columnPath : ColumnPath, value: Array[Byte], timestamp: Long) = {
+
+ val keyspaceMap = superBatchMap.getOrElseUpdate(keyspace,Map[String,BatchMutationSuper]())
+ val batch = keyspaceMap.getOrElseUpdate(id,new BatchMutationSuper())
+ batch.key = id
+ if(batch.cfmap == null){
+ batch.cfmap = new java.util.HashMap[java.lang.String,java.util.List[SuperColumn]]()
+ }
+ if(batch.cfmap.get(columnPath.column_family) == null){
+ batch.cfmap.put(columnPath.column_family, new java.util.ArrayList[SuperColumn]())
+ }
+
+ val superColTList = batch.cfmap.get(columnPath.column_family)
+ val superColT = superColTList.find(_.name == columnPath.super_column) match {
+ case Some(superCol) => superCol
+ case None => {
+ val superCol = new SuperColumn()
+ superCol.name = columnPath.super_column
+ superCol.columns = new java.util.ArrayList[Column]()
+ superColTList.add(superCol)
+ superCol
+ }
+ }
+
+ val colT = new Column
+ colT.name = columnPath.column
+ colT.timestamp = timestamp
+ colT.value = value
+ superColT.columns.add(colT)
+ }
+
+}
+
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
- def doWork[R](work : (Session) => R) = {
+ def newBatchSession : Session = newBatchSession(defConsistency)
+
+ def newBatchSession(consistency : Int) : Session = {
+ val t = transportPool.borrowObject
+
+ val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
+
+ new BatchSession
+ {
+ val client = c
+ val obtainedAt = System.currentTimeMillis
+ val consistencyLevel = consistency //What's the sensible default?
+ override def flush = {super.flush(); t.flush()}
+ def close = transportPool.returnObject(t)
+ }
+ }
+ def doWork[R](work : (Session) => R):R = {
val s = newSession
+ doWork(s,work)
+ }
+
+ def doBatchWork[R](work : (Session) => R):R = {
+ val s = newBatchSession
+ doWork(s,work)
+ }
+
+ protected def doWork[R](s : Session, work : (Session) => R):R = {
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index e25c3a1..2944568 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,70 +1,104 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import org.apache.cassandra.service.{ConsistencyLevel, ColumnPath}
import se.foldleft.pool._
object Main {
def main(a: Array[String]): Unit = {
work()
}
def work() = {
implicit def strToBytes(s: String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost", 9160)), Protocol.Binary, ConsistencyLevel.QUORUM)
/*
Note: the keyspace def to use this looks like
<Keyspace Name="Delicious">
<KeysCachedFraction>0.01</KeysCachedFraction>
<ColumnFamily CompareWith="UTF8Type" Name="Users"/>
<ColumnFamily CompareWith="UTF8Type" Name="Tags"/>
<ColumnFamily CompareWith="UTF8Type" Name="Bookmarks"/>
<ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserBookmarks"/>
<ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserTags"/>
</Keyspace>
*/
c.doWork {
s => {
+ val key = "mccv"
println("exercising inserts")
- s ++| ("Delicious", "mccv", new ColumnPath("Users", null, "name"), "Mark McBride")
- s / ("Delicious") ++| ("mccv", new ColumnPath("Users", null, "location"), "Santa Clara")
- s / ("Delicious") / ("mccv") ++| (new ColumnPath("Users", null, "state"), "CA")
- s/"Delicious"/"mccv"/"Users" ++| ("age","34-ish")
- s/"Delicious"/"mccv"/"Users"/"weight" ++| "too much"
+ s ++| ("Delicious", key, new ColumnPath("Users", null, "name"), "Mark McBride")
+ s / ("Delicious") ++| (key, new ColumnPath("Users", null, "location"), "Santa Clara")
+ s / ("Delicious") / (key) ++| (new ColumnPath("Users", null, "state"), "CA")
+ s/"Delicious"/key/"Users" ++| ("age","34-ish")
+ s/"Delicious"/key/"Users"/"weight" ++| "too much"
// now get all the values back
println("exercising reads")
- val cf = s/"Delicious"/"mccv"/"Users"
+ val cf = s/"Delicious"/key/"Users"
println("users/mccv has " + (cf|#) + " columns")
cf/"name"| match {
case Some(col) => println("mccv's name is " + new String(col.value))
case None => println("no name found for mccv")
}
// play with super columns
- s/"Delicious"/"mccv"/^"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
+ s/"Delicious"/key/^"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
// read out super columns
- val scf = s/"Delicious"/"mccv"/^"UserBookmarks"
+ val scf = s/"Delicious"/key/^"UserBookmarks"
println((scf|#) + " bookmarks for mccv")
scf/"http://www.twitter.com"/"description"| match {
case Some(col) => println("desc for twitter page is " + new String(col.value))
case None => println("no desc for this bookmark")
}
}
}
+ c.doBatchWork {
+ s => {
+ val key = "mccv2"
+ println("exercising batch inserts")
+ s ++| ("Delicious", key, new ColumnPath("Users", null, "name"), "Mark McBride")
+ s / ("Delicious") ++| (key, new ColumnPath("Users", null, "location"), "Santa Clara")
+ s / ("Delicious") / (key) ++| (new ColumnPath("Users", null, "state"), "CA")
+ s/"Delicious"/key/"Users" ++| ("age","34-ish")
+ s/"Delicious"/key/"Users"/"weight" ++| "too much"
+ s.flush()
+ // now get all the values back
+ println("exercising reads")
+ val cf = s/"Delicious"/key/"Users"
+ println("users/mccv has " + (cf|#) + " columns")
+ cf/"name"| match {
+ case Some(col) => println("mccv's name is " + new String(col.value))
+ case None => println("no name found for mccv")
+ }
+
+ // play with super columns
+ s/"Delicious"/key/^"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
+ s.flush()
+ // read out super columns
+ val scf = s/"Delicious"/key/^"UserBookmarks"
+ println((scf|#) + " bookmarks for mccv")
+ scf/"http://www.twitter.com"/"description"| match {
+ case Some(col) => println("desc for twitter page is " + new String(col.value))
+ case None => println("no desc for this bookmark")
+
+ }
+
+ }
+ }
}
}
\ No newline at end of file
|
mccv/Cassidy
|
e5f7cb54d40e0804fbe9a18aedd3df5243f5d486
|
making higher order classes depend on Session vs. client. Setting stage for batch sugar
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 4e57094..c17c885 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,143 +1,143 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
- def /(keyspace : String) = new KeySpace(client,keyspace,obtainedAt,consistencyLevel)
+ def /(keyspace : String) = new KeySpace(this,keyspace,obtainedAt,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(keyspace, key, columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
def |(keyspace : String, key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(keyspace,key,colPath,consistencyLevel)
def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
client.get(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper) : Unit =
++|^(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
--(keyspace,key,columnPath,timestamp,consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala b/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala
index b1a4423..04edefc 100644
--- a/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala
+++ b/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala
@@ -1,44 +1,35 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
-class CassidyColumn(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, superColumnName : Option[Array[Byte]], columnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int){
+class CassidyColumn(columnFamily : CassidyColumnParent[Column], columnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int){
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def colOrSuperToColOption(colOrSuper : ColumnOrSuperColumn):Option[Column] =
if(colOrSuper != null) Some(colOrSuper.column) else None
- val columnParent = superColumnName match {
- case Some(name) => new ColumnParent(columnFamily,name)
- case None => new ColumnParent(columnFamily,null)
- }
- val columnPath = superColumnName match {
- case Some(name) => new ColumnPath(columnFamily,name,columnName)
- case None => new ColumnPath(columnFamily,null,columnName)
- }
-
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
def |() : Option[Column] =
|(consistencyLevel)
def |(consistencyLevel : Int) : Option[Column] =
- client.get(keyspace, key, columnPath, consistencyLevel)
+ columnFamily|(columnName, consistencyLevel)
def ++|(value : Array[Byte]) : Unit =
++|(value,obtainedAt,consistencyLevel)
def ++|(value : Array[Byte], timestamp : Long) : Unit =
++|(value,timestamp,consistencyLevel)
def ++|(value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+ columnFamily++|(columnName, value,timestamp,consistencyLevel)
def --(timestamp : Long) : Unit =
--(timestamp,consistencyLevel)
def --(timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+ columnFamily--(columnName, timestamp, consistencyLevel)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala b/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala
index 8c84a0e..98baf89 100644
--- a/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala
+++ b/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala
@@ -1,70 +1,78 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
-/**
- * Created by IntelliJ IDEA.
- * User: mmcbride
- * Date: Aug 16, 2009
- * Time: 12:55:45 PM
- * To change this template use File | Settings | File Templates.
- */
-
-class CassidyColumnFamily(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, obtainedAt : Long, consistencyLevel : Int){
+trait CassidyColumnParent[T]{
+ def |(columnName : Array[Byte], consistencyLevel : Int) : Option[T]
+ def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit
+ def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit
+ val columnParent : ColumnParent
+}
+class CassidyColumnFamily(row: Row, columnFamily : String, obtainedAt : Long, consistencyLevel : Int)
+ extends CassidyColumnParent[Column]{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
val columnParent = new ColumnParent(columnFamily,null)
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
private implicit def colOrSuperListToColList(l : List[ColumnOrSuperColumn]):List[Column] = l.map(_.column)
private implicit def colOrSuperToColOption(colOrSuper : ColumnOrSuperColumn):Option[Column] =
if(colOrSuper != null) Some(colOrSuper.column) else None
def /(columnName : Array[Byte]) = {
- new CassidyColumn(client,keyspace,key,columnFamily,None,columnName,obtainedAt,consistencyLevel)
+ new CassidyColumn(this,columnName,obtainedAt,consistencyLevel)
}
def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[Column] =
/(start,end,ascending,count,consistencyLevel)
def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] = {
val range = new SliceRange(start,end,ascending,count)
/(new SlicePredicate(null,range), consistencyLevel)
}
def /(colNames : List[Array[Byte]]) : List[Column] =
/(colNames,consistencyLevel)
def /(colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] =
/(new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(predicate : SlicePredicate, consistencyLevel : Int) : List[Column] =
- client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+ row/(columnParent, predicate, consistencyLevel)
def |(columnName : Array[Byte]) : Option[Column] =
|(columnName,consistencyLevel)
def |(columnName : Array[Byte], consistencyLevel : Int) : Option[Column] =
- client.get(keyspace, key, new ColumnPath(columnFamily,null,columnName), consistencyLevel)
+ row|(new ColumnPath(columnFamily,null,columnName), consistencyLevel) match {
+ case Some(colOrSuperColumn) => {
+ if(colOrSuperColumn.column != null) {
+ Some(colOrSuperColumn.column)
+ } else {
+ throw new IllegalArgumentException("trying to treat " + columnFamily + " as a super column family")
+ }
+ }
+ case None => None
+ }
def |#() : Int =
|#(consistencyLevel)
def |#(consistencyLevel : Int) : Int =
- client.get_count(keyspace, key, columnParent, consistencyLevel)
+ row|#(columnParent, consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte]) : Unit =
++|(columnName,value,obtainedAt,consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
++|(columnName,value,timestamp,consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, new ColumnPath(columnFamily,null,columnName), value,timestamp,consistencyLevel)
+ row++|(new ColumnPath(columnFamily,null,columnName), value,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long) : Unit =
--(columnName,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
+ row--(new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala b/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala
index 7b8e3a6..a0a0c08 100644
--- a/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala
+++ b/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala
@@ -1,39 +1,46 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
-class CassidySuperColumn(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, superColumnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int){
+class CassidySuperColumn(superColumnFamily : CassidySuperColumnFamily, superColumnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int)
+ extends CassidyColumnParent[Column]{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
- val columnParent = new ColumnParent(columnFamily,superColumnName)
+ val columnParent = new ColumnParent(superColumnFamily.columnFamily,superColumnName)
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
private implicit def colOrSuperListToSuperColList(l : List[ColumnOrSuperColumn]):List[SuperColumn] = l.map(_.super_column)
private implicit def colOrSuperToSuperColOption(colOrSuper : ColumnOrSuperColumn):Option[SuperColumn] =
if(colOrSuper != null) Some(colOrSuper.super_column) else None
def /(columnName : Array[Byte]) = {
- new CassidyColumn(client,keyspace,key,columnFamily,Some(columnName),columnName,obtainedAt,consistencyLevel)
+ new CassidyColumn(this,columnName,obtainedAt,consistencyLevel)
}
- def |(columnName : Array[Byte]) : Option[SuperColumn] =
+ def |() : Option[SuperColumn] =
+ |(consistencyLevel)
+
+ def |(consistencyLevel : Int) : Option[SuperColumn] =
+ superColumnFamily|(superColumnName, consistencyLevel)
+
+ def |(columnName : Array[Byte]) : Option[Column] =
|(columnName,consistencyLevel)
- def |(columnName : Array[Byte], consistencyLevel : Int) : Option[SuperColumn] =
- client.get(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), consistencyLevel)
+ def |(columnName : Array[Byte], consistencyLevel : Int) : Option[Column] =
+ superColumnFamily|(superColumnName,columnName, consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte]) : Unit =
++|(columnName,value,obtainedAt,consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
++|(columnName,value,timestamp,consistencyLevel)
def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), value,timestamp,consistencyLevel)
+ superColumnFamily++|(superColumnName, columnName, value,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long) : Unit =
--(columnName,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), timestamp, consistencyLevel)
+ superColumnFamily--(columnName, timestamp, consistencyLevel)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala b/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala
index 6a71460..bc94fd9 100644
--- a/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala
+++ b/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala
@@ -1,70 +1,95 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
/**
* Created by IntelliJ IDEA.
* User: mmcbride
* Date: Aug 16, 2009
* Time: 12:55:45 PM
* To change this template use File | Settings | File Templates.
*/
-class CassidySuperColumnFamily(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, obtainedAt : Long, consistencyLevel : Int){
+class CassidySuperColumnFamily(row : Row, val columnFamily : String, obtainedAt : Long, consistencyLevel : Int){
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
val columnParent = new ColumnParent(columnFamily,null)
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
private implicit def colOrSuperListToSuperColList(l : List[ColumnOrSuperColumn]):List[SuperColumn] = l.map(_.super_column)
private implicit def colOrSuperToSuperColOption(colOrSuper : ColumnOrSuperColumn):Option[SuperColumn] =
if(colOrSuper != null) Some(colOrSuper.super_column) else None
def /(columnName : Array[Byte]) = {
- new CassidySuperColumn(client,keyspace,key,columnFamily,columnName,obtainedAt,consistencyLevel)
+ new CassidySuperColumn(this,columnName,obtainedAt,consistencyLevel)
}
def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[SuperColumn] =
/(start,end,ascending,count,consistencyLevel)
def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[SuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(new SlicePredicate(null,range), consistencyLevel)
}
def /(colNames : List[Array[Byte]]) : List[SuperColumn] =
/(colNames,consistencyLevel)
def /(colNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] =
/(new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(predicate : SlicePredicate, consistencyLevel : Int) : List[SuperColumn] =
- client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
-
- def |(columnName : Array[Byte]) : Option[SuperColumn] =
- |(columnName,consistencyLevel)
-
- def |(columnName : Array[Byte], consistencyLevel : Int) : Option[SuperColumn] =
- client.get(keyspace, key, new ColumnPath(columnFamily,null,columnName), consistencyLevel)
+ row/(columnParent, predicate, consistencyLevel)
+
+ def |(superColumnName : Array[Byte]) : Option[SuperColumn] =
+ |(superColumnName,consistencyLevel)
+
+ def |(superColumnName : Array[Byte], consistencyLevel : Int) : Option[SuperColumn] =
+ row|(new ColumnPath(columnFamily,superColumnName,null), consistencyLevel) match {
+ case Some(colOrSuperColumn) => {
+ if(colOrSuperColumn.super_column != null) {
+ Some(colOrSuperColumn.super_column)
+ } else {
+ throw new IllegalArgumentException("trying to treat " + columnFamily + " as a regular column family")
+ }
+ }
+ case None => None
+ }
+
+
+ def |(superColumnName : Array[Byte], columnName : Array[Byte]) : Option[Column] =
+ |(superColumnName,columnName,consistencyLevel)
+
+ def |(superColumnName : Array[Byte], columnName : Array[Byte], consistencyLevel : Int) : Option[Column] =
+ row|(new ColumnPath(columnFamily,superColumnName,columnName), consistencyLevel) match {
+ case Some(colOrSuperColumn) => {
+ if(colOrSuperColumn.column != null) {
+ Some(colOrSuperColumn.column)
+ } else {
+ throw new IllegalArgumentException("trying to treat " + columnFamily + ":" + superColumnName + " as a super column family")
+ }
+ }
+ case None => None
+ }
def |#() : Int =
|#(consistencyLevel)
def |#(consistencyLevel : Int) : Int =
- client.get_count(keyspace, key, columnParent, consistencyLevel)
+ row|#(columnParent, consistencyLevel)
def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte]) : Unit =
++|(superColumn, columnName,value,obtainedAt,consistencyLevel)
def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
++|(superColumn, columnName,value,timestamp,consistencyLevel)
def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, new ColumnPath(columnFamily,superColumn,columnName), value,timestamp,consistencyLevel)
+ row++|(new ColumnPath(columnFamily,superColumn,columnName), value,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long) : Unit =
--(columnName,timestamp,consistencyLevel)
def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
+ row--(new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/KeySpace.scala b/src/main/scala/se/foldleft/cassidy/KeySpace.scala
index 358ce8e..e7ec596 100644
--- a/src/main/scala/se/foldleft/cassidy/KeySpace.scala
+++ b/src/main/scala/se/foldleft/cassidy/KeySpace.scala
@@ -1,75 +1,75 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
-class KeySpace(client : Cassandra.Client, keyspace : String, obtainedAt : Long, consistencyLevel : Int){
+class KeySpace(session : Session, keyspace : String, obtainedAt : Long, consistencyLevel : Int){
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
- def /(key : String) = new Row(client,keyspace,key,obtainedAt,consistencyLevel)
+ def /(key : String) = new Row(this,key,obtainedAt,consistencyLevel)
def /(key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(key,columnParent,start,end,ascending,count,consistencyLevel)
def /(key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(key, columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(key,columnParent,colNames,consistencyLevel)
def /(key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
- client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+ session/(keyspace, key, columnParent, predicate, consistencyLevel)
def |(key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(key,colPath,consistencyLevel)
def |(key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
- client.get(keyspace, key, colPath, consistencyLevel)
+ session|(keyspace, key, colPath, consistencyLevel)
def |#(key : String, columnParent : ColumnParent) : Int =
|#(key,columnParent,consistencyLevel)
def |#(key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
- client.get_count(keyspace, key, columnParent, consistencyLevel)
+ session|#(keyspace, key, columnParent, consistencyLevel)
def ++|(key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(key,columnPath,value,timestamp,consistencyLevel)
def ++|(key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+ session++|(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(batch : BatchMutation) : Unit =
++|(batch, consistencyLevel)
def ++|(batch : BatchMutation, consistencyLevel : Int) :Unit =
- client.batch_insert(keyspace, batch, consistencyLevel)
+ session++|(keyspace, batch, consistencyLevel)
def ++|^(batch : BatchMutationSuper) : Unit =
++|^(batch, consistencyLevel)
def ++|^(batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
- client.batch_insert_super_column(keyspace, batch, consistencyLevel)
+ session++|^(keyspace, batch, consistencyLevel)
def --(key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
--(key,columnPath,timestamp,consistencyLevel)
def --(key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+ session--(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
- client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
+ session.keys(keyspace, columnFamily, startsWith, stopsAt, maxResults)
}
- def describeTable() = client.describe_keyspace(keyspace)
+ def describeTable() = session.describeTable(keyspace)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index 7870285..e25c3a1 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,70 +1,70 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import org.apache.cassandra.service.{ConsistencyLevel, ColumnPath}
import se.foldleft.pool._
object Main {
def main(a: Array[String]): Unit = {
work()
}
def work() = {
implicit def strToBytes(s: String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost", 9160)), Protocol.Binary, ConsistencyLevel.QUORUM)
/*
Note: the keyspace def to use this looks like
<Keyspace Name="Delicious">
<KeysCachedFraction>0.01</KeysCachedFraction>
<ColumnFamily CompareWith="UTF8Type" Name="Users"/>
<ColumnFamily CompareWith="UTF8Type" Name="Tags"/>
<ColumnFamily CompareWith="UTF8Type" Name="Bookmarks"/>
<ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserBookmarks"/>
<ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserTags"/>
</Keyspace>
*/
c.doWork {
s => {
println("exercising inserts")
s ++| ("Delicious", "mccv", new ColumnPath("Users", null, "name"), "Mark McBride")
s / ("Delicious") ++| ("mccv", new ColumnPath("Users", null, "location"), "Santa Clara")
s / ("Delicious") / ("mccv") ++| (new ColumnPath("Users", null, "state"), "CA")
s/"Delicious"/"mccv"/"Users" ++| ("age","34-ish")
s/"Delicious"/"mccv"/"Users"/"weight" ++| "too much"
// now get all the values back
println("exercising reads")
val cf = s/"Delicious"/"mccv"/"Users"
println("users/mccv has " + (cf|#) + " columns")
cf/"name"| match {
case Some(col) => println("mccv's name is " + new String(col.value))
case None => println("no name found for mccv")
}
// play with super columns
- s/"Delicious"/"mccv"*"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
+ s/"Delicious"/"mccv"/^"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
// read out super columns
- val scf = s/"Delicious"/"mccv"*"UserBookmarks"
+ val scf = s/"Delicious"/"mccv"/^"UserBookmarks"
println((scf|#) + " bookmarks for mccv")
scf/"http://www.twitter.com"/"description"| match {
case Some(col) => println("desc for twitter page is " + new String(col.value))
case None => println("no desc for this bookmark")
}
}
}
}
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Row.scala b/src/main/scala/se/foldleft/cassidy/Row.scala
index 08c6ce0..0ff34ec 100644
--- a/src/main/scala/se/foldleft/cassidy/Row.scala
+++ b/src/main/scala/se/foldleft/cassidy/Row.scala
@@ -1,62 +1,62 @@
package se.foldleft.cassidy
import org.apache.cassandra.service._
-class Row(client : Cassandra.Client, keyspace : String, key : String, obtainedAt : Long, consistencyLevel : Int){
+class Row(keyspace : KeySpace, key : String, obtainedAt : Long, consistencyLevel : Int){
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
def /(columnFamily : String) = {
- new CassidyColumnFamily(client,keyspace,key,columnFamily,obtainedAt,consistencyLevel)
+ new CassidyColumnFamily(this,columnFamily,obtainedAt,consistencyLevel)
}
- def *(columnFamily : String) = {
- new CassidySuperColumnFamily(client,keyspace,key,columnFamily,obtainedAt,consistencyLevel)
+ def /^(superColumnFamily : String) = {
+ new CassidySuperColumnFamily(this,superColumnFamily,obtainedAt,consistencyLevel)
}
def /(columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(columnParent,start,end,ascending,count,consistencyLevel)
def /(columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(columnParent,colNames,consistencyLevel)
def /(columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
- client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+ keyspace/(key, columnParent, predicate, consistencyLevel)
def |(colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(colPath,consistencyLevel)
def |(colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
- client.get(keyspace, key, colPath, consistencyLevel)
+ keyspace.|(key, colPath, consistencyLevel)
def |#(columnParent : ColumnParent) : Int =
|#(columnParent,consistencyLevel)
def |#(columnParent : ColumnParent, consistencyLevel : Int) : Int =
- client.get_count(keyspace, key, columnParent, consistencyLevel)
+ keyspace.|#(key, columnParent, consistencyLevel)
def ++|(columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(columnPath,value,obtainedAt,consistencyLevel)
def ++|(columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(columnPath,value,timestamp,consistencyLevel)
def ++|(columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
- client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+ keyspace.++|(key, columnPath, value,timestamp,consistencyLevel)
def --(columnPath : ColumnPath, timestamp : Long) : Unit =
--(columnPath,timestamp,consistencyLevel)
def --(columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+ keyspace--(key, columnPath, timestamp, consistencyLevel)
}
\ No newline at end of file
|
mccv/Cassidy
|
0302ac748f8f6873f36175b2193727d69f74e516
|
adding keyspace, row, column family and column constructs
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 10d8229..4e57094 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,141 +1,143 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
+ def /(keyspace : String) = new KeySpace(client,keyspace,obtainedAt,consistencyLevel)
+
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
val range = new SliceRange(start,end,ascending,count)
/(keyspace, key, columnParent, new SlicePredicate(null,range), consistencyLevel)
}
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
def |(keyspace : String, key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(keyspace,key,colPath,consistencyLevel)
def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
client.get(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper) : Unit =
++|^(keyspace, batch, consistencyLevel)
def ++|^(keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
--(keyspace,key,columnPath,timestamp,consistencyLevel)
def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala b/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala
new file mode 100644
index 0000000..b1a4423
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/CassidyColumn.scala
@@ -0,0 +1,44 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+class CassidyColumn(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, superColumnName : Option[Array[Byte]], columnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ private implicit def colOrSuperToColOption(colOrSuper : ColumnOrSuperColumn):Option[Column] =
+ if(colOrSuper != null) Some(colOrSuper.column) else None
+
+ val columnParent = superColumnName match {
+ case Some(name) => new ColumnParent(columnFamily,name)
+ case None => new ColumnParent(columnFamily,null)
+ }
+ val columnPath = superColumnName match {
+ case Some(name) => new ColumnPath(columnFamily,name,columnName)
+ case None => new ColumnPath(columnFamily,null,columnName)
+ }
+
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+
+ def |() : Option[Column] =
+ |(consistencyLevel)
+
+ def |(consistencyLevel : Int) : Option[Column] =
+ client.get(keyspace, key, columnPath, consistencyLevel)
+
+ def ++|(value : Array[Byte]) : Unit =
+ ++|(value,obtainedAt,consistencyLevel)
+
+ def ++|(value : Array[Byte], timestamp : Long) : Unit =
+ ++|(value,timestamp,consistencyLevel)
+
+ def ++|(value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+
+ def --(timestamp : Long) : Unit =
+ --(timestamp,consistencyLevel)
+
+ def --(timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala b/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala
new file mode 100644
index 0000000..8c84a0e
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/CassidyColumnFamily.scala
@@ -0,0 +1,70 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: mmcbride
+ * Date: Aug 16, 2009
+ * Time: 12:55:45 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+class CassidyColumnFamily(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ val columnParent = new ColumnParent(columnFamily,null)
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+ private implicit def colOrSuperListToColList(l : List[ColumnOrSuperColumn]):List[Column] = l.map(_.column)
+ private implicit def colOrSuperToColOption(colOrSuper : ColumnOrSuperColumn):Option[Column] =
+ if(colOrSuper != null) Some(colOrSuper.column) else None
+
+ def /(columnName : Array[Byte]) = {
+ new CassidyColumn(client,keyspace,key,columnFamily,None,columnName,obtainedAt,consistencyLevel)
+ }
+ def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[Column] =
+ /(start,end,ascending,count,consistencyLevel)
+
+ def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] = {
+ val range = new SliceRange(start,end,ascending,count)
+ /(new SlicePredicate(null,range), consistencyLevel)
+ }
+
+ def /(colNames : List[Array[Byte]]) : List[Column] =
+ /(colNames,consistencyLevel)
+
+ def /(colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] =
+ /(new SlicePredicate(colNames.asJava,null),consistencyLevel)
+
+ def /(predicate : SlicePredicate, consistencyLevel : Int) : List[Column] =
+ client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+
+ def |(columnName : Array[Byte]) : Option[Column] =
+ |(columnName,consistencyLevel)
+
+ def |(columnName : Array[Byte], consistencyLevel : Int) : Option[Column] =
+ client.get(keyspace, key, new ColumnPath(columnFamily,null,columnName), consistencyLevel)
+
+ def |#() : Int =
+ |#(consistencyLevel)
+
+ def |#(consistencyLevel : Int) : Int =
+ client.get_count(keyspace, key, columnParent, consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte]) : Unit =
+ ++|(columnName,value,obtainedAt,consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
+ ++|(columnName,value,timestamp,consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, new ColumnPath(columnFamily,null,columnName), value,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long) : Unit =
+ --(columnName,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala b/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala
new file mode 100644
index 0000000..7b8e3a6
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/CassidySuperColumn.scala
@@ -0,0 +1,39 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+class CassidySuperColumn(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, superColumnName : Array[Byte], obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ val columnParent = new ColumnParent(columnFamily,superColumnName)
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+ private implicit def colOrSuperListToSuperColList(l : List[ColumnOrSuperColumn]):List[SuperColumn] = l.map(_.super_column)
+ private implicit def colOrSuperToSuperColOption(colOrSuper : ColumnOrSuperColumn):Option[SuperColumn] =
+ if(colOrSuper != null) Some(colOrSuper.super_column) else None
+
+ def /(columnName : Array[Byte]) = {
+ new CassidyColumn(client,keyspace,key,columnFamily,Some(columnName),columnName,obtainedAt,consistencyLevel)
+ }
+ def |(columnName : Array[Byte]) : Option[SuperColumn] =
+ |(columnName,consistencyLevel)
+
+ def |(columnName : Array[Byte], consistencyLevel : Int) : Option[SuperColumn] =
+ client.get(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte]) : Unit =
+ ++|(columnName,value,obtainedAt,consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
+ ++|(columnName,value,timestamp,consistencyLevel)
+
+ def ++|(columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), value,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long) : Unit =
+ --(columnName,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, new ColumnPath(columnFamily,superColumnName,columnName), timestamp, consistencyLevel)
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala b/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala
new file mode 100644
index 0000000..6a71460
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/CassidySuperColumnFamily.scala
@@ -0,0 +1,70 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: mmcbride
+ * Date: Aug 16, 2009
+ * Time: 12:55:45 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+class CassidySuperColumnFamily(client : Cassandra.Client, keyspace : String, key : String, columnFamily : String, obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ val columnParent = new ColumnParent(columnFamily,null)
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+ private implicit def colOrSuperListToSuperColList(l : List[ColumnOrSuperColumn]):List[SuperColumn] = l.map(_.super_column)
+ private implicit def colOrSuperToSuperColOption(colOrSuper : ColumnOrSuperColumn):Option[SuperColumn] =
+ if(colOrSuper != null) Some(colOrSuper.super_column) else None
+
+ def /(columnName : Array[Byte]) = {
+ new CassidySuperColumn(client,keyspace,key,columnFamily,columnName,obtainedAt,consistencyLevel)
+ }
+ def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[SuperColumn] =
+ /(start,end,ascending,count,consistencyLevel)
+
+ def /(start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[SuperColumn] = {
+ val range = new SliceRange(start,end,ascending,count)
+ /(new SlicePredicate(null,range), consistencyLevel)
+ }
+
+ def /(colNames : List[Array[Byte]]) : List[SuperColumn] =
+ /(colNames,consistencyLevel)
+
+ def /(colNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] =
+ /(new SlicePredicate(colNames.asJava,null),consistencyLevel)
+
+ def /(predicate : SlicePredicate, consistencyLevel : Int) : List[SuperColumn] =
+ client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+
+ def |(columnName : Array[Byte]) : Option[SuperColumn] =
+ |(columnName,consistencyLevel)
+
+ def |(columnName : Array[Byte], consistencyLevel : Int) : Option[SuperColumn] =
+ client.get(keyspace, key, new ColumnPath(columnFamily,null,columnName), consistencyLevel)
+
+ def |#() : Int =
+ |#(consistencyLevel)
+
+ def |#(consistencyLevel : Int) : Int =
+ client.get_count(keyspace, key, columnParent, consistencyLevel)
+
+ def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte]) : Unit =
+ ++|(superColumn, columnName,value,obtainedAt,consistencyLevel)
+
+ def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte], timestamp : Long) : Unit =
+ ++|(superColumn, columnName,value,timestamp,consistencyLevel)
+
+ def ++|(superColumn : Array[Byte], columnName : Array[Byte], value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, new ColumnPath(columnFamily,superColumn,columnName), value,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long) : Unit =
+ --(columnName,timestamp,consistencyLevel)
+
+ def --(columnName : Array[Byte], timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, new ColumnPath(columnFamily,null,columnName), timestamp, consistencyLevel)
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/KeySpace.scala b/src/main/scala/se/foldleft/cassidy/KeySpace.scala
new file mode 100644
index 0000000..358ce8e
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/KeySpace.scala
@@ -0,0 +1,75 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+class KeySpace(client : Cassandra.Client, keyspace : String, obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+
+ def /(key : String) = new Row(client,keyspace,key,obtainedAt,consistencyLevel)
+ def /(key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
+ /(key,columnParent,start,end,ascending,count,consistencyLevel)
+
+ def /(key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
+ val range = new SliceRange(start,end,ascending,count)
+ /(key, columnParent, new SlicePredicate(null,range), consistencyLevel)
+ }
+
+ def /(key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
+ /(key,columnParent,colNames,consistencyLevel)
+
+ def /(key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ /(key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
+
+ def /(key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+
+ def |(key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
+ |(key,colPath,consistencyLevel)
+
+ def |(key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
+ client.get(keyspace, key, colPath, consistencyLevel)
+
+ def |#(key : String, columnParent : ColumnParent) : Int =
+ |#(key,columnParent,consistencyLevel)
+
+ def |#(key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
+ client.get_count(keyspace, key, columnParent, consistencyLevel)
+
+ def ++|(key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
+ ++|(key,columnPath,value,obtainedAt,consistencyLevel)
+
+ def ++|(key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
+ ++|(key,columnPath,value,timestamp,consistencyLevel)
+
+ def ++|(key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+
+ def ++|(batch : BatchMutation) : Unit =
+ ++|(batch, consistencyLevel)
+
+ def ++|(batch : BatchMutation, consistencyLevel : Int) :Unit =
+ client.batch_insert(keyspace, batch, consistencyLevel)
+
+ def ++|^(batch : BatchMutationSuper) : Unit =
+ ++|^(batch, consistencyLevel)
+
+ def ++|^(batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
+ client.batch_insert_super_column(keyspace, batch, consistencyLevel)
+
+ def --(key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
+ --(key,columnPath,timestamp,consistencyLevel)
+
+ def --(key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+
+ def keys(columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
+ client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
+ }
+
+ def describeTable() = client.describe_keyspace(keyspace)
+
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index 6c0e2af..7870285 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,31 +1,70 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
-import org.apache.cassandra.service.{ConsistencyLevel,ColumnPath}
+import org.apache.cassandra.service.{ConsistencyLevel, ColumnPath}
import se.foldleft.pool._
object Main {
-
- /*
- import se.foldleft.pool._
- import se.foldleft.cassidy._
- import org.apache.cassandra.service._
- */
- def main(a : Array[String]) : Unit = {
- implicit def strToBytes(s : String) = s.getBytes("UTF-8")
- import scala.collection.jcl.Conversions._
- val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary,ConsistencyLevel.QUORUM)
+ def main(a: Array[String]): Unit = {
+ work()
+ }
- c.doWork { s => { s++|("SocialGraph","mccv",new ColumnPath("Details",null,"name"),"Mark McBride")}}
+ def work() = {
+ implicit def strToBytes(s: String) = s.getBytes("UTF-8")
+ import scala.collection.jcl.Conversions._
+ val c = new Cassidy(StackPool(SocketProvider("localhost", 9160)), Protocol.Binary, ConsistencyLevel.QUORUM)
+ /*
+ Note: the keyspace def to use this looks like
+ <Keyspace Name="Delicious">
+ <KeysCachedFraction>0.01</KeysCachedFraction>
+ <ColumnFamily CompareWith="UTF8Type" Name="Users"/>
+ <ColumnFamily CompareWith="UTF8Type" Name="Tags"/>
+ <ColumnFamily CompareWith="UTF8Type" Name="Bookmarks"/>
+ <ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserBookmarks"/>
+ <ColumnFamily ColumnType="Super" CompareWith="UTF8Type" CompareSubcolumnsWith="UTF8Type" Name="UserTags"/>
+ </Keyspace>
+
+ */
+ c.doWork {
+ s => {
+ println("exercising inserts")
+ s ++| ("Delicious", "mccv", new ColumnPath("Users", null, "name"), "Mark McBride")
+ s / ("Delicious") ++| ("mccv", new ColumnPath("Users", null, "location"), "Santa Clara")
+ s / ("Delicious") / ("mccv") ++| (new ColumnPath("Users", null, "state"), "CA")
+ s/"Delicious"/"mccv"/"Users" ++| ("age","34-ish")
+ s/"Delicious"/"mccv"/"Users"/"weight" ++| "too much"
+
+ // now get all the values back
+ println("exercising reads")
+ val cf = s/"Delicious"/"mccv"/"Users"
+ println("users/mccv has " + (cf|#) + " columns")
+ cf/"name"| match {
+ case Some(col) => println("mccv's name is " + new String(col.value))
+ case None => println("no name found for mccv")
+ }
+
+ // play with super columns
+ s/"Delicious"/"mccv"*"UserBookmarks"/"http://www.twitter.com"/"description" ++| "the twitter page"
+
+ // read out super columns
+ val scf = s/"Delicious"/"mccv"*"UserBookmarks"
+ println((scf|#) + " bookmarks for mccv")
+ scf/"http://www.twitter.com"/"description"| match {
+ case Some(col) => println("desc for twitter page is " + new String(col.value))
+ case None => println("no desc for this bookmark")
+
+ }
+ }
}
+ }
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Row.scala b/src/main/scala/se/foldleft/cassidy/Row.scala
new file mode 100644
index 0000000..08c6ce0
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/Row.scala
@@ -0,0 +1,62 @@
+package se.foldleft.cassidy
+
+import org.apache.cassandra.service._
+
+class Row(client : Cassandra.Client, keyspace : String, key : String, obtainedAt : Long, consistencyLevel : Int){
+
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+
+ def /(columnFamily : String) = {
+ new CassidyColumnFamily(client,keyspace,key,columnFamily,obtainedAt,consistencyLevel)
+ }
+
+ def *(columnFamily : String) = {
+ new CassidySuperColumnFamily(client,keyspace,key,columnFamily,obtainedAt,consistencyLevel)
+ }
+ def /(columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
+ /(columnParent,start,end,ascending,count,consistencyLevel)
+
+ def /(columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
+ val range = new SliceRange(start,end,ascending,count)
+ /(columnParent, new SlicePredicate(null,range), consistencyLevel)
+ }
+
+ def /(columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
+ /(columnParent,colNames,consistencyLevel)
+
+ def /(columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ /(columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
+
+ def /(columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
+
+ def |(colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
+ |(colPath,consistencyLevel)
+
+ def |(colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
+ client.get(keyspace, key, colPath, consistencyLevel)
+
+ def |#(columnParent : ColumnParent) : Int =
+ |#(columnParent,consistencyLevel)
+
+ def |#(columnParent : ColumnParent, consistencyLevel : Int) : Int =
+ client.get_count(keyspace, key, columnParent, consistencyLevel)
+
+ def ++|(columnPath : ColumnPath, value : Array[Byte]) : Unit =
+ ++|(columnPath,value,obtainedAt,consistencyLevel)
+
+ def ++|(columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
+ ++|(columnPath,value,timestamp,consistencyLevel)
+
+ def ++|(columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
+ client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
+
+ def --(columnPath : ColumnPath, timestamp : Long) : Unit =
+ --(columnPath,timestamp,consistencyLevel)
+
+ def --(columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
+}
\ No newline at end of file
|
mccv/Cassidy
|
a700394c9af42e6c86f0e2b606551df5e05d6c0f
|
updating to latest cassandra trunk (0.4 beta)
|
diff --git a/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar
index 7240f0f..2c30418 100644
Binary files a/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar and b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar differ
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 6b6a8fa..10d8229 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,155 +1,141 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
- def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[Column] =
+ def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
- def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] =
- client.get_slice(keyspace, key, columnParent, start, end, ascending, count, consistencyLevel).toList
+ def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[ColumnOrSuperColumn] = {
+ val range = new SliceRange(start,end,ascending,count)
+ /(keyspace, key, columnParent, new SlicePredicate(null,range), consistencyLevel)
+ }
- def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[Column] =
+ def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[ColumnOrSuperColumn] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
- def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] =
- client.get_slice_by_names(keyspace, key, columnParent, colNames.asJava, consistencyLevel ).toList
+ def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ /(keyspace,key,columnParent,new SlicePredicate(colNames.asJava,null),consistencyLevel)
+
+ def /(keyspace : String, key : String, columnParent : ColumnParent, predicate : SlicePredicate, consistencyLevel : Int) : List[ColumnOrSuperColumn] =
+ client.get_slice(keyspace, key, columnParent, predicate, consistencyLevel).toList
- def |(keyspace : String, key : String, colPath : ColumnPath) : Option[Column] =
+ def |(keyspace : String, key : String, colPath : ColumnPath) : Option[ColumnOrSuperColumn] =
|(keyspace,key,colPath,consistencyLevel)
- def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[Column] =
- client.get_column(keyspace, key, colPath, consistencyLevel)
+ def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[ColumnOrSuperColumn] =
+ client.get(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
- client.get_column_count(keyspace, key, columnParent, consistencyLevel)
+ client.get_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
- def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long) : Unit =
- --(keyspace,key,columnPathOrParent,timestamp,consistencyLevel)
-
- def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long, consistencyLevel : Int) : Unit =
- client.remove(keyspace, key, columnPathOrParent, timestamp, consistencyLevel)
-
- def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], ascending : Boolean, count : Int) : List[SuperColumn] =
- /^(keyspace,key,columnFamily,start,end,ascending,count,consistencyLevel)
-
- def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], isAscending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] =
- client.get_slice_super(keyspace, key,columnFamily, start, end,isAscending,count,consistencyLevel).toList
+ def ++|^(keyspace : String, batch : BatchMutationSuper) : Unit =
+ ++|^(keyspace, batch, consistencyLevel)
- def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]]) : List[SuperColumn] =
- /^(keyspace,key,columnFamily,superColNames,consistencyLevel)
-
- def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] =
- client.get_slice_super_by_names(keyspace, key, columnFamily, superColNames.asJava,consistencyLevel).toList
-
- def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath) : Option[SuperColumn] =
- |^(keyspace,key,superColumnPath,consistencyLevel)
-
- def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath,consistencyLevel : Int) : Option[SuperColumn] =
- client.get_super_column(keyspace,key,superColumnPath,consistencyLevel)
+ def ++|^(keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) :Unit =
+ client.batch_insert_super_column(keyspace, batch, consistencyLevel)
- def ++|^ (keyspace : String, batch : BatchMutationSuper) : Unit =
- ++|^ (keyspace, batch,consistencyLevel)
+ def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long) : Unit =
+ --(keyspace,key,columnPath,timestamp,consistencyLevel)
- def ++|^ (keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) : Unit =
- client.batch_insert_super_column(keyspace, batch, consistencyLevel)
+ def --(keyspace : String, key : String, columnPath : ColumnPath, timestamp : Long, consistencyLevel : Int) : Unit =
+ client.remove(keyspace, key, columnPath, timestamp, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
- def ?(query : String) = client.execute_query(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index 6886d8d..6c0e2af 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,32 +1,31 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
+import org.apache.cassandra.service.{ConsistencyLevel,ColumnPath}
import se.foldleft.pool._
object Main {
+ /*
+ import se.foldleft.pool._
+ import se.foldleft.cassidy._
+ import org.apache.cassandra.service._
+ */
+
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
- val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary,10)
- c.doWork { s => {
- val user_id = "1"
- // s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
- //s.++|("users",user_id,"base_attributes:age", "24", false)
-
- //for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
-
- ()
- }
- }
+ val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary,ConsistencyLevel.QUORUM)
+
+ c.doWork { s => { s++|("SocialGraph","mccv",new ColumnPath("Details",null,"name"),"Mark McBride")}}
}
}
\ No newline at end of file
diff --git a/target/cassidy-0.1.jar b/target/cassidy-0.1.jar
index e8ecb49..aebab08 100644
Binary files a/target/cassidy-0.1.jar and b/target/cassidy-0.1.jar differ
diff --git a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class
index 65e97d2..ecf5601 100644
Binary files a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class and b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Cassidy.class b/target/classes/se/foldleft/cassidy/Cassidy.class
index 112a0ab..9939e21 100644
Binary files a/target/classes/se/foldleft/cassidy/Cassidy.class and b/target/classes/se/foldleft/cassidy/Cassidy.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class
index 5fcafc1..8b8180f 100644
Binary files a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class and b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$.class b/target/classes/se/foldleft/cassidy/Main$.class
index 2ce1e12..d1281fe 100644
Binary files a/target/classes/se/foldleft/cassidy/Main$.class and b/target/classes/se/foldleft/cassidy/Main$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main.class b/target/classes/se/foldleft/cassidy/Main.class
index 047a56c..afb7ae2 100644
Binary files a/target/classes/se/foldleft/cassidy/Main.class and b/target/classes/se/foldleft/cassidy/Main.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$.class b/target/classes/se/foldleft/cassidy/Protocol$.class
index fde0817..7d7dd2b 100644
Binary files a/target/classes/se/foldleft/cassidy/Protocol$.class and b/target/classes/se/foldleft/cassidy/Protocol$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class
index 34d2a12..1033158 100644
Binary files a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class and b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class
index bed083d..55f67b2 100644
Binary files a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class and b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class
index 7a2d5ee..26bd449 100644
Binary files a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class and b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol.class b/target/classes/se/foldleft/cassidy/Protocol.class
index 44a742f..36cd7bc 100644
Binary files a/target/classes/se/foldleft/cassidy/Protocol.class and b/target/classes/se/foldleft/cassidy/Protocol.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class
index 2a87314..2872925 100644
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class and b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$class.class b/target/classes/se/foldleft/cassidy/Session$class.class
index 2a343d0..47d539d 100644
Binary files a/target/classes/se/foldleft/cassidy/Session$class.class and b/target/classes/se/foldleft/cassidy/Session$class.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session.class b/target/classes/se/foldleft/cassidy/Session.class
index 62cf68d..d53905a 100644
Binary files a/target/classes/se/foldleft/cassidy/Session.class and b/target/classes/se/foldleft/cassidy/Session.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
index edb8f64..696fd1e 100644
--- a/target/maven-archiver/pom.properties
+++ b/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Mon Aug 03 21:47:39 CEST 2009
+#Fri Aug 14 22:14:40 PDT 2009
version=0.1
groupId=se.foldleft
artifactId=cassidy
|
mccv/Cassidy
|
e3d5e38532b8367a0c7857d5f1c95bb26afabcc6
|
Removed maven folder in META-INF because of headache
|
diff --git a/pom.xml b/pom.xml
index 51da034..7bd8348 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,156 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<description>
Cassidy is a Scala wrapper around Cassandra
</description>
<organization>
<name>Foldleft</name>
<url>http://foldleft.se</url>
</organization>
<licenses>
<license>
<name>the Apache License, ASL Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>viktorklang</id>
<name>Viktor Klang</name>
<timezone>+1</timezone>
<email>viktor.klang [at] gmail.com</email>
<roles>
<role>BDFL</role>
</roles>
</developer>
</developers>
<properties>
<scala.version>2.7.5</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.4.0-SNAPSHOT</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>javautils</artifactId>
<version>2.7.4-0.1</version>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ </archive>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
<!--<args>
<arg></arg>
</args>-->
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 6b6a8fa..f05c3f1 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,155 +1,155 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
val consistencyLevel : Int
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[Column] =
/(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] =
client.get_slice(keyspace, key, columnParent, start, end, ascending, count, consistencyLevel).toList
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[Column] =
/(keyspace,key,columnParent,colNames,consistencyLevel)
def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] =
client.get_slice_by_names(keyspace, key, columnParent, colNames.asJava, consistencyLevel ).toList
def |(keyspace : String, key : String, colPath : ColumnPath) : Option[Column] =
|(keyspace,key,colPath,consistencyLevel)
def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[Column] =
client.get_column(keyspace, key, colPath, consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
|#(keyspace,key,columnParent,consistencyLevel)
def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_column_count(keyspace, key, columnParent, consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation) : Unit =
++|(keyspace, batch, consistencyLevel)
def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long) : Unit =
--(keyspace,key,columnPathOrParent,timestamp,consistencyLevel)
def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPathOrParent, timestamp, consistencyLevel)
def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], ascending : Boolean, count : Int) : List[SuperColumn] =
/^(keyspace,key,columnFamily,start,end,ascending,count,consistencyLevel)
- def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], isAscending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] =
- client.get_slice_super(keyspace, key,columnFamily, start, end,isAscending,count,consistencyLevel).toList
+ def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] =
+ client.get_slice_super(keyspace, key,columnFamily, start, end,ascending,count,consistencyLevel).toList
def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]]) : List[SuperColumn] =
/^(keyspace,key,columnFamily,superColNames,consistencyLevel)
def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] =
client.get_slice_super_by_names(keyspace, key, columnFamily, superColNames.asJava,consistencyLevel).toList
def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath) : Option[SuperColumn] =
|^(keyspace,key,superColumnPath,consistencyLevel)
def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath,consistencyLevel : Int) : Option[SuperColumn] =
client.get_super_column(keyspace,key,superColumnPath,consistencyLevel)
def ++|^ (keyspace : String, batch : BatchMutationSuper) : Unit =
++|^ (keyspace, batch,consistencyLevel)
def ++|^ (keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) : Unit =
client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
def ?(query : String) = client.execute_query(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
def newSession : Session = newSession(defConsistency)
def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/target/cassidy-0.1.jar b/target/cassidy-0.1.jar
index e8ecb49..43fdb19 100644
Binary files a/target/cassidy-0.1.jar and b/target/cassidy-0.1.jar differ
diff --git a/target/classes/se/foldleft/cassidy/Session$class.class b/target/classes/se/foldleft/cassidy/Session$class.class
index 2a343d0..2f2967f 100644
Binary files a/target/classes/se/foldleft/cassidy/Session$class.class and b/target/classes/se/foldleft/cassidy/Session$class.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
deleted file mode 100644
index edb8f64..0000000
--- a/target/maven-archiver/pom.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-#Generated by Maven
-#Mon Aug 03 21:47:39 CEST 2009
-version=0.1
-groupId=se.foldleft
-artifactId=cassidy
diff --git a/target/pom-transformed.xml b/target/pom-transformed.xml
index 51da034..7bd8348 100644
--- a/target/pom-transformed.xml
+++ b/target/pom-transformed.xml
@@ -1,156 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<description>
Cassidy is a Scala wrapper around Cassandra
</description>
<organization>
<name>Foldleft</name>
<url>http://foldleft.se</url>
</organization>
<licenses>
<license>
<name>the Apache License, ASL Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>viktorklang</id>
<name>Viktor Klang</name>
<timezone>+1</timezone>
<email>viktor.klang [at] gmail.com</email>
<roles>
<role>BDFL</role>
</roles>
</developer>
</developers>
<properties>
<scala.version>2.7.5</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.4.0-SNAPSHOT</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>javautils</artifactId>
<version>2.7.4-0.1</version>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ </archive>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
<!--<args>
<arg></arg>
</args>-->
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
|
mccv/Cassidy
|
0ef536982c5e50612b3373ec8d11efd505b2166c
|
Refined 0.4.0 iface
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index eb39e07..6b6a8fa 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,126 +1,155 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
-
- def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] = {
+ val consistencyLevel : Int
+
+ def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int) : List[Column] =
+ /(keyspace,key,columnParent,start,end,ascending,count,consistencyLevel)
+
+ def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] =
client.get_slice(keyspace, key, columnParent, start, end, ascending, count, consistencyLevel).toList
- }
- def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] = {
+ def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]]) : List[Column] =
+ /(keyspace,key,columnParent,colNames,consistencyLevel)
+
+ def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] =
client.get_slice_by_names(keyspace, key, columnParent, colNames.asJava, consistencyLevel ).toList
- }
- def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[Column] = {
+ def |(keyspace : String, key : String, colPath : ColumnPath) : Option[Column] =
+ |(keyspace,key,colPath,consistencyLevel)
+
+ def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[Column] =
client.get_column(keyspace, key, colPath, consistencyLevel)
- }
- def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int = {
+ def |#(keyspace : String, key : String, columnParent : ColumnParent) : Int =
+ |#(keyspace,key,columnParent,consistencyLevel)
+
+ def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int =
client.get_column_count(keyspace, key, columnParent, consistencyLevel)
- }
- def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) = {
+ def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte]) : Unit =
+ ++|(keyspace,key,columnPath,value,obtainedAt,consistencyLevel)
+
+ def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long) : Unit =
+ ++|(keyspace,key,columnPath,value,timestamp,consistencyLevel)
+
+ def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) =
client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
- }
- def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) = {
+ def ++|(keyspace : String, batch : BatchMutation) : Unit =
+ ++|(keyspace, batch, consistencyLevel)
+
+ def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) :Unit =
client.batch_insert(keyspace, batch, consistencyLevel)
- }
- def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long, consistencyLevel : Int) = {
+ def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long) : Unit =
+ --(keyspace,key,columnPathOrParent,timestamp,consistencyLevel)
+
+ def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long, consistencyLevel : Int) : Unit =
client.remove(keyspace, key, columnPathOrParent, timestamp, consistencyLevel)
- }
- def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], isAscending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] = {
- client.get_slice_super(keyspace, key,columnFamily, start, end,isAscending,consistencyLevel).toList
- }
+ def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], ascending : Boolean, count : Int) : List[SuperColumn] =
+ /^(keyspace,key,columnFamily,start,end,ascending,count,consistencyLevel)
+
+ def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], isAscending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] =
+ client.get_slice_super(keyspace, key,columnFamily, start, end,isAscending,count,consistencyLevel).toList
- def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] = {
+ def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]]) : List[SuperColumn] =
+ /^(keyspace,key,columnFamily,superColNames,consistencyLevel)
+
+ def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] =
client.get_slice_super_by_names(keyspace, key, columnFamily, superColNames.asJava,consistencyLevel).toList
- }
- def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath,consistencyLevel : Int) : Option[SuperColumn] = {
+ def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath) : Option[SuperColumn] =
+ |^(keyspace,key,superColumnPath,consistencyLevel)
+
+ def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath,consistencyLevel : Int) : Option[SuperColumn] =
client.get_super_column(keyspace,key,superColumnPath,consistencyLevel)
- }
- def ++|^ (batch : BatchMutationSuper, consistencyLevel : Int) = {
- client.batch_insert_super_column(batch, consistencyLevel)
- }
+ def ++|^ (keyspace : String, batch : BatchMutationSuper) : Unit =
+ ++|^ (keyspace, batch,consistencyLevel)
+
+ def ++|^ (keyspace : String, batch : BatchMutationSuper, consistencyLevel : Int) : Unit =
+ client.batch_insert_super_column(keyspace, batch, consistencyLevel)
def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.get_string_property(name)
def properties(name : String) : List[String] = client.get_string_list_property(name).toList
def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
def ?(query : String) = client.execute_query(query)
}
-class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
+class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol, defConsistency : Int) extends Closeable
{
- def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
-
- def newSession : Session = {
+ def this(transportPool : Pool[T], ioProtocol : Protocol,consistencyLevel : Int) = this(transportPool,ioProtocol,ioProtocol,consistencyLevel)
+
+ def newSession : Session = newSession(defConsistency)
+
+ def newSession(consistency : Int) : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
+ val consistencyLevel = consistency //What's the sensible default?
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index e06ae0a..6886d8d 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,32 +1,32 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
- val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
+ val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary,10)
c.doWork { s => {
val user_id = "1"
// s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
//s.++|("users",user_id,"base_attributes:age", "24", false)
//for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
()
}
}
}
}
\ No newline at end of file
diff --git a/target/cassidy-0.1.jar b/target/cassidy-0.1.jar
new file mode 100644
index 0000000..e8ecb49
Binary files /dev/null and b/target/cassidy-0.1.jar differ
diff --git a/target/classes.timestamp b/target/classes.timestamp
new file mode 100644
index 0000000..945c9b4
--- /dev/null
+++ b/target/classes.timestamp
@@ -0,0 +1 @@
+.
\ No newline at end of file
diff --git a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class
new file mode 100644
index 0000000..65e97d2
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Cassidy.class b/target/classes/se/foldleft/cassidy/Cassidy.class
new file mode 100644
index 0000000..112a0ab
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Cassidy.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class
new file mode 100644
index 0000000..5fcafc1
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$.class b/target/classes/se/foldleft/cassidy/Main$.class
new file mode 100644
index 0000000..2ce1e12
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main.class b/target/classes/se/foldleft/cassidy/Main.class
new file mode 100644
index 0000000..047a56c
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$.class b/target/classes/se/foldleft/cassidy/Protocol$.class
new file mode 100644
index 0000000..fde0817
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class
new file mode 100644
index 0000000..34d2a12
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class
new file mode 100644
index 0000000..bed083d
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class
new file mode 100644
index 0000000..7a2d5ee
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol.class b/target/classes/se/foldleft/cassidy/Protocol.class
new file mode 100644
index 0000000..44a742f
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class
new file mode 100644
index 0000000..2a87314
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$class.class b/target/classes/se/foldleft/cassidy/Session$class.class
new file mode 100644
index 0000000..2a343d0
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$class.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session.class b/target/classes/se/foldleft/cassidy/Session.class
new file mode 100644
index 0000000..62cf68d
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session.class differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider$.class b/target/classes/se/foldleft/cassidy/SocketProvider$.class
new file mode 100644
index 0000000..1be9073
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/SocketProvider$.class differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider.class b/target/classes/se/foldleft/cassidy/SocketProvider.class
new file mode 100644
index 0000000..0c44145
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/SocketProvider.class differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory$class.class b/target/classes/se/foldleft/cassidy/TransportFactory$class.class
new file mode 100644
index 0000000..cffadc3
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/TransportFactory$class.class differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory.class b/target/classes/se/foldleft/cassidy/TransportFactory.class
new file mode 100644
index 0000000..574e087
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/TransportFactory.class differ
diff --git a/target/classes/se/foldleft/pool/Pool.class b/target/classes/se/foldleft/pool/Pool.class
new file mode 100644
index 0000000..f20fa6a
Binary files /dev/null and b/target/classes/se/foldleft/pool/Pool.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class b/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class
new file mode 100644
index 0000000..a9ec43a
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$class.class b/target/classes/se/foldleft/pool/PoolBridge$class.class
new file mode 100644
index 0000000..c5c9a37
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge$class.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge.class b/target/classes/se/foldleft/pool/PoolBridge.class
new file mode 100644
index 0000000..68edc29
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge.class differ
diff --git a/target/classes/se/foldleft/pool/PoolFactory.class b/target/classes/se/foldleft/pool/PoolFactory.class
new file mode 100644
index 0000000..298d4ab
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolFactory.class differ
diff --git a/target/classes/se/foldleft/pool/PoolItemFactory.class b/target/classes/se/foldleft/pool/PoolItemFactory.class
new file mode 100644
index 0000000..6d653b9
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolItemFactory.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class
new file mode 100644
index 0000000..857114d
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class
new file mode 100644
index 0000000..3d257b8
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$.class b/target/classes/se/foldleft/pool/SoftRefPool$.class
new file mode 100644
index 0000000..5410642
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool.class b/target/classes/se/foldleft/pool/SoftRefPool.class
new file mode 100644
index 0000000..37007a1
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$1.class b/target/classes/se/foldleft/pool/StackPool$$anon$1.class
new file mode 100644
index 0000000..0221a15
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$1.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$2.class b/target/classes/se/foldleft/pool/StackPool$$anon$2.class
new file mode 100644
index 0000000..9d289bd
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$2.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$3.class b/target/classes/se/foldleft/pool/StackPool$$anon$3.class
new file mode 100644
index 0000000..68e18be
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$3.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$.class b/target/classes/se/foldleft/pool/StackPool$.class
new file mode 100644
index 0000000..43d02c0
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool.class b/target/classes/se/foldleft/pool/StackPool.class
new file mode 100644
index 0000000..d9bb3b8
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..edb8f64
--- /dev/null
+++ b/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Mon Aug 03 21:47:39 CEST 2009
+version=0.1
+groupId=se.foldleft
+artifactId=cassidy
diff --git a/target/pom-transformed.xml b/target/pom-transformed.xml
new file mode 100644
index 0000000..51da034
--- /dev/null
+++ b/target/pom-transformed.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>se.foldleft</groupId>
+ <artifactId>cassidy</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <name>Cassidy 0.1</name>
+ <url>git@github.com/viktorklang/Cassidy.git</url>
+ <inceptionYear>2009</inceptionYear>
+ <description>
+ Cassidy is a Scala wrapper around Cassandra
+ </description>
+ <organization>
+ <name>Foldleft</name>
+ <url>http://foldleft.se</url>
+ </organization>
+ <licenses>
+ <license>
+ <name>the Apache License, ASL Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <developers>
+ <developer>
+ <id>viktorklang</id>
+ <name>Viktor Klang</name>
+ <timezone>+1</timezone>
+ <email>viktor.klang [at] gmail.com</email>
+ <roles>
+ <role>BDFL</role>
+ </roles>
+ </developer>
+ </developers>
+ <properties>
+ <scala.version>2.7.5</scala.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ <repository>
+ <id>central</id>
+ <name>Maven Repository Switchboard</name>
+ <layout>default</layout>
+ <url>http://repo1.maven.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>embedded</id>
+ <name>Project Embbed Repository</name>
+ <url>file://${basedir}/repo-embedded</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.5.1</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.7.5</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>cassandra</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>thrift</artifactId>
+ <version>0.1</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>javautils</artifactId>
+ <version>2.7.4-0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-tools.testing</groupId>
+ <artifactId>specs</artifactId>
+ <version>1.5.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.10.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ <args>
+ <arg>-target:jvm-1.5</arg>
+ <arg>-unchecked</arg>
+ </args>
+ <launchers>
+ <launcher>
+ <id>main-launcher</id>
+ <mainClass>se.foldleft.cassidy.Main</mainClass>
+ <!--<args>
+ <arg></arg>
+ </args>-->
+ </launcher>
+ </launchers>
+
+ <jvmArgs>
+ <jvmArg>-Xmx1024m</jvmArg>
+ </jvmArgs>
+ <args>
+ <arg>-unchecked</arg>
+ <arg>-deprecation</arg>
+ <arg>-Xno-varargs-conversion</arg>
+ </args>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
|
mccv/Cassidy
|
e7849d3211579228dd36ac5004fe4b5c53fbc969
|
Upgraded to Cassandra 0.4.0-SNAPSHOT
|
diff --git a/pom.xml b/pom.xml
index 8d5ab05..51da034 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,156 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<description>
Cassidy is a Scala wrapper around Cassandra
</description>
<organization>
<name>Foldleft</name>
<url>http://foldleft.se</url>
</organization>
<licenses>
<license>
<name>the Apache License, ASL Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>viktorklang</id>
<name>Viktor Klang</name>
<timezone>+1</timezone>
<email>viktor.klang [at] gmail.com</email>
<roles>
<role>BDFL</role>
</roles>
</developer>
</developers>
<properties>
<scala.version>2.7.5</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
- <version>0.3.0</version>
+ <version>0.4.0-SNAPSHOT</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>javautils</artifactId>
<version>2.7.4-0.1</version>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
<!--<args>
<arg></arg>
</args>-->
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 323f274..eb39e07 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,138 +1,126 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
val obtainedAt : Long
- def /(tableName : String, key : String, columnParent : String, start : Option[Int],end : Option[Int]) : List[column_t] = {
- client.get_slice(tableName, key, columnParent, start.getOrElse(-1),end.getOrElse(-1)).toList
- }
-
- def /(tableName : String, key : String, columnParent : String, colNames : List[String]) : List[column_t] = {
- client.get_slice_by_names(tableName, key, columnParent, colNames.asJava ).toList
- }
-
- def |(tableName : String, key : String, colPath : String) : Option[column_t] = {
- client.get_column(tableName, key, colPath)
- }
-
- def |#(tableName : String, key : String, columnParent : String) : Int = {
- client.get_column_count(tableName, key, columnParent)
+ def /(keyspace : String, key : String, columnParent : ColumnParent, start : Array[Byte],end : Array[Byte], ascending : Boolean, count : Int, consistencyLevel : Int) : List[Column] = {
+ client.get_slice(keyspace, key, columnParent, start, end, ascending, count, consistencyLevel).toList
}
- def ++|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], timestamp : Long, block : Boolean) = {
- client.insert(tableName, key, columnPath, cellData,timestamp,block)
+ def /(keyspace : String, key : String, columnParent : ColumnParent, colNames : List[Array[Byte]], consistencyLevel : Int) : List[Column] = {
+ client.get_slice_by_names(keyspace, key, columnParent, colNames.asJava, consistencyLevel ).toList
}
- def ++|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], block : Boolean) = {
- client.insert(tableName,key,columnPath,cellData,obtainedAt,block)
+ def |(keyspace : String, key : String, colPath : ColumnPath, consistencyLevel : Int) : Option[Column] = {
+ client.get_column(keyspace, key, colPath, consistencyLevel)
}
- def ++|(batch : batch_mutation_t, block : Boolean) = {
- client.batch_insert(batch, block)
+ def |#(keyspace : String, key : String, columnParent : ColumnParent, consistencyLevel : Int) : Int = {
+ client.get_column_count(keyspace, key, columnParent, consistencyLevel)
}
- def --(tableName : String, key : String, columnPathOrParent : String, timestamp : Long, block : Boolean) = {
- client.remove(tableName, key, columnPathOrParent, timestamp, block)
+ def ++|(keyspace : String, key : String, columnPath : ColumnPath, value : Array[Byte], timestamp : Long, consistencyLevel : Int) = {
+ client.insert(keyspace, key, columnPath, value,timestamp,consistencyLevel)
}
- def --(tableName : String, key : String, columnPathOrParent : String, block : Boolean) = {
- client.remove(tableName, key, columnPathOrParent, obtainedAt, block)
+ def ++|(keyspace : String, batch : BatchMutation, consistencyLevel : Int) = {
+ client.batch_insert(keyspace, batch, consistencyLevel)
}
- def /@(tableName : String, key : String, columnParent : String, timestamp : Long) : List[column_t] = {
- client.get_columns_since(tableName, key, columnParent, timestamp).toList
+ def --(keyspace : String, key : String, columnPathOrParent : ColumnPathOrParent, timestamp : Long, consistencyLevel : Int) = {
+ client.remove(keyspace, key, columnPathOrParent, timestamp, consistencyLevel)
}
- def /^(tableName : String, key : String, columnFamily : String, start : Option[Int], end : Option[Int], count : Int ) : List[superColumn_t] = {
- client.get_slice_super(tableName, key,columnFamily, start.getOrElse(-1), end.getOrElse(-1)).toList //TODO upgrade thrift interface to support count
+ def /^(keyspace : String, key : String, columnFamily : String, start : Array[Byte], end : Array[Byte], isAscending : Boolean, count : Int, consistencyLevel : Int ) : List[SuperColumn] = {
+ client.get_slice_super(keyspace, key,columnFamily, start, end,isAscending,consistencyLevel).toList
}
- def /^(tableName : String, key : String, columnFamily : String, superColNames : List[String]) : List[superColumn_t] = {
- client.get_slice_super_by_names(tableName, key, columnFamily, superColNames.asJava).toList
+ def /^(keyspace : String, key : String, columnFamily : String, superColNames : List[Array[Byte]], consistencyLevel : Int) : List[SuperColumn] = {
+ client.get_slice_super_by_names(keyspace, key, columnFamily, superColNames.asJava,consistencyLevel).toList
}
- def |^(tableName : String, key : String, superColumnPath : String) : Option[superColumn_t] = {
- client.get_superColumn(tableName,key,superColumnPath)
+ def |^(keyspace : String, key : String, superColumnPath : SuperColumnPath,consistencyLevel : Int) : Option[SuperColumn] = {
+ client.get_super_column(keyspace,key,superColumnPath,consistencyLevel)
}
- def ++|^ (batch : batch_mutation_super_t, block : Boolean) = {
- client.batch_insert_superColumn(batch, block)
+ def ++|^ (batch : BatchMutationSuper, consistencyLevel : Int) = {
+ client.batch_insert_super_column(batch, consistencyLevel)
}
- def keys(tableName : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
- client.get_key_range(tableName, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
+ def keys(keyspace : String, columnFamily : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
+ client.get_key_range(keyspace, columnFamily, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
- def property(name : String) : String = client.getStringProperty(name)
- def properties(name : String) : List[String] = client.getStringListProperty(name).toList
- def describeTable(tableName : String) = client.describeTable(tableName)
+ def property(name : String) : String = client.get_string_property(name)
+ def properties(name : String) : List[String] = client.get_string_list_property(name).toList
+ def describeTable(keyspace : String) = client.describe_keyspace(keyspace)
- def ?(query : String) = client.executeQuery(query)
+ def ?(query : String) = client.execute_query(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
val obtainedAt = System.currentTimeMillis
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index dedc7cd..e06ae0a 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,32 +1,32 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
c.doWork { s => {
val user_id = "1"
- s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
- s.++|("users",user_id,"base_attributes:age", "24", false)
+ // s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
+ //s.++|("users",user_id,"base_attributes:age", "24", false)
- for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
+ //for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
-
+ ()
}
}
}
}
\ No newline at end of file
diff --git a/target/cassidy-0.1.jar b/target/cassidy-0.1.jar
deleted file mode 100644
index 12e60d4..0000000
Binary files a/target/cassidy-0.1.jar and /dev/null differ
diff --git a/target/classes.timestamp b/target/classes.timestamp
deleted file mode 100644
index 945c9b4..0000000
--- a/target/classes.timestamp
+++ /dev/null
@@ -1 +0,0 @@
-.
\ No newline at end of file
diff --git a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class
deleted file mode 100644
index 3f05fed..0000000
Binary files a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Cassidy.class b/target/classes/se/foldleft/cassidy/Cassidy.class
deleted file mode 100644
index d4c35af..0000000
Binary files a/target/classes/se/foldleft/cassidy/Cassidy.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class
deleted file mode 100644
index 4769937..0000000
Binary files a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class
deleted file mode 100644
index ee7292e..0000000
Binary files a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Main$.class b/target/classes/se/foldleft/cassidy/Main$.class
deleted file mode 100644
index ba0d40b..0000000
Binary files a/target/classes/se/foldleft/cassidy/Main$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Main.class b/target/classes/se/foldleft/cassidy/Main.class
deleted file mode 100644
index afb7ae2..0000000
Binary files a/target/classes/se/foldleft/cassidy/Main.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$.class b/target/classes/se/foldleft/cassidy/Protocol$.class
deleted file mode 100644
index 17b5407..0000000
Binary files a/target/classes/se/foldleft/cassidy/Protocol$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class
deleted file mode 100644
index c1c5d2c..0000000
Binary files a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class
deleted file mode 100644
index e2f93d2..0000000
Binary files a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class
deleted file mode 100644
index 00cb623..0000000
Binary files a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol.class b/target/classes/se/foldleft/cassidy/Protocol.class
deleted file mode 100644
index 267925e..0000000
Binary files a/target/classes/se/foldleft/cassidy/Protocol.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class
deleted file mode 100644
index 740e5a5..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class
deleted file mode 100644
index ceacbf6..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class
deleted file mode 100644
index 18da94e..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class
deleted file mode 100644
index 2c12484..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class
deleted file mode 100644
index c6692f7..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session$class.class b/target/classes/se/foldleft/cassidy/Session$class.class
deleted file mode 100644
index 75d8ade..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session$class.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/Session.class b/target/classes/se/foldleft/cassidy/Session.class
deleted file mode 100644
index 9a3157c..0000000
Binary files a/target/classes/se/foldleft/cassidy/Session.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider$.class b/target/classes/se/foldleft/cassidy/SocketProvider$.class
deleted file mode 100644
index 1be9073..0000000
Binary files a/target/classes/se/foldleft/cassidy/SocketProvider$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider.class b/target/classes/se/foldleft/cassidy/SocketProvider.class
deleted file mode 100644
index 0c44145..0000000
Binary files a/target/classes/se/foldleft/cassidy/SocketProvider.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory$class.class b/target/classes/se/foldleft/cassidy/TransportFactory$class.class
deleted file mode 100644
index cffadc3..0000000
Binary files a/target/classes/se/foldleft/cassidy/TransportFactory$class.class and /dev/null differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory.class b/target/classes/se/foldleft/cassidy/TransportFactory.class
deleted file mode 100644
index 574e087..0000000
Binary files a/target/classes/se/foldleft/cassidy/TransportFactory.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/Pool.class b/target/classes/se/foldleft/pool/Pool.class
deleted file mode 100644
index f20fa6a..0000000
Binary files a/target/classes/se/foldleft/pool/Pool.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class b/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class
deleted file mode 100644
index a9ec43a..0000000
Binary files a/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$class.class b/target/classes/se/foldleft/pool/PoolBridge$class.class
deleted file mode 100644
index c5c9a37..0000000
Binary files a/target/classes/se/foldleft/pool/PoolBridge$class.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge.class b/target/classes/se/foldleft/pool/PoolBridge.class
deleted file mode 100644
index 68edc29..0000000
Binary files a/target/classes/se/foldleft/pool/PoolBridge.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/PoolFactory.class b/target/classes/se/foldleft/pool/PoolFactory.class
deleted file mode 100644
index 298d4ab..0000000
Binary files a/target/classes/se/foldleft/pool/PoolFactory.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/PoolItemFactory.class b/target/classes/se/foldleft/pool/PoolItemFactory.class
deleted file mode 100644
index 6d653b9..0000000
Binary files a/target/classes/se/foldleft/pool/PoolItemFactory.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class
deleted file mode 100644
index 857114d..0000000
Binary files a/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class
deleted file mode 100644
index 3d257b8..0000000
Binary files a/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$.class b/target/classes/se/foldleft/pool/SoftRefPool$.class
deleted file mode 100644
index 5410642..0000000
Binary files a/target/classes/se/foldleft/pool/SoftRefPool$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool.class b/target/classes/se/foldleft/pool/SoftRefPool.class
deleted file mode 100644
index 37007a1..0000000
Binary files a/target/classes/se/foldleft/pool/SoftRefPool.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$1.class b/target/classes/se/foldleft/pool/StackPool$$anon$1.class
deleted file mode 100644
index 0221a15..0000000
Binary files a/target/classes/se/foldleft/pool/StackPool$$anon$1.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$2.class b/target/classes/se/foldleft/pool/StackPool$$anon$2.class
deleted file mode 100644
index 9d289bd..0000000
Binary files a/target/classes/se/foldleft/pool/StackPool$$anon$2.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$3.class b/target/classes/se/foldleft/pool/StackPool$$anon$3.class
deleted file mode 100644
index 68e18be..0000000
Binary files a/target/classes/se/foldleft/pool/StackPool$$anon$3.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/StackPool$.class b/target/classes/se/foldleft/pool/StackPool$.class
deleted file mode 100644
index 43d02c0..0000000
Binary files a/target/classes/se/foldleft/pool/StackPool$.class and /dev/null differ
diff --git a/target/classes/se/foldleft/pool/StackPool.class b/target/classes/se/foldleft/pool/StackPool.class
deleted file mode 100644
index d9bb3b8..0000000
Binary files a/target/classes/se/foldleft/pool/StackPool.class and /dev/null differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
deleted file mode 100644
index 6292857..0000000
--- a/target/maven-archiver/pom.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-#Generated by Maven
-#Sun Aug 02 18:43:34 CEST 2009
-version=0.1
-groupId=se.foldleft
-artifactId=cassidy
diff --git a/target/pom-transformed.xml b/target/pom-transformed.xml
deleted file mode 100644
index 8d5ab05..0000000
--- a/target/pom-transformed.xml
+++ /dev/null
@@ -1,156 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>se.foldleft</groupId>
- <artifactId>cassidy</artifactId>
- <packaging>jar</packaging>
- <version>0.1</version>
- <name>Cassidy 0.1</name>
- <url>git@github.com/viktorklang/Cassidy.git</url>
- <inceptionYear>2009</inceptionYear>
- <description>
- Cassidy is a Scala wrapper around Cassandra
- </description>
- <organization>
- <name>Foldleft</name>
- <url>http://foldleft.se</url>
- </organization>
- <licenses>
- <license>
- <name>the Apache License, ASL Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- <developers>
- <developer>
- <id>viktorklang</id>
- <name>Viktor Klang</name>
- <timezone>+1</timezone>
- <email>viktor.klang [at] gmail.com</email>
- <roles>
- <role>BDFL</role>
- </roles>
- </developer>
- </developers>
- <properties>
- <scala.version>2.7.5</scala.version>
- </properties>
- <repositories>
- <repository>
- <id>scala-tools.org</id>
- <name>Scala-Tools Maven2 Repository</name>
- <url>http://scala-tools.org/repo-releases</url>
- </repository>
- <repository>
- <id>central</id>
- <name>Maven Repository Switchboard</name>
- <layout>default</layout>
- <url>http://repo1.maven.org/maven2</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
- <id>embedded</id>
- <name>Project Embbed Repository</name>
- <url>file://${basedir}/repo-embedded</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- <version>1.5.1</version>
- <optional>false</optional>
- </dependency>
- <dependency>
- <groupId>org.scala-lang</groupId>
- <artifactId>scala-library</artifactId>
- <version>2.7.5</version>
- <optional>false</optional>
- </dependency>
- <dependency>
- <groupId>org.apache</groupId>
- <artifactId>cassandra</artifactId>
- <version>0.3.0</version>
- <optional>false</optional>
- </dependency>
- <dependency>
- <groupId>org.apache</groupId>
- <artifactId>thrift</artifactId>
- <version>0.1</version>
- <optional>false</optional>
- </dependency>
- <dependency>
- <groupId>org.scala-tools</groupId>
- <artifactId>javautils</artifactId>
- <version>2.7.4-0.1</version>
- </dependency>
- <dependency>
- <groupId>org.scala-tools.testing</groupId>
- <artifactId>specs</artifactId>
- <version>1.5.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.14</version>
- </dependency>
- </dependencies>
- <build>
- <sourceDirectory>src/main/scala</sourceDirectory>
- <testSourceDirectory>src/test/scala</testSourceDirectory>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
- <version>2.10.1</version>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <scalaVersion>${scala.version}</scalaVersion>
- <args>
- <arg>-target:jvm-1.5</arg>
- <arg>-unchecked</arg>
- </args>
- <launchers>
- <launcher>
- <id>main-launcher</id>
- <mainClass>se.foldleft.cassidy.Main</mainClass>
- <!--<args>
- <arg></arg>
- </args>-->
- </launcher>
- </launchers>
-
- <jvmArgs>
- <jvmArg>-Xmx1024m</jvmArg>
- </jvmArgs>
- <args>
- <arg>-unchecked</arg>
- <arg>-deprecation</arg>
- <arg>-Xno-varargs-conversion</arg>
- </args>
- <scalaVersion>${scala.version}</scalaVersion>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
\ No newline at end of file
|
mccv/Cassidy
|
702dfbc8fdb1d8f000762fd1975522dfd42c6060
|
Moved to Cassandra 0.4-SNAPSHOT
|
diff --git a/nbactions.xml b/nbactions.xml
new file mode 100644
index 0000000..e689f3e
--- /dev/null
+++ b/nbactions.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+ <action>
+ <actionName>run</actionName>
+ <goals>
+ <goal>scala:run</goal>
+ </goals>
+ </action>
+ <action>
+ <actionName>debug</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
+ </goals>
+ <properties>
+ <exec.workingdir>/Users/foldLeft/Documents/workspace/Cassidy</exec.workingdir>
+ <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.foldleft.cassidy.Main</exec.args>
+ <jpda.listen>true</jpda.listen>
+ <exec.executable>java</exec.executable>
+ </properties>
+ </action>
+ <action>
+ <actionName>profile</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
+ </goals>
+ <properties>
+ <exec.workingdir>/Users/foldLeft/Documents/workspace/Cassidy</exec.workingdir>
+ <exec.args>${profiler.args} -classpath %classpath org.foldleft.cassidy.Main</exec.args>
+ <profiler.action>profile</profiler.action>
+ <exec.executable>${profiler.java}</exec.executable>
+ </properties>
+ </action>
+ </actions>
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar
deleted file mode 100644
index e035153..0000000
Binary files a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar and /dev/null differ
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/LICENSE.txt b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/LICENSE.txt
similarity index 100%
rename from repo-embedded/org/apache/cassandra/0.3.0/LICENSE.txt
rename to repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/LICENSE.txt
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/NOTICE.txt b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/NOTICE.txt
similarity index 100%
rename from repo-embedded/org/apache/cassandra/0.3.0/NOTICE.txt
rename to repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/NOTICE.txt
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/README.txt b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/README.txt
similarity index 100%
rename from repo-embedded/org/apache/cassandra/0.3.0/README.txt
rename to repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/README.txt
diff --git a/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar
new file mode 100644
index 0000000..7240f0f
Binary files /dev/null and b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.jar differ
diff --git a/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.pom b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.pom
new file mode 100644
index 0000000..a9ae069
--- /dev/null
+++ b/repo-embedded/org/apache/cassandra/0.4.0-SNAPSHOT/cassandra-0.4.0-SNAPSHOT.pom
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache</groupId>
+ <artifactId>cassandra</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar b/repo-embedded/org/apache/thrift/1.0/thrift-1.0.jar
similarity index 100%
rename from repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar
rename to repo-embedded/org/apache/thrift/1.0/thrift-1.0.jar
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar.LICENSE b/repo-embedded/org/apache/thrift/1.0/thrift-1.0.jar.LICENSE
similarity index 100%
rename from repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar.LICENSE
rename to repo-embedded/org/apache/thrift/1.0/thrift-1.0.jar.LICENSE
diff --git a/repo-embedded/org/apache/thrift/1.0/thrift-1.0.pom b/repo-embedded/org/apache/thrift/1.0/thrift-1.0.pom
new file mode 100644
index 0000000..6bbf048
--- /dev/null
+++ b/repo-embedded/org/apache/thrift/1.0/thrift-1.0.pom
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache</groupId>
+ <artifactId>thrift</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+</project>
\ No newline at end of file
diff --git a/target/cassidy-0.1.jar b/target/cassidy-0.1.jar
new file mode 100644
index 0000000..12e60d4
Binary files /dev/null and b/target/cassidy-0.1.jar differ
diff --git a/target/classes.timestamp b/target/classes.timestamp
new file mode 100644
index 0000000..945c9b4
--- /dev/null
+++ b/target/classes.timestamp
@@ -0,0 +1 @@
+.
\ No newline at end of file
diff --git a/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class
new file mode 100644
index 0000000..3f05fed
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Cassidy$$anon$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Cassidy.class b/target/classes/se/foldleft/cassidy/Cassidy.class
new file mode 100644
index 0000000..d4c35af
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Cassidy.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class
new file mode 100644
index 0000000..4769937
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1$$anonfun$apply$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class
new file mode 100644
index 0000000..ee7292e
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main$$anonfun$main$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main$.class b/target/classes/se/foldleft/cassidy/Main$.class
new file mode 100644
index 0000000..ba0d40b
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Main.class b/target/classes/se/foldleft/cassidy/Main.class
new file mode 100644
index 0000000..afb7ae2
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Main.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$.class b/target/classes/se/foldleft/cassidy/Protocol$.class
new file mode 100644
index 0000000..17b5407
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$Binary$.class b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class
new file mode 100644
index 0000000..c1c5d2c
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$Binary$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$JSON$.class b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class
new file mode 100644
index 0000000..e2f93d2
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$JSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class
new file mode 100644
index 0000000..00cb623
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol$SimpleJSON$.class differ
diff --git a/target/classes/se/foldleft/cassidy/Protocol.class b/target/classes/se/foldleft/cassidy/Protocol.class
new file mode 100644
index 0000000..267925e
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Protocol.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class
new file mode 100644
index 0000000..740e5a5
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class
new file mode 100644
index 0000000..ceacbf6
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$2.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class
new file mode 100644
index 0000000..18da94e
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class
new file mode 100644
index 0000000..2c12484
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$$div$up$2.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class
new file mode 100644
index 0000000..c6692f7
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$$anonfun$keys$1.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session$class.class b/target/classes/se/foldleft/cassidy/Session$class.class
new file mode 100644
index 0000000..75d8ade
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session$class.class differ
diff --git a/target/classes/se/foldleft/cassidy/Session.class b/target/classes/se/foldleft/cassidy/Session.class
new file mode 100644
index 0000000..9a3157c
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/Session.class differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider$.class b/target/classes/se/foldleft/cassidy/SocketProvider$.class
new file mode 100644
index 0000000..1be9073
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/SocketProvider$.class differ
diff --git a/target/classes/se/foldleft/cassidy/SocketProvider.class b/target/classes/se/foldleft/cassidy/SocketProvider.class
new file mode 100644
index 0000000..0c44145
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/SocketProvider.class differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory$class.class b/target/classes/se/foldleft/cassidy/TransportFactory$class.class
new file mode 100644
index 0000000..cffadc3
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/TransportFactory$class.class differ
diff --git a/target/classes/se/foldleft/cassidy/TransportFactory.class b/target/classes/se/foldleft/cassidy/TransportFactory.class
new file mode 100644
index 0000000..574e087
Binary files /dev/null and b/target/classes/se/foldleft/cassidy/TransportFactory.class differ
diff --git a/target/classes/se/foldleft/pool/Pool.class b/target/classes/se/foldleft/pool/Pool.class
new file mode 100644
index 0000000..f20fa6a
Binary files /dev/null and b/target/classes/se/foldleft/pool/Pool.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class b/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class
new file mode 100644
index 0000000..a9ec43a
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge$$anon$6.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge$class.class b/target/classes/se/foldleft/pool/PoolBridge$class.class
new file mode 100644
index 0000000..c5c9a37
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge$class.class differ
diff --git a/target/classes/se/foldleft/pool/PoolBridge.class b/target/classes/se/foldleft/pool/PoolBridge.class
new file mode 100644
index 0000000..68edc29
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolBridge.class differ
diff --git a/target/classes/se/foldleft/pool/PoolFactory.class b/target/classes/se/foldleft/pool/PoolFactory.class
new file mode 100644
index 0000000..298d4ab
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolFactory.class differ
diff --git a/target/classes/se/foldleft/pool/PoolItemFactory.class b/target/classes/se/foldleft/pool/PoolItemFactory.class
new file mode 100644
index 0000000..6d653b9
Binary files /dev/null and b/target/classes/se/foldleft/pool/PoolItemFactory.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class
new file mode 100644
index 0000000..857114d
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$$anon$4.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class b/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class
new file mode 100644
index 0000000..3d257b8
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$$anon$5.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool$.class b/target/classes/se/foldleft/pool/SoftRefPool$.class
new file mode 100644
index 0000000..5410642
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool$.class differ
diff --git a/target/classes/se/foldleft/pool/SoftRefPool.class b/target/classes/se/foldleft/pool/SoftRefPool.class
new file mode 100644
index 0000000..37007a1
Binary files /dev/null and b/target/classes/se/foldleft/pool/SoftRefPool.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$1.class b/target/classes/se/foldleft/pool/StackPool$$anon$1.class
new file mode 100644
index 0000000..0221a15
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$1.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$2.class b/target/classes/se/foldleft/pool/StackPool$$anon$2.class
new file mode 100644
index 0000000..9d289bd
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$2.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$$anon$3.class b/target/classes/se/foldleft/pool/StackPool$$anon$3.class
new file mode 100644
index 0000000..68e18be
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$$anon$3.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool$.class b/target/classes/se/foldleft/pool/StackPool$.class
new file mode 100644
index 0000000..43d02c0
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool$.class differ
diff --git a/target/classes/se/foldleft/pool/StackPool.class b/target/classes/se/foldleft/pool/StackPool.class
new file mode 100644
index 0000000..d9bb3b8
Binary files /dev/null and b/target/classes/se/foldleft/pool/StackPool.class differ
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..6292857
--- /dev/null
+++ b/target/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Sun Aug 02 18:43:34 CEST 2009
+version=0.1
+groupId=se.foldleft
+artifactId=cassidy
diff --git a/target/pom-transformed.xml b/target/pom-transformed.xml
new file mode 100644
index 0000000..8d5ab05
--- /dev/null
+++ b/target/pom-transformed.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>se.foldleft</groupId>
+ <artifactId>cassidy</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <name>Cassidy 0.1</name>
+ <url>git@github.com/viktorklang/Cassidy.git</url>
+ <inceptionYear>2009</inceptionYear>
+ <description>
+ Cassidy is a Scala wrapper around Cassandra
+ </description>
+ <organization>
+ <name>Foldleft</name>
+ <url>http://foldleft.se</url>
+ </organization>
+ <licenses>
+ <license>
+ <name>the Apache License, ASL Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <developers>
+ <developer>
+ <id>viktorklang</id>
+ <name>Viktor Klang</name>
+ <timezone>+1</timezone>
+ <email>viktor.klang [at] gmail.com</email>
+ <roles>
+ <role>BDFL</role>
+ </roles>
+ </developer>
+ </developers>
+ <properties>
+ <scala.version>2.7.5</scala.version>
+ </properties>
+ <repositories>
+ <repository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ <repository>
+ <id>central</id>
+ <name>Maven Repository Switchboard</name>
+ <layout>default</layout>
+ <url>http://repo1.maven.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>embedded</id>
+ <name>Project Embbed Repository</name>
+ <url>file://${basedir}/repo-embedded</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.5.1</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.7.5</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>cassandra</artifactId>
+ <version>0.3.0</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache</groupId>
+ <artifactId>thrift</artifactId>
+ <version>0.1</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>javautils</artifactId>
+ <version>2.7.4-0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-tools.testing</groupId>
+ <artifactId>specs</artifactId>
+ <version>1.5.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.10.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ <args>
+ <arg>-target:jvm-1.5</arg>
+ <arg>-unchecked</arg>
+ </args>
+ <launchers>
+ <launcher>
+ <id>main-launcher</id>
+ <mainClass>se.foldleft.cassidy.Main</mainClass>
+ <!--<args>
+ <arg></arg>
+ </args>-->
+ </launcher>
+ </launchers>
+
+ <jvmArgs>
+ <jvmArg>-Xmx1024m</jvmArg>
+ </jvmArgs>
+ <args>
+ <arg>-unchecked</arg>
+ <arg>-deprecation</arg>
+ <arg>-Xno-varargs-conversion</arg>
+ </args>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
|
mccv/Cassidy
|
33765d4cb654ceef9053729ca2669dfc30faaa14
|
Fixed a typo
|
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index e1aa24f..dedc7cd 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,32 +1,32 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
c.doWork { s => {
val user_id = "1"
s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
- s.++|("users",user_id,"base_attributes:name", "24", false)
+ s.++|("users",user_id,"base_attributes:age", "24", false)
for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
}
}
}
}
\ No newline at end of file
|
mccv/Cassidy
|
9a55eead53ce6e941c9b905d7783b32e447e59c8
|
Added Session time synchronization
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 5d4e95b..323f274 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,127 +1,138 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
+
+ val obtainedAt : Long
def /(tableName : String, key : String, columnParent : String, start : Option[Int],end : Option[Int]) : List[column_t] = {
client.get_slice(tableName, key, columnParent, start.getOrElse(-1),end.getOrElse(-1)).toList
}
def /(tableName : String, key : String, columnParent : String, colNames : List[String]) : List[column_t] = {
client.get_slice_by_names(tableName, key, columnParent, colNames.asJava ).toList
}
def |(tableName : String, key : String, colPath : String) : Option[column_t] = {
client.get_column(tableName, key, colPath)
}
def |#(tableName : String, key : String, columnParent : String) : Int = {
client.get_column_count(tableName, key, columnParent)
}
def ++|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], timestamp : Long, block : Boolean) = {
client.insert(tableName, key, columnPath, cellData,timestamp,block)
}
+ def ++|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], block : Boolean) = {
+ client.insert(tableName,key,columnPath,cellData,obtainedAt,block)
+ }
+
def ++|(batch : batch_mutation_t, block : Boolean) = {
client.batch_insert(batch, block)
}
def --(tableName : String, key : String, columnPathOrParent : String, timestamp : Long, block : Boolean) = {
client.remove(tableName, key, columnPathOrParent, timestamp, block)
}
+ def --(tableName : String, key : String, columnPathOrParent : String, block : Boolean) = {
+ client.remove(tableName, key, columnPathOrParent, obtainedAt, block)
+ }
+
def /@(tableName : String, key : String, columnParent : String, timestamp : Long) : List[column_t] = {
client.get_columns_since(tableName, key, columnParent, timestamp).toList
}
def /^(tableName : String, key : String, columnFamily : String, start : Option[Int], end : Option[Int], count : Int ) : List[superColumn_t] = {
client.get_slice_super(tableName, key,columnFamily, start.getOrElse(-1), end.getOrElse(-1)).toList //TODO upgrade thrift interface to support count
}
def /^(tableName : String, key : String, columnFamily : String, superColNames : List[String]) : List[superColumn_t] = {
client.get_slice_super_by_names(tableName, key, columnFamily, superColNames.asJava).toList
}
def |^(tableName : String, key : String, superColumnPath : String) : Option[superColumn_t] = {
client.get_superColumn(tableName,key,superColumnPath)
}
- def ++|^ (batch : batch_mutation_super_t, block : boolean) = {
+ def ++|^ (batch : batch_mutation_super_t, block : Boolean) = {
client.batch_insert_superColumn(batch, block)
}
def keys(tableName : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(tableName, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.getStringProperty(name)
def properties(name : String) : List[String] = client.getStringListProperty(name).toList
def describeTable(tableName : String) = client.describeTable(tableName)
def ?(query : String) = client.executeQuery(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
+ val obtainedAt = System.currentTimeMillis
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index 93b29fa..e1aa24f 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,33 +1,32 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
c.doWork { s => {
val user_id = "1"
- val now = System.currentTimeMillis
- s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", now, false)
- s.++|("users",user_id,"base_attributes:name", "24", now, false)
+ s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", false)
+ s.++|("users",user_id,"base_attributes:name", "24", false)
for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
}
}
}
}
\ No newline at end of file
|
mccv/Cassidy
|
240bcb6b72cadbf9cd8a6c4043af5469749ed6b6
|
Removed clutter
|
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index f3ad706..93b29fa 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,33 +1,33 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
- c.doWork { case s : Session => {
+ c.doWork { s => {
val user_id = "1"
val now = System.currentTimeMillis
s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", now, false)
s.++|("users",user_id,"base_attributes:name", "24", now, false)
for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
}
}
}
}
\ No newline at end of file
|
mccv/Cassidy
|
6d1fbbb99908fef1a3484e5594d892b6b4b52fac
|
Changed demo data
|
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index fb97105..f3ad706 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,33 +1,33 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
c.doWork { case s : Session => {
val user_id = "1"
val now = System.currentTimeMillis
- s.++|("users",user_id,"base_attributes:name", "Chris Goffinet", now, false)
+ s.++|("users",user_id,"base_attributes:name", "Lord Foo Bar", now, false)
s.++|("users",user_id,"base_attributes:name", "24", now, false)
for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
}
}
}
}
\ No newline at end of file
|
mccv/Cassidy
|
3435815d3c6d0ea63728ebe262e2f757f25320d4
|
Changed syntax for insert
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 7db9c2a..5d4e95b 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,127 +1,127 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
import scala.collection.jcl.Conversions._
import org.scala_tools.javautils.Imports._
private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
protected val client : Cassandra.Client
def /(tableName : String, key : String, columnParent : String, start : Option[Int],end : Option[Int]) : List[column_t] = {
client.get_slice(tableName, key, columnParent, start.getOrElse(-1),end.getOrElse(-1)).toList
}
def /(tableName : String, key : String, columnParent : String, colNames : List[String]) : List[column_t] = {
client.get_slice_by_names(tableName, key, columnParent, colNames.asJava ).toList
}
- def <-|(tableName : String, key : String, colPath : String) : Option[column_t] = {
+ def |(tableName : String, key : String, colPath : String) : Option[column_t] = {
client.get_column(tableName, key, colPath)
}
def |#(tableName : String, key : String, columnParent : String) : Int = {
client.get_column_count(tableName, key, columnParent)
}
- def ->|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], timestamp : Long, block : Boolean) = {
+ def ++|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], timestamp : Long, block : Boolean) = {
client.insert(tableName, key, columnPath, cellData,timestamp,block)
}
- def ->|(batch : batch_mutation_t, block : Boolean) = {
+ def ++|(batch : batch_mutation_t, block : Boolean) = {
client.batch_insert(batch, block)
}
def --(tableName : String, key : String, columnPathOrParent : String, timestamp : Long, block : Boolean) = {
client.remove(tableName, key, columnPathOrParent, timestamp, block)
}
def /@(tableName : String, key : String, columnParent : String, timestamp : Long) : List[column_t] = {
client.get_columns_since(tableName, key, columnParent, timestamp).toList
}
def /^(tableName : String, key : String, columnFamily : String, start : Option[Int], end : Option[Int], count : Int ) : List[superColumn_t] = {
client.get_slice_super(tableName, key,columnFamily, start.getOrElse(-1), end.getOrElse(-1)).toList //TODO upgrade thrift interface to support count
}
def /^(tableName : String, key : String, columnFamily : String, superColNames : List[String]) : List[superColumn_t] = {
client.get_slice_super_by_names(tableName, key, columnFamily, superColNames.asJava).toList
}
def |^(tableName : String, key : String, superColumnPath : String) : Option[superColumn_t] = {
client.get_superColumn(tableName,key,superColumnPath)
}
- def ->|^ (batch : batch_mutation_super_t, block : boolean) = {
+ def ++|^ (batch : batch_mutation_super_t, block : boolean) = {
client.batch_insert_superColumn(batch, block)
}
def keys(tableName : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
client.get_key_range(tableName, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
}
def property(name : String) : String = client.getStringProperty(name)
def properties(name : String) : List[String] = client.getStringListProperty(name).toList
def describeTable(tableName : String) = client.describeTable(tableName)
def ?(query : String) = client.executeQuery(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index b7c6d84..fb97105 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,33 +1,33 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
def main(a : Array[String]) : Unit = {
implicit def strToBytes(s : String) = s.getBytes("UTF-8")
import scala.collection.jcl.Conversions._
val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
c.doWork { case s : Session => {
val user_id = "1"
val now = System.currentTimeMillis
- s.->("users",user_id,"base_attributes:name", "Chris Goffinet", now, false)
- s.->("users",user_id,"base_attributes:name", "24", now, false)
+ s.++|("users",user_id,"base_attributes:name", "Chris Goffinet", now, false)
+ s.++|("users",user_id,"base_attributes:name", "24", now, false)
for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
}
}
}
}
\ No newline at end of file
|
mccv/Cassidy
|
cdeed910f87a8f8a780ac844450f15c0d70b5643
|
Added early DSL
|
diff --git a/pom.xml b/pom.xml
index ef14aeb..8d5ab05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,153 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<description>
Cassidy is a Scala wrapper around Cassandra
</description>
<organization>
<name>Foldleft</name>
<url>http://foldleft.se</url>
</organization>
<licenses>
<license>
<name>the Apache License, ASL Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>viktorklang</id>
<name>Viktor Klang</name>
<timezone>+1</timezone>
<email>viktor.klang [at] gmail.com</email>
<roles>
<role>BDFL</role>
</roles>
</developer>
</developers>
<properties>
<scala.version>2.7.5</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
- <url>${basedir}/repo-embedded</url>
- <snapshots/>
- <releases/>
+ <url>file://${basedir}/repo-embedded</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.3.0</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
+ <dependency>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>javautils</artifactId>
+ <version>2.7.4-0.1</version>
+ </dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
<!--<args>
<arg></arg>
</args>-->
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
- <!-- arg>-unchecked</arg -->
+ <arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index d3f44e7..7db9c2a 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,64 +1,127 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
- val client : Cassandra.Client
+ import scala.collection.jcl.Conversions._
+ import org.scala_tools.javautils.Imports._
+
+ private implicit def null2Option[T](t : T) : Option[T] = if(t != null) Some(t) else None
+
+ protected val client : Cassandra.Client
+
+ def /(tableName : String, key : String, columnParent : String, start : Option[Int],end : Option[Int]) : List[column_t] = {
+ client.get_slice(tableName, key, columnParent, start.getOrElse(-1),end.getOrElse(-1)).toList
+ }
+
+ def /(tableName : String, key : String, columnParent : String, colNames : List[String]) : List[column_t] = {
+ client.get_slice_by_names(tableName, key, columnParent, colNames.asJava ).toList
+ }
+
+ def <-|(tableName : String, key : String, colPath : String) : Option[column_t] = {
+ client.get_column(tableName, key, colPath)
+ }
+
+ def |#(tableName : String, key : String, columnParent : String) : Int = {
+ client.get_column_count(tableName, key, columnParent)
+ }
+
+ def ->|(tableName : String, key : String, columnPath : String, cellData : Array[Byte], timestamp : Long, block : Boolean) = {
+ client.insert(tableName, key, columnPath, cellData,timestamp,block)
+ }
+
+ def ->|(batch : batch_mutation_t, block : Boolean) = {
+ client.batch_insert(batch, block)
+ }
+
+ def --(tableName : String, key : String, columnPathOrParent : String, timestamp : Long, block : Boolean) = {
+ client.remove(tableName, key, columnPathOrParent, timestamp, block)
+ }
+
+ def /@(tableName : String, key : String, columnParent : String, timestamp : Long) : List[column_t] = {
+ client.get_columns_since(tableName, key, columnParent, timestamp).toList
+ }
+
+ def /^(tableName : String, key : String, columnFamily : String, start : Option[Int], end : Option[Int], count : Int ) : List[superColumn_t] = {
+ client.get_slice_super(tableName, key,columnFamily, start.getOrElse(-1), end.getOrElse(-1)).toList //TODO upgrade thrift interface to support count
+ }
+
+ def /^(tableName : String, key : String, columnFamily : String, superColNames : List[String]) : List[superColumn_t] = {
+ client.get_slice_super_by_names(tableName, key, columnFamily, superColNames.asJava).toList
+ }
+
+ def |^(tableName : String, key : String, superColumnPath : String) : Option[superColumn_t] = {
+ client.get_superColumn(tableName,key,superColumnPath)
+ }
+
+ def ->|^ (batch : batch_mutation_super_t, block : boolean) = {
+ client.batch_insert_superColumn(batch, block)
+ }
+
+ def keys(tableName : String, startsWith : String, stopsAt : String, maxResults : Option[Int]) : List[String] = {
+ client.get_key_range(tableName, startsWith, stopsAt, maxResults.getOrElse(-1)).toList
+ }
+
+ def property(name : String) : String = client.getStringProperty(name)
+ def properties(name : String) : List[String] = client.getStringListProperty(name).toList
+ def describeTable(tableName : String) = client.describeTable(tableName)
+
+ def ?(query : String) = client.executeQuery(query)
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
new Session
{
val client = c
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
val r = work(s)
s.flush
r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
{
def apply(transport : TTransport) = factory.getProtocol(transport)
}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
-}
+}
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
index 6d51829..b7c6d84 100644
--- a/src/main/scala/se/foldleft/cassidy/Main.scala
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -1,18 +1,33 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import se.foldleft.pool._
object Main {
+
+
+
def main(a : Array[String]) : Unit = {
- val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
+ implicit def strToBytes(s : String) = s.getBytes("UTF-8")
+ import scala.collection.jcl.Conversions._
+ val c = new Cassidy(StackPool(SocketProvider("localhost",9160)),Protocol.Binary)
+ c.doWork { case s : Session => {
+ val user_id = "1"
+ val now = System.currentTimeMillis
+ s.->("users",user_id,"base_attributes:name", "Chris Goffinet", now, false)
+ s.->("users",user_id,"base_attributes:name", "24", now, false)
+
+ for( i <- s./("users", user_id, "base_attributes", None,None).toList) println(i)
+
+
+ }
+ }
- c.doWork { case s : Session => println(s) }
}
-}
+}
\ No newline at end of file
|
mccv/Cassidy
|
0336ea5efa73afaf126c910e41b4b9313265ccab
|
Fixed a bug in the pool
|
diff --git a/src/main/scala/se/foldleft/cassidy/TransportPool.scala b/src/main/scala/se/foldleft/cassidy/TransportPool.scala
index fa86a0c..5d85f99 100644
--- a/src/main/scala/se/foldleft/cassidy/TransportPool.scala
+++ b/src/main/scala/se/foldleft/cassidy/TransportPool.scala
@@ -1,25 +1,29 @@
/**
* TransportPool enables pooling of Thrift TTransports
*/
package se.foldleft.cassidy
import se.foldleft.pool._
import org.apache.thrift.transport._
trait TransportFactory[T <: TTransport] extends PoolItemFactory[T]
{
def createTransport : T
def makeObject : T = createTransport
def destroyObject(transport : T) : Unit = transport.close
def validateObject(transport : T) = transport.isOpen
def activateObject(transport : T) : Unit = if( !transport.isOpen ) transport.open else ()
def passivateObject(transport : T) : Unit = transport.flush
}
case class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
{
- def createTransport = new TSocket(host,port)
+ def createTransport = {
+ val t = new TSocket(host,port)
+ t.open
+ t
+ }
}
\ No newline at end of file
|
mccv/Cassidy
|
bb829997d564829803fd873f21c742d4aa5303be
|
Small mods
|
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index d664352..d3f44e7 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,56 +1,64 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
+
+ val c = new Cassandra.Client(inputProtocol(t),outputProtocol(t))
+
new Session
{
- val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
+ val client = c
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
- work(s)
- s.flush
+ val r = work(s)
+ s.flush
+
+ r
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
+{
+ def apply(transport : TTransport) = factory.getProtocol(transport)
+}
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
|
mccv/Cassidy
|
438b5839de54a9d368bc1a9f359ea11cfa2d90f2
|
Added log4j and fixed launcher goal
|
diff --git a/pom.xml b/pom.xml
index b7a6c60..ef14aeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,148 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<description>
Cassidy is a Scala wrapper around Cassandra
</description>
<organization>
<name>Foldleft</name>
<url>http://foldleft.se</url>
</organization>
<licenses>
<license>
<name>the Apache License, ASL Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>viktorklang</id>
<name>Viktor Klang</name>
<timezone>+1</timezone>
<email>viktor.klang [at] gmail.com</email>
<roles>
<role>BDFL</role>
</roles>
</developer>
</developers>
<properties>
<scala.version>2.7.5</scala.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>${basedir}/repo-embedded</url>
<snapshots/>
<releases/>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.3.0</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ </dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
- <args>
+ <!--<args>
<arg></arg>
- </args>
+ </args>-->
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
<!-- arg>-unchecked</arg -->
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
|
mccv/Cassidy
|
8903ce0fbee7eb39590c52f2e3ffcff8551e197c
|
Moved main method
|
diff --git a/pom.xml b/pom.xml
index 8412037..b7a6c60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,131 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
- <properties>
- <scala.version>2.7.5</scala.version>
- </properties>
+ <description>
+ Cassidy is a Scala wrapper around Cassandra
+ </description>
+ <organization>
+ <name>Foldleft</name>
+ <url>http://foldleft.se</url>
+ </organization>
+ <licenses>
+ <license>
+ <name>the Apache License, ASL Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
<developers>
<developer>
- <name>Viktor Klang</name>
<id>viktorklang</id>
- <email>viktorklang@gmail.com</email>
- <organization>foldleft.se</organization>
+ <name>Viktor Klang</name>
+ <timezone>+1</timezone>
+ <email>viktor.klang [at] gmail.com</email>
+ <roles>
+ <role>BDFL</role>
+ </roles>
</developer>
</developers>
+ <properties>
+ <scala.version>2.7.5</scala.version>
+ </properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
- <url>file://${basedir}/repo-embedded</url>
+ <url>${basedir}/repo-embedded</url>
<snapshots/>
<releases/>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.3.0</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
<artifactId>specs</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
<arg>-unchecked</arg>
</args>
<launchers>
<launcher>
<id>main-launcher</id>
<mainClass>se.foldleft.cassidy.Main</mainClass>
<args>
<arg></arg>
</args>
</launcher>
</launchers>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
<args>
<!-- arg>-unchecked</arg -->
<arg>-deprecation</arg>
<arg>-Xno-varargs-conversion</arg>
</args>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml
deleted file mode 100644
index f2c0337..0000000
--- a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache</groupId>
- <artifactId>cassandra</artifactId>
- <version>0.3.0</version>
- <packaging>jar</packaging>
-</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml
deleted file mode 100644
index 9883312..0000000
--- a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache</groupId>
- <artifactId>thrift</artifactId>
- <version>0.1</version>
- <packaging>jar</packaging>
-</project>
\ No newline at end of file
diff --git a/src/main/scala/se/foldleft/cassidy/Cassidy.scala b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
index 0053f20..d664352 100644
--- a/src/main/scala/se/foldleft/cassidy/Cassidy.scala
+++ b/src/main/scala/se/foldleft/cassidy/Cassidy.scala
@@ -1,64 +1,56 @@
/**
* Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
work(s)
s.flush
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
-
-object Main {
- def main(a : Array[String]) : Unit = {
- val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
-
- c.doWork { case s : Session => println(s) }
- }
-}
diff --git a/src/main/scala/se/foldleft/cassidy/Main.scala b/src/main/scala/se/foldleft/cassidy/Main.scala
new file mode 100644
index 0000000..6d51829
--- /dev/null
+++ b/src/main/scala/se/foldleft/cassidy/Main.scala
@@ -0,0 +1,18 @@
+/*
+ * Main.scala
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package se.foldleft.cassidy
+
+import se.foldleft.pool._
+
+object Main {
+ def main(a : Array[String]) : Unit = {
+ val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
+
+ c.doWork { case s : Session => println(s) }
+ }
+}
|
mccv/Cassidy
|
d2ba392ec7e66149c68d3dc38da00bddec84f0b4
|
Added Scala launcher
|
diff --git a/pom.xml b/pom.xml
index 399e31a..7de0d4b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,85 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
-xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
-
+ <properties>
+ <scala.version>2.7.5</scala.version>
+ </properties>
<developers>
<developer>
<name>Viktor Klang</name>
<id>viktorklang</id>
<email>viktorklang@gmail.com</email>
<organization>foldleft.se</organization>
</developer>
</developers>
-
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
- <snapshots />
- <releases />
+ <snapshots/>
+ <releases/>
</repository>
</repositories>
-
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.3.0</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
+ <dependency>
+ <groupId>org.scala-tools.testing</groupId>
+ <artifactId>specs</artifactId>
+ <version>1.5.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
-
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ <args>
+ <arg>-target:jvm-1.5</arg>
+ <arg>-unchecked</arg>
+ </args>
+ <launchers>
+ <launcher>
+ <id>main-launcher</id>
+ <mainClass>se.foldleft.cassandra.Main</mainClass>
+ <args>
+ <arg></arg>
+ </args>
+ </launcher>
+ </launchers>
+ </configuration>
<build>
- <directory>target</directory>
- <outputDirectory>target/classes</outputDirectory>
- <finalName>${artifactId}-${version}</finalName>
- <sourceDirectory>src/</sourceDirectory>
- <testSourceDirectory>test</testSourceDirectory>
- <resources>
- <resource>
- <directory>resources</directory>
- </resource>
- </resources>
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.scala-tools</groupId>
+ <artifactId>maven-scala-plugin</artifactId>
+ <version>2.10.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <jvmArgs>
+ <jvmArg>-Xmx1024m</jvmArg>
+ </jvmArgs>
+ <args>
+ <!-- arg>-unchecked</arg -->
+ <arg>-deprecation</arg>
+ <arg>-Xno-varargs-conversion</arg>
+ </args>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ </plugin>
+ </plugins>
</build>
</project>
\ No newline at end of file
|
mccv/Cassidy
|
2fb84d3bab789dc5e202b73404129e119a76f8d3
|
Restructuring due to Maven being a *****
|
diff --git a/pom.xml b/pom.xml
index df2f699..399e31a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,85 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<developers>
<developer>
<name>Viktor Klang</name>
<id>viktorklang</id>
<email>viktorklang@gmail.com</email>
<organization>foldleft.se</organization>
</developer>
</developers>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
<snapshots />
<releases />
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cassandra</artifactId>
<version>0.3.0</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>thrift</artifactId>
<version>0.1</version>
<optional>false</optional>
</dependency>
</dependencies>
<build>
- <!--<directory>src</directory>-->
+ <directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
- <sourceDirectory>src</sourceDirectory>
+ <sourceDirectory>src/</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/LICENSE.txt b/repo-embedded/org/apache/cassandra/0.3.0/LICENSE.txt
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/repo-embedded/org/apache/cassandra/0.3.0/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/NOTICE.txt b/repo-embedded/org/apache/cassandra/0.3.0/NOTICE.txt
new file mode 100644
index 0000000..5919825
--- /dev/null
+++ b/repo-embedded/org/apache/cassandra/0.3.0/NOTICE.txt
@@ -0,0 +1,63 @@
+This product includes software developed by The Apache Software
+Foundation (http://www.apache.org/).
+
+
+
+From Lucene's notice file:
+Apache Lucene
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+The snowball stemmers in
+ contrib/snowball/src/java/net/sf/snowball
+were developed by Martin Porter and Richard Boulton.
+The full snowball package is available from
+ http://snowball.tartarus.org/
+
+
+
+From Groovy's notice file:
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Groovy Language distribution. ==
+ =========================================================================
+
+ Groovy Language
+ Copyright 2003-2007 The respective authors and developers
+ Developers and Contributors are listed in the project POM file
+
+ This product includes software developed by
+ The Groovy community (http://groovy.codehaus.org/).
+
+
+
+From Thrift's notice file:
+Apache Thrift
+Copyright 2006-2009 The Apache Software Foundation, et al.
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+Some files in this distribution are distributed under different terms
+from the rest of Apache Thrift. Please see individual files for
+license information.
+
+In addition, the following unlabelled files are distributed under
+specific terms. Please see the "doc" directory for the text of their
+licenses.
+
+ lib/rb/setup.rb: GNU Lesser General Public License 2.1 (lgpl-2.1.txt)
+ lib/ocaml/OCamlMakefile: GNU Lesser General Public License 2.1 (lgpl-2.1.txt)
+ lib/ocaml/README-OCamlMakefile: GNU Lesser General Public License 2.1 (lgpl-2.1.txt)
+ lib/erl/build/beamver: MIT License (otp-base-license.txt)
+ lib/erl/build/buildtargets.mk: MIT License (otp-base-license.txt)
+ lib/erl/build/colors.mk: MIT License (otp-base-license.txt)
+ lib/erl/build/docs.mk: MIT License (otp-base-license.txt)
+ lib/erl/build/mime.types: MIT License (otp-base-license.txt)
+ lib/erl/build/otp.mk: MIT License (otp-base-license.txt)
+ lib/erl/build/otp_subdir.mk: MIT License (otp-base-license.txt)
+ lib/erl/build/raw_test.mk: MIT License (otp-base-license.txt)
+ lib/erl/src/Makefile: MIT License (otp-base-license.txt)
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/README.txt b/repo-embedded/org/apache/cassandra/0.3.0/README.txt
new file mode 100644
index 0000000..a2da28d
--- /dev/null
+++ b/repo-embedded/org/apache/cassandra/0.3.0/README.txt
@@ -0,0 +1,95 @@
+Cassandra is a highly scalable, eventually consistent, distributed, structured
+key-value store.
+
+
+Project description
+-------------------
+
+Cassandra brings together the distributed systems technologies from Dynamo
+and the data model from Google's BigTable. Like Dynamo, Cassandra is
+eventually consistent. Like BigTable, Cassandra provides a ColumnFamily-based
+data model richer than typical key/value systems.
+
+For more information see http://incubator.apache.org/cassandra
+
+
+Getting started
+---------------
+
+This short guide will walk you through getting a basic one node cluster up
+and running, and demonstrate some simple reads and writes.
+
+ * tar -zxvf cassandra-$VERSION.tgz
+ * cd cassandra-$VERSION
+ * sudo mkdir -p /var/cassandra/logs
+ * sudo chown `whoami` -R /var/cassandra
+
+Note: The sample configuration files in conf/ determine the file-system
+locations Cassandra uses for logging and data storage. You are free to
+change these to suit your own environment and adjust the path names
+used here accordingly.
+
+Now that we're ready, let's start it up!
+
+ * bin/cassandra -f
+
+Running the startup script with the -f argument will cause Cassandra to
+remain in the foreground and log to standard out.
+
+Now let's try to read and write some data using the command line client.
+
+ * bin/cassandra-cli --host localhost --port 9160
+
+The command line client is interactive so if everything worked you should
+be sitting in front of a prompt...
+
+ Connected to localhost/9160
+ Welcome to cassandra CLI.
+
+ Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
+ cassandra>
+
+As the banner says, you can use 'help' or '?' to see what the CLI has to
+offer, and 'quit' or 'exit' when you've had enough fun. But lets try
+something slightly more interesting...
+
+ cassandra> set Table1.Standard1['jsmith']['first'] = 'John'
+ Statement processed.
+ cassandra> set Table1.Standard1['jsmith']['last'] = 'Smith'
+ Statement processed.
+ cassandra> set Table1.Standard1['jsmith']['age'] = '42'
+ Statement processed.
+ cassandra> get Table1.Standard1['jsmith']
+ COLUMN_TIMESTAMP = 1241129773658; COLUMN_VALUE = 42; COLUMN_KEY = age;
+ COLUMN_TIMESTAMP = 1241129537336; COLUMN_VALUE = Smith; COLUMN_KEY = last;
+ COLUMN_TIMESTAMP = 1241129520503; COLUMN_VALUE = John; COLUMN_KEY = first;
+ Statement processed.
+ cassandra>
+
+If your session looks similar to what's above, congrats, your single node
+cluster is operational! But what exactly was all of that? Let's break it
+down into pieces and see.
+
+ set Table1.Standard1['jsmith']['first'] = 'John'
+ \ \ \ \ \
+ \ \ \_ key \ \_ value
+ \ \ \_ column
+ \_ table \_ column family
+
+Data stored in Cassandra is associated with a column family (Standard1),
+which in turn is associated with a table (Table1). In the example above,
+we set the value 'John' in the 'first' column for key 'jsmith'.
+
+For more information on the Cassandra data model be sure to checkout
+http://wiki.apache.org/cassandra/DataModel
+
+Wondering where to go from here?
+
+ * The wiki (http://wiki.apache.org/cassandra/) is the
+ best source for additional information.
+ * Join us in #cassandra on irc.freenode.net and ask questions.
+ * Subscribe to the Users mailing list by sending a mail to
+ cassandra-user-subscribe@incubator.apache.org
+
+
+
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar.LICENSE b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar.LICENSE
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar.LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/src/se/foldleft/cassidy/Cassidy.scala b/src/se/foldleft/cassidy/Cassidy.scala
index bc15953..0053f20 100644
--- a/src/se/foldleft/cassidy/Cassidy.scala
+++ b/src/se/foldleft/cassidy/Cassidy.scala
@@ -1,67 +1,64 @@
-/*
- * Main.scala
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
+/**
+ * Welcome to Cassidy, the Scala Cassandra client
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
work(s)
s.flush
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
object Main {
def main(a : Array[String]) : Unit = {
val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
c.doWork { case s : Session => println(s) }
}
}
diff --git a/src/se/foldleft/cassidy/TransportPool.scala b/src/se/foldleft/cassidy/TransportPool.scala
index e9fe48b..fa86a0c 100644
--- a/src/se/foldleft/cassidy/TransportPool.scala
+++ b/src/se/foldleft/cassidy/TransportPool.scala
@@ -1,21 +1,25 @@
+/**
+ * TransportPool enables pooling of Thrift TTransports
+ */
+
package se.foldleft.cassidy
import se.foldleft.pool._
import org.apache.thrift.transport._
trait TransportFactory[T <: TTransport] extends PoolItemFactory[T]
{
def createTransport : T
def makeObject : T = createTransport
def destroyObject(transport : T) : Unit = transport.close
def validateObject(transport : T) = transport.isOpen
def activateObject(transport : T) : Unit = if( !transport.isOpen ) transport.open else ()
def passivateObject(transport : T) : Unit = transport.flush
}
case class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
{
def createTransport = new TSocket(host,port)
}
\ No newline at end of file
diff --git a/src/se/foldleft/pool/Pool.scala b/src/se/foldleft/pool/Pool.scala
index fa49b8f..8c1c8bc 100644
--- a/src/se/foldleft/pool/Pool.scala
+++ b/src/se/foldleft/pool/Pool.scala
@@ -1,37 +1,34 @@
-/*
- * Pool.scala
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
+/**
+ * se.foldleft.pool contain an abstract interface that mimics the API of org.apache.commons.pool
+ * but adds typesafety
*/
-
package se.foldleft.pool
//ObjectPool
trait Pool[T] extends java.io.Closeable
{
def borrowObject : T
def returnObject(t : T) : Unit
def invalidateObject(t : T) : Unit
def addObject : Unit
def getNumIdle : Int
def getNumActive : Int
def clear : Unit
def setFactory(factory : PoolItemFactory[T]) : Unit
}
//ObjectPoolFactory
trait PoolFactory[T]
{
def createPool : Pool[T]
}
//PoolableObjectFactory
trait PoolItemFactory[T]
{
def makeObject : T
def destroyObject(t : T) : Unit
def validateObject(t : T) : Boolean
def activateObject(t : T) : Unit
def passivateObject(t : T) : Unit
}
\ No newline at end of file
diff --git a/src/se/foldleft/pool/PoolBridge.scala b/src/se/foldleft/pool/PoolBridge.scala
index 9137657..aed7b0f 100644
--- a/src/se/foldleft/pool/PoolBridge.scala
+++ b/src/se/foldleft/pool/PoolBridge.scala
@@ -1,58 +1,58 @@
+/**
+ * PoolBridge bridges the se.foldleft.pool to org.apache.commons.pool
+ */
+
package se.foldleft.pool
import org.apache.commons.pool._
import org.apache.commons.pool.impl._
-/**
- * PoolBridge is a wrapper/bridge from org.apache.commons.pool to se.foldleft.pool
- */
-
trait PoolBridge[T,OP <: ObjectPool] extends Pool[T]
{
val impl : OP
override def borrowObject : T = impl.borrowObject.asInstanceOf[T]
override def returnObject(t : T) = impl.returnObject(t)
override def invalidateObject(t : T) = impl.invalidateObject(t)
override def addObject = impl.addObject
override def getNumIdle : Int = impl.getNumIdle
override def getNumActive : Int = impl.getNumActive
override def clear : Unit = impl.clear
override def close : Unit = impl.close
override def setFactory(factory : PoolItemFactory[T]) = impl.setFactory(toPoolableObjectFactory(factory))
def toPoolableObjectFactory[T](pif : PoolItemFactory[T]) = new PoolableObjectFactory {
def makeObject : Object = pif.makeObject.asInstanceOf[Object]
def destroyObject(o : Object) : Unit = pif.destroyObject(o.asInstanceOf[T])
def validateObject(o : Object) : Boolean = pif.validateObject(o.asInstanceOf[T])
def activateObject(o : Object) : Unit = pif.activateObject(o.asInstanceOf[T])
def passivateObject(o : Object) : Unit = pif.passivateObject(o.asInstanceOf[T])
}
}
object StackPool
{
def apply[T](factory : PoolItemFactory[T]) = new PoolBridge[T,StackObjectPool] {
val impl = new StackObjectPool(toPoolableObjectFactory(factory))
}
def apply[T](factory : PoolItemFactory[T], maxIdle : Int) = new PoolBridge[T,StackObjectPool] {
val impl = new StackObjectPool(toPoolableObjectFactory(factory),maxIdle)
}
def apply[T](factory : PoolItemFactory[T], maxIdle : Int, initIdleCapacity : Int) = new PoolBridge[T,StackObjectPool] {
val impl = new StackObjectPool(toPoolableObjectFactory(factory),maxIdle,initIdleCapacity)
}
}
object SoftRefPool
{
def apply[T](factory : PoolItemFactory[T]) = new PoolBridge[T,SoftReferenceObjectPool] {
val impl = new SoftReferenceObjectPool(toPoolableObjectFactory(factory))
}
def apply[T](factory : PoolItemFactory[T], initSize : Int) = new PoolBridge[T,SoftReferenceObjectPool] {
val impl = new SoftReferenceObjectPool(toPoolableObjectFactory(factory),initSize)
}
}
|
mccv/Cassidy
|
2af3cdf6c44c3b706c49b1c757ab475f308e403f
|
Remastered with embedded repo
|
diff --git a/pom.xml b/pom.xml
index 8fc5cc7..df2f699 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,77 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<developers>
<developer>
<name>Viktor Klang</name>
<id>viktorklang</id>
<email>viktorklang@gmail.com</email>
<organization>foldleft.se</organization>
</developer>
</developers>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
+ <repository>
+ <id>embedded</id>
+ <name>Project Embbed Repository</name>
+ <url>file://${basedir}/repo-embedded</url>
+ <snapshots />
+ <releases />
+ </repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
- <groupId>Cassandra</groupId>
- <artifactId>org.apache.cassandra</artifactId>
- <version>0.3</version>
- <scope>system</scope>
- <systemPath>${basedir}/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar</systemPath>
+ <groupId>org.apache</groupId>
+ <artifactId>cassandra</artifactId>
+ <version>0.3.0</version>
+ <optional>false</optional>
</dependency>
<dependency>
- <groupId>thrift</groupId>
- <artifactId>org.apache.thrift</artifactId>
- <version>1.0</version>
- <scope>system</scope>
- <systemPath>${basedir}/lib/Cassandra/libthrift.jar</systemPath>
+ <groupId>org.apache</groupId>
+ <artifactId>thrift</artifactId>
+ <version>0.1</version>
+ <optional>false</optional>
</dependency>
</dependencies>
<build>
+ <!--<directory>src</directory>-->
+ <outputDirectory>target/classes</outputDirectory>
+ <finalName>${artifactId}-${version}</finalName>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar
new file mode 100644
index 0000000..e035153
Binary files /dev/null and b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.jar differ
diff --git a/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml
new file mode 100644
index 0000000..f2c0337
--- /dev/null
+++ b/repo-embedded/org/apache/cassandra/0.3.0/cassandra-0.3.0.pom.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache</groupId>
+ <artifactId>cassandra</artifactId>
+ <version>0.3.0</version>
+ <packaging>jar</packaging>
+</project>
\ No newline at end of file
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar
new file mode 100644
index 0000000..9782f26
Binary files /dev/null and b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.jar differ
diff --git a/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml
new file mode 100644
index 0000000..9883312
--- /dev/null
+++ b/repo-embedded/org/apache/thrift/0.1/thrift-0.1.pom.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache</groupId>
+ <artifactId>thrift</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+</project>
\ No newline at end of file
diff --git a/src/cassidy-0.1.jar b/src/cassidy-0.1.jar
new file mode 100644
index 0000000..c8f7aa4
Binary files /dev/null and b/src/cassidy-0.1.jar differ
diff --git a/src/maven-archiver/pom.properties b/src/maven-archiver/pom.properties
new file mode 100644
index 0000000..3b47165
--- /dev/null
+++ b/src/maven-archiver/pom.properties
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Fri Jul 10 14:31:29 CEST 2009
+version=0.1
+groupId=se.foldleft
+artifactId=cassidy
diff --git a/src/se/foldleft/cassidy/Cassidy.scala b/src/se/foldleft/cassidy/Cassidy.scala
index 4ec22de..bc15953 100644
--- a/src/se/foldleft/cassidy/Cassidy.scala
+++ b/src/se/foldleft/cassidy/Cassidy.scala
@@ -1,70 +1,67 @@
+/*
+ * Main.scala
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
-/**
- * Session represents - guess what - a Session!
- */
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
-/**
- * Cassidy is a wrapper around Cassandra that uses the Thrift java bindings with a TTransport pool
- * You can find TransportPool samples in PoolBridge.scala
- */
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
work(s)
s.flush
}
finally
{
s.close
}
}
def close = transportPool.close
}
-/**
- * Protocol is just a simple wrapper over TProtocolFactory
- */
-abstract class Protocol(val factory : TProtocolFactory)
+sealed abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
object Main {
def main(a : Array[String]) : Unit = {
val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
- c.doWork { x => println(x) }
+ c.doWork { case s : Session => println(s) }
}
}
diff --git a/src/se/foldleft/cassidy/TransportPool.scala b/src/se/foldleft/cassidy/TransportPool.scala
index 04f956a..e9fe48b 100644
--- a/src/se/foldleft/cassidy/TransportPool.scala
+++ b/src/se/foldleft/cassidy/TransportPool.scala
@@ -1,27 +1,21 @@
package se.foldleft.cassidy
import se.foldleft.pool._
import org.apache.thrift.transport._
-/**
- * TransportFactory is a specialization to allow for pooling of TTransports
- */
trait TransportFactory[T <: TTransport] extends PoolItemFactory[T]
{
def createTransport : T
def makeObject : T = createTransport
def destroyObject(transport : T) : Unit = transport.close
def validateObject(transport : T) = transport.isOpen
def activateObject(transport : T) : Unit = if( !transport.isOpen ) transport.open else ()
def passivateObject(transport : T) : Unit = transport.flush
}
-/**
- * SocketProvider is a specialization of TransportFactory for TSocket pooling
- */
case class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
{
def createTransport = new TSocket(host,port)
}
\ No newline at end of file
diff --git a/src/se/foldleft/pool/Pool.scala b/src/se/foldleft/pool/Pool.scala
index e68bf46..fa49b8f 100644
--- a/src/se/foldleft/pool/Pool.scala
+++ b/src/se/foldleft/pool/Pool.scala
@@ -1,35 +1,37 @@
-package se.foldleft.pool
-
-/**
- * Pool is a simple typesafe Scala object pool interface
- * Just view it as a typesafe wrapper over something like org.apache.commons.pool
+/*
+ * Pool.scala
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
*/
+package se.foldleft.pool
+
//ObjectPool
trait Pool[T] extends java.io.Closeable
{
def borrowObject : T
def returnObject(t : T) : Unit
def invalidateObject(t : T) : Unit
def addObject : Unit
def getNumIdle : Int
def getNumActive : Int
def clear : Unit
def setFactory(factory : PoolItemFactory[T]) : Unit
}
//ObjectPoolFactory
trait PoolFactory[T]
{
def createPool : Pool[T]
}
//PoolableObjectFactory
trait PoolItemFactory[T]
{
def makeObject : T
def destroyObject(t : T) : Unit
def validateObject(t : T) : Boolean
def activateObject(t : T) : Unit
def passivateObject(t : T) : Unit
}
\ No newline at end of file
|
mccv/Cassidy
|
437b111edeb8c35c89db5663b567ef8f33233099
|
Added documentation
|
diff --git a/src/se/foldleft/cassidy/Cassidy.scala b/src/se/foldleft/cassidy/Cassidy.scala
index bc15953..4ec22de 100644
--- a/src/se/foldleft/cassidy/Cassidy.scala
+++ b/src/se/foldleft/cassidy/Cassidy.scala
@@ -1,67 +1,70 @@
-/*
- * Main.scala
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
+/**
+ * Session represents - guess what - a Session!
+ */
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
+/**
+ * Cassidy is a wrapper around Cassandra that uses the Thrift java bindings with a TTransport pool
+ * You can find TransportPool samples in PoolBridge.scala
+ */
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
work(s)
s.flush
}
finally
{
s.close
}
}
def close = transportPool.close
}
-sealed abstract class Protocol(val factory : TProtocolFactory)
+/**
+ * Protocol is just a simple wrapper over TProtocolFactory
+ */
+abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
object Main {
def main(a : Array[String]) : Unit = {
val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
- c.doWork { case s : Session => println(s) }
+ c.doWork { x => println(x) }
}
}
diff --git a/src/se/foldleft/cassidy/TransportPool.scala b/src/se/foldleft/cassidy/TransportPool.scala
index e9fe48b..04f956a 100644
--- a/src/se/foldleft/cassidy/TransportPool.scala
+++ b/src/se/foldleft/cassidy/TransportPool.scala
@@ -1,21 +1,27 @@
package se.foldleft.cassidy
import se.foldleft.pool._
import org.apache.thrift.transport._
+/**
+ * TransportFactory is a specialization to allow for pooling of TTransports
+ */
trait TransportFactory[T <: TTransport] extends PoolItemFactory[T]
{
def createTransport : T
def makeObject : T = createTransport
def destroyObject(transport : T) : Unit = transport.close
def validateObject(transport : T) = transport.isOpen
def activateObject(transport : T) : Unit = if( !transport.isOpen ) transport.open else ()
def passivateObject(transport : T) : Unit = transport.flush
}
+/**
+ * SocketProvider is a specialization of TransportFactory for TSocket pooling
+ */
case class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
{
def createTransport = new TSocket(host,port)
}
\ No newline at end of file
diff --git a/src/se/foldleft/pool/Pool.scala b/src/se/foldleft/pool/Pool.scala
index fa49b8f..e68bf46 100644
--- a/src/se/foldleft/pool/Pool.scala
+++ b/src/se/foldleft/pool/Pool.scala
@@ -1,37 +1,35 @@
-/*
- * Pool.scala
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
package se.foldleft.pool
+/**
+ * Pool is a simple typesafe Scala object pool interface
+ * Just view it as a typesafe wrapper over something like org.apache.commons.pool
+ */
+
//ObjectPool
trait Pool[T] extends java.io.Closeable
{
def borrowObject : T
def returnObject(t : T) : Unit
def invalidateObject(t : T) : Unit
def addObject : Unit
def getNumIdle : Int
def getNumActive : Int
def clear : Unit
def setFactory(factory : PoolItemFactory[T]) : Unit
}
//ObjectPoolFactory
trait PoolFactory[T]
{
def createPool : Pool[T]
}
//PoolableObjectFactory
trait PoolItemFactory[T]
{
def makeObject : T
def destroyObject(t : T) : Unit
def validateObject(t : T) : Boolean
def activateObject(t : T) : Unit
def passivateObject(t : T) : Unit
}
\ No newline at end of file
diff --git a/src/se/foldleft/pool/PoolBridge.scala b/src/se/foldleft/pool/PoolBridge.scala
new file mode 100644
index 0000000..9137657
--- /dev/null
+++ b/src/se/foldleft/pool/PoolBridge.scala
@@ -0,0 +1,58 @@
+package se.foldleft.pool
+
+import org.apache.commons.pool._
+import org.apache.commons.pool.impl._
+
+/**
+ * PoolBridge is a wrapper/bridge from org.apache.commons.pool to se.foldleft.pool
+ */
+
+trait PoolBridge[T,OP <: ObjectPool] extends Pool[T]
+{
+ val impl : OP
+ override def borrowObject : T = impl.borrowObject.asInstanceOf[T]
+ override def returnObject(t : T) = impl.returnObject(t)
+ override def invalidateObject(t : T) = impl.invalidateObject(t)
+ override def addObject = impl.addObject
+ override def getNumIdle : Int = impl.getNumIdle
+ override def getNumActive : Int = impl.getNumActive
+ override def clear : Unit = impl.clear
+ override def close : Unit = impl.close
+ override def setFactory(factory : PoolItemFactory[T]) = impl.setFactory(toPoolableObjectFactory(factory))
+
+ def toPoolableObjectFactory[T](pif : PoolItemFactory[T]) = new PoolableObjectFactory {
+ def makeObject : Object = pif.makeObject.asInstanceOf[Object]
+ def destroyObject(o : Object) : Unit = pif.destroyObject(o.asInstanceOf[T])
+ def validateObject(o : Object) : Boolean = pif.validateObject(o.asInstanceOf[T])
+ def activateObject(o : Object) : Unit = pif.activateObject(o.asInstanceOf[T])
+ def passivateObject(o : Object) : Unit = pif.passivateObject(o.asInstanceOf[T])
+ }
+
+}
+
+object StackPool
+{
+ def apply[T](factory : PoolItemFactory[T]) = new PoolBridge[T,StackObjectPool] {
+ val impl = new StackObjectPool(toPoolableObjectFactory(factory))
+ }
+
+ def apply[T](factory : PoolItemFactory[T], maxIdle : Int) = new PoolBridge[T,StackObjectPool] {
+ val impl = new StackObjectPool(toPoolableObjectFactory(factory),maxIdle)
+ }
+
+ def apply[T](factory : PoolItemFactory[T], maxIdle : Int, initIdleCapacity : Int) = new PoolBridge[T,StackObjectPool] {
+ val impl = new StackObjectPool(toPoolableObjectFactory(factory),maxIdle,initIdleCapacity)
+ }
+}
+
+object SoftRefPool
+{
+ def apply[T](factory : PoolItemFactory[T]) = new PoolBridge[T,SoftReferenceObjectPool] {
+ val impl = new SoftReferenceObjectPool(toPoolableObjectFactory(factory))
+ }
+
+ def apply[T](factory : PoolItemFactory[T], initSize : Int) = new PoolBridge[T,SoftReferenceObjectPool] {
+ val impl = new SoftReferenceObjectPool(toPoolableObjectFactory(factory),initSize)
+ }
+
+}
|
mccv/Cassidy
|
1fcf3d62c5fd2c8510b4a15a5d48d512818ece6f
|
added resource directory
|
diff --git a/pom.xml b/pom.xml
index a04abe2..8fc5cc7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,77 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<developers>
<developer>
<name>Viktor Klang</name>
<id>viktorklang</id>
<email>viktorklang@gmail.com</email>
<organization>foldleft.se</organization>
</developer>
</developers>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>Cassandra</groupId>
<artifactId>org.apache.cassandra</artifactId>
<version>0.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar</systemPath>
</dependency>
<dependency>
<groupId>thrift</groupId>
<artifactId>org.apache.thrift</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Cassandra/libthrift.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
- <directory>src/main/resources</directory>
+ <directory>resources</directory>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
|
mccv/Cassidy
|
b363bf07e4d21a4704e6a2997375a42967a78ac9
|
Added source/test directories to pom
|
diff --git a/pom.xml b/pom.xml
index 1e0806f..a04abe2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,67 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>se.foldleft</groupId>
<artifactId>cassidy</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Cassidy 0.1</name>
<url>git@github.com/viktorklang/Cassidy.git</url>
<inceptionYear>2009</inceptionYear>
<developers>
<developer>
<name>Viktor Klang</name>
<id>viktorklang</id>
<email>viktorklang@gmail.com</email>
<organization>foldleft.se</organization>
</developer>
</developers>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.5.1</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.7.5</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>Cassandra</groupId>
<artifactId>org.apache.cassandra</artifactId>
<version>0.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar</systemPath>
</dependency>
<dependency>
<groupId>thrift</groupId>
<artifactId>org.apache.thrift</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Cassandra/libthrift.jar</systemPath>
</dependency>
</dependencies>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>test</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
</project>
\ No newline at end of file
|
mccv/Cassidy
|
ae6e860e003261e27c8941a37f5aaed10276df80
|
Mavenized the project
|
diff --git a/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar b/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar
new file mode 100644
index 0000000..e035153
Binary files /dev/null and b/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar differ
diff --git a/lib/Cassandra/libthrift.jar b/lib/Cassandra/libthrift.jar
new file mode 100644
index 0000000..9782f26
Binary files /dev/null and b/lib/Cassandra/libthrift.jar differ
diff --git a/lib/Cassandra/licenses/libthrift.jar.LICENSE b/lib/Cassandra/licenses/libthrift.jar.LICENSE
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/lib/Cassandra/licenses/libthrift.jar.LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..1e0806f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" xmlns="http://maven.apache.org/POM/4.0"
+xsi:schemaLocation="http://maven.apache.org/POM/4.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>se.foldleft</groupId>
+ <artifactId>cassidy</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <name>Cassidy 0.1</name>
+ <url>git@github.com/viktorklang/Cassidy.git</url>
+ <inceptionYear>2009</inceptionYear>
+
+ <developers>
+ <developer>
+ <name>Viktor Klang</name>
+ <id>viktorklang</id>
+ <email>viktorklang@gmail.com</email>
+ <organization>foldleft.se</organization>
+ </developer>
+ </developers>
+
+ <repositories>
+ <repository>
+ <id>scala-tools.org</id>
+ <name>Scala-Tools Maven2 Repository</name>
+ <url>http://scala-tools.org/repo-releases</url>
+ </repository>
+ <repository>
+ <id>central</id>
+ <name>Maven Repository Switchboard</name>
+ <layout>default</layout>
+ <url>http://repo1.maven.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <version>1.5.1</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.7.5</version>
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>Cassandra</groupId>
+ <artifactId>org.apache.cassandra</artifactId>
+ <version>0.3</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/Cassandra/apache-cassandra-incubating-0.3.0-dev.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>thrift</groupId>
+ <artifactId>org.apache.thrift</artifactId>
+ <version>1.0</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/Cassandra/libthrift.jar</systemPath>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
|
mccv/Cassidy
|
8595cbad4d16a1a90443b26f9e035bc9c5f5909a
|
Changed test code
|
diff --git a/src/se/foldleft/cassidy/Cassidy.scala b/src/se/foldleft/cassidy/Cassidy.scala
index 73586c2..bc15953 100644
--- a/src/se/foldleft/cassidy/Cassidy.scala
+++ b/src/se/foldleft/cassidy/Cassidy.scala
@@ -1,68 +1,67 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
def doWork[R](work : (Session) => R) = {
val s = newSession
try
{
work(s)
+ s.flush
}
finally
{
s.close
}
}
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
object Main {
def main(a : Array[String]) : Unit = {
val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
- c.doWork { _.client }
-
- ()
+ c.doWork { case s : Session => println(s) }
}
}
|
mccv/Cassidy
|
a726bd28187c5de35180bd28ad188b9c7dbe8d54
|
refactored Casidy
|
diff --git a/src/se/foldleft/cassidy/Cassidy.scala b/src/se/foldleft/cassidy/Cassidy.scala
index 12a53a3..73586c2 100644
--- a/src/se/foldleft/cassidy/Cassidy.scala
+++ b/src/se/foldleft/cassidy/Cassidy.scala
@@ -1,84 +1,68 @@
/*
* Main.scala
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package se.foldleft.cassidy
import org.apache.cassandra.service._
import org.apache.thrift._
import org.apache.thrift.transport._
import org.apache.thrift.protocol._
import java.io.{Flushable,Closeable}
import se.foldleft.pool._
-object With{
-
- def apply[T <: Flushable with Closeable,S](t : T)(work : (T) => S) : Option[S] = {
- try
- {
- val r = work(t)
- if(r != null)
- Some(r)
- else
- None
- }
- finally
- {
- try
- {
- t.flush
- }
- finally
- {
- t.close
- }
- }
- }
-}
-
trait Session extends Closeable with Flushable
{
val client : Cassandra.Client
}
class Cassidy[T <: TTransport](transportPool : Pool[T], inputProtocol : Protocol, outputProtocol : Protocol) extends Closeable
{
def this(transportPool : Pool[T], ioProtocol : Protocol) = this(transportPool,ioProtocol,ioProtocol)
def newSession : Session = {
val t = transportPool.borrowObject
new Session
{
val client = new Cassandra.Client(inputProtocol.factory.getProtocol(t),outputProtocol.factory.getProtocol(t))
def flush = t.flush
def close = transportPool.returnObject(t)
}
}
+ def doWork[R](work : (Session) => R) = {
+ val s = newSession
+ try
+ {
+ work(s)
+ }
+ finally
+ {
+ s.close
+ }
+ }
+
def close = transportPool.close
}
sealed abstract class Protocol(val factory : TProtocolFactory)
object Protocol
{
object Binary extends Protocol(new TBinaryProtocol.Factory)
object SimpleJSON extends Protocol(new TSimpleJSONProtocol.Factory)
object JSON extends Protocol(new TJSONProtocol.Factory)
}
object Main {
def main(a : Array[String]) : Unit = {
val c = new Cassidy(StackPool(SocketProvider("localhost",9610)),Protocol.Binary)
- With(c.newSession) {
- _.client
- }
-
+ c.doWork { _.client }
()
}
}
diff --git a/src/se/foldleft/cassidy/TransportPool.scala b/src/se/foldleft/cassidy/TransportPool.scala
index 4e8baf2..e9fe48b 100644
--- a/src/se/foldleft/cassidy/TransportPool.scala
+++ b/src/se/foldleft/cassidy/TransportPool.scala
@@ -1,21 +1,21 @@
package se.foldleft.cassidy
import se.foldleft.pool._
import org.apache.thrift.transport._
trait TransportFactory[T <: TTransport] extends PoolItemFactory[T]
{
def createTransport : T
def makeObject : T = createTransport
def destroyObject(transport : T) : Unit = transport.close
def validateObject(transport : T) = transport.isOpen
def activateObject(transport : T) : Unit = if( !transport.isOpen ) transport.open else ()
def passivateObject(transport : T) : Unit = transport.flush
}
-class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
+case class SocketProvider(val host : String,val port : Int) extends TransportFactory[TSocket]
{
def createTransport = new TSocket(host,port)
}
\ No newline at end of file
|
IvanPulleyn/dotfiles
|
cc76e1433f4162934167fb8be40855cd09a4267c
|
add gpp function
|
diff --git a/dot.bashrc b/dot.bashrc
index 1f41869..cd66342 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,127 +1,132 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
+function gpp
+{
+ git pull && git push
+}
+
function fanmax
{
sudo rmmod thinkpad_acpi
sudo modprobe thinkpad_acpi fan_control=1
sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
}
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function ctime
{
if [ -z "$1" ]; then
echo "Usage: ctime timestamp";
return 1
fi
perl -e"use POSIX; print ctime($1);"
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
|
IvanPulleyn/dotfiles
|
a0437d08663308111b9ba0fd9f4848190483b788
|
adjust C indenting
|
diff --git a/dot.emacs b/dot.emacs
index ac7ad08..79e5c60 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,107 +1,108 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
+ (statement-cont . +) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(statement-case-open . +) ;; Do indent for case open
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
(global-set-key "g" 'goto-line)
|
IvanPulleyn/dotfiles
|
d5aee413b208f90f5d546e7bdf9fc4c57d8d3398
|
remove buzz
|
diff --git a/dot.bashrc b/dot.bashrc
index 1f41869..ad5f518 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,127 +1,116 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function fanmax
{
sudo rmmod thinkpad_acpi
sudo modprobe thinkpad_acpi fan_control=1
sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
}
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
-# buzz
-function bzlogin
-{
- java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
-}
-
-function bzcons
-{
- java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
-}
-
function ctime
{
if [ -z "$1" ]; then
echo "Usage: ctime timestamp";
return 1
fi
perl -e"use POSIX; print ctime($1);"
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
|
IvanPulleyn/dotfiles
|
fda6a193c6cfba303abc60926a49bc3ee37822f7
|
adjust case brace indent
|
diff --git a/dot.emacs b/dot.emacs
index f19bf1e..ac7ad08 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,106 +1,107 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
+ (statement-case-open . +) ;; Do indent for case open
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
(global-set-key "g" 'goto-line)
|
IvanPulleyn/dotfiles
|
ab3170f5e5c0f7f6f457e508dab99fd7566f6549
|
remove protobuf and mmm for php
|
diff --git a/dot.emacs b/dot.emacs
index 2ec2374..f19bf1e 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,120 +1,106 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
-(require 'protobuf-mode)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
-
-;; php mmm
-(require 'mmm-mode)
-(setq mmm-global-mode 'maybe)
-(mmm-add-mode-ext-class nil "\\.php?\\'" 'html-php)
-(mmm-add-classes
- '((html-php
- :submode php-mode
- :front "<\\?\\(php\\)?"
- :back "\\?>")))
-(autoload 'php-mode "php-mode" "PHP editing mode" t)
-(add-to-list 'auto-mode-alist '("\\.php?\\'" . html-mode))
-
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
(global-set-key "g" 'goto-line)
|
IvanPulleyn/dotfiles
|
cc0c825f9ab9987f937121b00cfa80ef7d99e478
|
add mmm for php
|
diff --git a/dot.emacs b/dot.emacs
index 44da44e..2ec2374 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,107 +1,120 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(require 'protobuf-mode)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
+
+;; php mmm
+(require 'mmm-mode)
+(setq mmm-global-mode 'maybe)
+(mmm-add-mode-ext-class nil "\\.php?\\'" 'html-php)
+(mmm-add-classes
+ '((html-php
+ :submode php-mode
+ :front "<\\?\\(php\\)?"
+ :back "\\?>")))
+(autoload 'php-mode "php-mode" "PHP editing mode" t)
+(add-to-list 'auto-mode-alist '("\\.php?\\'" . html-mode))
+
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
(global-set-key "g" 'goto-line)
|
IvanPulleyn/dotfiles
|
ef11348b776bafe36bbf4533bc6c6541bedb0b6c
|
remove stupid rvm
|
diff --git a/dot.bashrc b/dot.bashrc
index 68c4ea7..1f41869 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,128 +1,127 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function fanmax
{
sudo rmmod thinkpad_acpi
sudo modprobe thinkpad_acpi fan_control=1
sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
}
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function ctime
{
if [ -z "$1" ]; then
echo "Usage: ctime timestamp";
return 1
fi
perl -e"use POSIX; print ctime($1);"
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
-[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
|
IvanPulleyn/dotfiles
|
541f64339b073c77271ae96a6a791f8d52d95c5a
|
add goto-line mapping
|
diff --git a/dot.emacs b/dot.emacs
index 3f45d75..44da44e 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,106 +1,107 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(require 'protobuf-mode)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
+(global-set-key "g" 'goto-line)
|
IvanPulleyn/dotfiles
|
38c0bcc5b5dd0977462f380b6e92284bf984e936
|
add protobuf-mode
|
diff --git a/dot.emacs b/dot.emacs
index 593fcd1..3f45d75 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,104 +1,106 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
+(require 'protobuf-mode)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
+ ("\\.erb$" . html-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
- ("\\.erb$" . html-mode)
+ ("\\.proto$" . protobuf-mode)
("\\.rhtml$" . html-mode)
- ("\\.xml$" . nxml-mode)
- ("\\.xsl$" . nxml-mode)
+ ("\\.xml$" . nxml-mode)
+ ("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; turn on code folding
(defun enable-folding ()
(hs-minor-mode t)
(local-set-key (kbd "C-c =") 'hs-show-block)
(local-set-key (kbd "C-c +") 'hs-show-all)
(local-set-key (kbd "C-c -") 'hs-hide-block)
(local-set-key (kbd "C-c _") 'hs-hide-all))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
(enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
diff --git a/protobuf-mode.el b/protobuf-mode.el
new file mode 100644
index 0000000..9ac0c72
--- /dev/null
+++ b/protobuf-mode.el
@@ -0,0 +1,219 @@
+;;; protobuf-mode.el --- major mode for editing protocol buffers.
+
+;; Author: Alexandre Vassalotti <alexandre@peadrop.com>
+;; Created: 23-Apr-2009
+;; Version: 0.3
+;; Keywords: google protobuf languages
+
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are
+;; met:
+;;
+;; * Redistributions of source code must retain the above copyright
+;; notice, this list of conditions and the following disclaimer.
+;; * Redistributions in binary form must reproduce the above
+;; copyright notice, this list of conditions and the following disclaimer
+;; in the documentation and/or other materials provided with the
+;; distribution.
+;; * Neither the name of Google Inc. nor the names of its
+;; contributors may be used to endorse or promote products derived from
+;; this software without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;; Commentary:
+
+;; Installation:
+;; - Put `protobuf-mode.el' in your Emacs load-path.
+;; - Add this line to your .emacs file:
+;; (require 'protobuf-mode)
+;;
+;; You can customize this mode just like any mode derived from CC Mode. If
+;; you want to add customizations specific to protobuf-mode, you can use the
+;; `protobuf-mode-hook'. For example, the following would make protocol-mode
+;; use 2-space indentation:
+;;
+;; (defconst my-protobuf-style
+;; '((c-basic-offset . 2)
+;; (indent-tabs-mode . nil)))
+;;
+;; (add-hook 'protobuf-mode-hook
+;; (lambda () (c-add-style "my-style" my-protobuf-style t)))
+;;
+;; Refer to the documentation of CC Mode for more information about
+;; customization details and how to use this mode.
+;;
+;; TODO:
+;; - Make highlighting for enum values work properly.
+;; - Fix the parser to recognize extensions as identifiers and not
+;; as casts.
+;; - Improve the parsing of option assignment lists. For example:
+;; optional int32 foo = 1 [(my_field_option) = 4.5];
+;; - Add support for fully-qualified identifiers (e.g., with a leading ".").
+
+;;; Code:
+
+(require 'cc-mode)
+
+(eval-when-compile
+ (require 'cc-langs)
+ (require 'cc-fonts))
+
+;; This mode does not inherit properties from other modes. So, we do not use
+;; the usual `c-add-language' function.
+(put 'protobuf-mode 'c-mode-prefix "protobuf-")
+
+;; The following code uses of the `c-lang-defconst' macro define syntactic
+;; features of protocol buffer language. Refer to the documentation in the
+;; cc-langs.el file for information about the meaning of the -kwds variables.
+
+(c-lang-defconst c-primitive-type-kwds
+ protobuf '("double" "float" "int32" "int64" "uint32" "uint64" "sint32"
+ "sint64" "fixed32" "fixed64" "sfixed32" "sfixed64" "bool"
+ "string" "bytes" "group"))
+
+(c-lang-defconst c-modifier-kwds
+ protobuf '("required" "optional" "repeated"))
+
+(c-lang-defconst c-class-decl-kwds
+ protobuf '("message" "enum" "service"))
+
+(c-lang-defconst c-constant-kwds
+ protobuf '("true" "false"))
+
+(c-lang-defconst c-other-decl-kwds
+ protobuf '("package" "import"))
+
+(c-lang-defconst c-other-kwds
+ protobuf '("default" "max"))
+
+(c-lang-defconst c-identifier-ops
+ ;; Handle extended identifiers like google.protobuf.MessageOptions
+ protobuf '((left-assoc ".")))
+
+;; The following keywords do not fit well in keyword classes defined by
+;; cc-mode. So, we approximate as best we can.
+
+(c-lang-defconst c-type-list-kwds
+ protobuf '("extensions" "to"))
+
+(c-lang-defconst c-typeless-decl-kwds
+ protobuf '("extend" "rpc" "option" "returns"))
+
+
+;; Here we remove default syntax for loops, if-statements and other C
+;; syntactic features that are not supported by the protocol buffer language.
+
+(c-lang-defconst c-brace-list-decl-kwds
+ ;; Remove syntax for C-style enumerations.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-1-kwds
+ ;; Remove syntax for "do" and "else" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-2-kwds
+ ;; Remove syntax for "for", "if", "switch" and "while" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-simple-stmt-kwds
+ ;; Remove syntax for "break", "continue", "goto" and "return" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-paren-stmt-kwds
+ ;; Remove special case for the "(;;)" in for-loops.
+ protobuf nil)
+
+(c-lang-defconst c-label-kwds
+ ;; Remove case label syntax for the "case" and "default" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-before-label-kwds
+ ;; Remove special case for the label in a goto statement.
+ protobuf nil)
+
+(c-lang-defconst c-cpp-matchers
+ ;; Disable all the C preprocessor syntax.
+ protobuf nil)
+
+(c-lang-defconst c-decl-prefix-re
+ ;; Same as for C, except it does not match "(". This is needed for disabling
+ ;; the syntax for casts.
+ protobuf "\\([\{\};,]+\\)")
+
+
+;; Add support for variable levels of syntax highlighting.
+
+(defconst protobuf-font-lock-keywords-1 (c-lang-const c-matchers-1 protobuf)
+ "Minimal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-2 (c-lang-const c-matchers-2 protobuf)
+ "Fast normal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-3 (c-lang-const c-matchers-3 protobuf)
+ "Accurate normal highlighting for protobuf-mode.")
+
+(defvar protobuf-font-lock-keywords protobuf-font-lock-keywords-3
+ "Default expressions to highlight in protobuf-mode.")
+
+;; Our syntax table is auto-generated from the keyword classes we defined
+;; previously with the `c-lang-const' macro.
+(defvar protobuf-mode-syntax-table nil
+ "Syntax table used in protobuf-mode buffers.")
+(or protobuf-mode-syntax-table
+ (setq protobuf-mode-syntax-table
+ (funcall (c-lang-const c-make-mode-syntax-table protobuf))))
+
+(defvar protobuf-mode-abbrev-table nil
+ "Abbreviation table used in protobuf-mode buffers.")
+
+(defvar protobuf-mode-map nil
+ "Keymap used in protobuf-mode buffers.")
+(or protobuf-mode-map
+ (setq protobuf-mode-map (c-make-inherited-keymap)))
+
+(easy-menu-define protobuf-menu protobuf-mode-map
+ "Protocol Buffers Mode Commands"
+ (cons "Protocol Buffers" (c-lang-const c-mode-menu protobuf)))
+
+;;;###autoload (add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
+
+;;;###autoload
+(defun protobuf-mode ()
+ "Major mode for editing Protocol Buffers description language.
+
+The hook `c-mode-common-hook' is run with no argument at mode
+initialization, then `protobuf-mode-hook'.
+
+Key bindings:
+\\{protobuf-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+ (set-syntax-table protobuf-mode-syntax-table)
+ (setq major-mode 'protobuf-mode
+ mode-name "Protocol-Buffers"
+ local-abbrev-table protobuf-mode-abbrev-table
+ abbrev-mode t)
+ (use-local-map protobuf-mode-map)
+ (c-initialize-cc-mode t)
+ (if (fboundp 'c-make-emacs-variables-local)
+ (c-make-emacs-variables-local))
+ (c-init-language-vars protobuf-mode)
+ (c-common-init 'protobuf-mode)
+ (easy-menu-add protobuf-menu)
+ (c-run-mode-hooks 'c-mode-common-hook 'protobuf-mode-hook)
+ (c-update-modeline))
+
+(provide 'protobuf-mode)
+
+;;; protobuf-mode.el ends here
|
IvanPulleyn/dotfiles
|
92f2d48d7e579c33f79a922534c886dae5ce3be0
|
add hs-minor-mode
|
diff --git a/dot.emacs b/dot.emacs
index 6971992..593fcd1 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,94 +1,104 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
+;; turn on code folding
+(defun enable-folding ()
+ (hs-minor-mode t)
+ (local-set-key (kbd "C-c =") 'hs-show-block)
+ (local-set-key (kbd "C-c +") 'hs-show-all)
+ (local-set-key (kbd "C-c -") 'hs-hide-block)
+ (local-set-key (kbd "C-c _") 'hs-hide-all))
+
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil)
+ (enable-folding)
;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
(setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
(defun-block-intro . +) ;; Do indent for functions
(statement-block-intro . +) ;; Do indent for statementblocks
(statement . 0) ;; Don't indent on individual statements
(substatement-open . 0) ;; Do indent for conditional blocks
(substatement . +) ;; Do indent for 1-line if blocks
(else-clause . 0) ;; Don't indent for the else clause
(block-close . 0) ;; Don't indent for the block closing }
(cpp-macro . [0]) ;; Don't indent inside #ifdefs
(cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
(inclass . +) ;; Do indent inside class declarations
(case-label . 0) ;; Do indent for case labels
(access-label . -) ;; Don't indent public/private
(statement-case-intro . +) ;; Do indent for case blocks
(comment-intro . 0) ;; Don't indent for comments
(c . 1) ;; Don't indent for comment continuations
(brace-list-intro . +) ;; Do indent the first line in enums
(brace-list-entry . 0) ;; Do not indent additional lines inside enums
(brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
(brace-list-close . 0) ;; Go back after brace list closes
(topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
(arglist-intro . +) ;; Do indent initial argument
(arglist-cont-nonempty . +) ;; Do indent additional argument lines
(arglist-close . 0) ;; Do not indent closing paren
)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
+
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
25a98f5d809330946ff079d3899dceac00bc8aab
|
add ctime utility function
|
diff --git a/dot.bashrc b/dot.bashrc
index c186e50..68c4ea7 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,119 +1,128 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function fanmax
{
sudo rmmod thinkpad_acpi
sudo modprobe thinkpad_acpi fan_control=1
sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
}
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
+function ctime
+{
+ if [ -z "$1" ]; then
+ echo "Usage: ctime timestamp";
+ return 1
+ fi
+ perl -e"use POSIX; print ctime($1);"
+}
+
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
|
IvanPulleyn/dotfiles
|
f96e8bc7cd002639affb88563c85b96f15c4ea27
|
detailed emacs c-mode indent
|
diff --git a/dot.emacs b/dot.emacs
index d2d4b0f..6971992 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,68 +1,94 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
- (setq indent-tabs-mode nil))
+ (setq indent-tabs-mode nil)
+ ;; originally copied from http://www.patd.net/~ciggieposeur/other/startup.el
+ (setq c-offsets-alist '((innamespace . 0) ;; Don't indent for namespace
+ (defun-block-intro . +) ;; Do indent for functions
+ (statement-block-intro . +) ;; Do indent for statementblocks
+ (statement . 0) ;; Don't indent on individual statements
+ (substatement-open . 0) ;; Do indent for conditional blocks
+ (substatement . +) ;; Do indent for 1-line if blocks
+ (else-clause . 0) ;; Don't indent for the else clause
+ (block-close . 0) ;; Don't indent for the block closing }
+ (cpp-macro . [0]) ;; Don't indent inside #ifdefs
+ (cpp-macro-cont . 0) ;; Don't indent inside #ifdefs
+ (inclass . +) ;; Do indent inside class declarations
+ (case-label . 0) ;; Do indent for case labels
+ (access-label . -) ;; Don't indent public/private
+ (statement-case-intro . +) ;; Do indent for case blocks
+ (comment-intro . 0) ;; Don't indent for comments
+ (c . 1) ;; Don't indent for comment continuations
+ (brace-list-intro . +) ;; Do indent the first line in enums
+ (brace-list-entry . 0) ;; Do not indent additional lines inside enums
+ (brace-entry-open . 0) ;; Do not indent additional lines inside brace lists
+ (brace-list-close . 0) ;; Go back after brace list closes
+ (topmost-intro-cont . 0) ;; top-level continued (like argument in function pointer typedef)
+ (arglist-intro . +) ;; Do indent initial argument
+ (arglist-cont-nonempty . +) ;; Do indent additional argument lines
+ (arglist-close . 0) ;; Do not indent closing paren
+ )))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
8f31145cfb4b39bed3c1c6917b797c222ce0769a
|
add rvm
|
diff --git a/dot.bashrc b/dot.bashrc
index 320faa6..c186e50 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,118 +1,119 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function fanmax
{
sudo rmmod thinkpad_acpi
sudo modprobe thinkpad_acpi fan_control=1
sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
}
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
+[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
|
IvanPulleyn/dotfiles
|
996f0cdefa46b8b1441497f7049e3e27940358aa
|
disable annoying mirror mode for javascript
|
diff --git a/dot.emacs b/dot.emacs
index 08279cc..d2d4b0f 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,67 +1,68 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
+(setq js2-mirror-mode nil)
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent)
(setq indent-tabs-mode nil))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-text-string)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
a30fbbb6fe832b6bb33a84015a947708bf49b4dc
|
ubuntu maverick fan bug workaround for x201s
|
diff --git a/dot.bashrc b/dot.bashrc
index 1f5fbb3..320faa6 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,111 +1,118 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
+function fanmax
+{
+ sudo rmmod thinkpad_acpi
+ sudo modprobe thinkpad_acpi fan_control=1
+ sudo bash -c 'sudo echo "level disengaged" > /proc/acpi/ibm/fan'
+}
+
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
|
IvanPulleyn/dotfiles
|
b267548d9d3d5189bbac6dd8fd93e0464cb6e17b
|
fix android path
|
diff --git a/dot.bashrc b/dot.bashrc
index 7e00b4e..1f5fbb3 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,111 +1,111 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
-export PATH=$HOME/android-sdk-linux_86/tools:$PATH
+export PATH=$HOME/android-sdk-linux_x86/tools:$PATH
export PATH=$PATH:/sbin
export PATH=$PATH:/usr/sbin
export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
|
IvanPulleyn/dotfiles
|
502375c2a2a89d6e1aead9cd3d4e21fd6fcb15dd
|
disable tabs in c-mode
|
diff --git a/dot.emacs b/dot.emacs
index 5ed735e..1e30b65 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,66 +1,67 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(load "nxml-mode-20041004/rng-auto.el")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
("\\.xml$" . nxml-mode)
("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
- (local-set-key (kbd "RET") 'newline-and-indent))
+ (local-set-key (kbd "RET") 'newline-and-indent)
+ (setq indent-tabs-mode nil))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-symbol)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
b9a614554152a0aa45584c84af405855eb44fea2
|
- always enable nxml-mode
|
diff --git a/dot.emacs b/dot.emacs
index b749072..5ed735e 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,65 +1,66 @@
; -*- mode: lisp; -*-
(setq load-path
(append (list nil
"~ivan/dotfiles/")
load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
+(load "nxml-mode-20041004/rng-auto.el")
+
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
+ ("\\.xml$" . nxml-mode)
+ ("\\.xsl$" . nxml-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
-;; nxml-mode
-(defun enable-nxml () (interactive) (load "nxml-mode-20041004/rng-auto.el"))
-
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-symbol)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
55b0c6e514937184f240dff3edf0dafa7cf76499
|
- add enable-nxml - add .gitignore
|
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b25c15b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*~
diff --git a/dot.emacs b/dot.emacs
index 7d32917..b749072 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,59 +1,65 @@
; -*- mode: lisp; -*-
-(setq load-path (cons "~ivan/dotfiles" load-path))
+(setq load-path
+ (append (list nil
+ "~ivan/dotfiles/")
+ load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
+;; nxml-mode
+(defun enable-nxml () (interactive) (load "nxml-mode-20041004/rng-auto.el"))
+
;; c-mode
(defun my-c-mode-common-hook ()
(local-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-symbol)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
ec45230565e4fd1882fa02cbe811b8012fd79675
|
- fix c-mode
|
diff --git a/dot.emacs b/dot.emacs
index 7efaaea..7d32917 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,59 +1,59 @@
; -*- mode: lisp; -*-
(setq load-path (cons "~ivan/dotfiles" load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
+(setq c-default-style "bsd")
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
- (setq tab-width 2 indent-tabs-mode nil)
- (define-key c-mode-map "\C-m" 'newline-and-indent))
+ (local-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f1] 'cscope-find-global-definition)
(global-set-key [f2] 'cscope-find-this-symbol)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
2fc096897b55f6a163208fc4afaf78fe917e41a5
|
- fix path in emacsrc - add sbin to path
|
diff --git a/dot.bashrc b/dot.bashrc
index 05c937a..7e00b4e 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,109 +1,111 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
+export PATH=$HOME/local/bin:$PATH
+export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
-export PATH=$HOME/.cabal/bin:$PATH
-export PATH=/usr/lib/postgresql/8.4/bin:$PATH
-export PATH=/opt/ghc/6.10.4/bin:$PATH
export PATH=$HOME/android-sdk-linux_86/tools:$PATH
+export PATH=$PATH:/sbin
+export PATH=$PATH:/usr/sbin
+export PATH=$PATH:/usr/local/sbin
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
diff --git a/dot.emacs b/dot.emacs
index dd20ebc..7efaaea 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,57 +1,59 @@
; -*- mode: lisp; -*-
-(setq load-path (cons "~/dotfiles" load-path))
+(setq load-path (cons "~ivan/dotfiles" load-path))
(require 'git)
(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(setq tab-width 2 indent-tabs-mode nil)
(define-key c-mode-map "\C-m" 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
+(global-set-key [f1] 'cscope-find-global-definition)
+(global-set-key [f2] 'cscope-find-this-symbol)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
|
IvanPulleyn/dotfiles
|
5e62065a3d597ddd96ad27113e6650eebf2470c2
|
add xcscope.el
|
diff --git a/cscope-indexer b/cscope-indexer
new file mode 100755
index 0000000..13c0ae2
--- /dev/null
+++ b/cscope-indexer
@@ -0,0 +1,166 @@
+#! /bin/sh
+###############################################################################
+#
+# File: cscope-indexer
+# RCS: $Header: /cvsroot/cscope/cscope/contrib/xcscope/cscope-indexer,v 1.2 2001/06/28 04:39:47 darrylo Exp $
+# Description: Script to index files for cscope
+#
+# This script generates a list of files to index
+# (cscope.out), which is then (optionally) used to
+# generate a cscope database. You can use this script
+# to just build a list of files, or it can be used to
+# build a list and database. This script is not used to
+# just build a database (skipping the list of files
+# step), as this can be simply done by just calling
+# "cscope -b".
+#
+# Normally, cscope will do its own indexing, but this
+# script can be used to force indexing. This is useful
+# if you need to recurse into subdirectories, or have
+# many files to index (you can run this script from a
+# cron job, during the night). It is especially useful
+# for large projects, which can contstantly have source
+# files added and deleted; by using this script, the
+# changing sources files are automatically handled.
+#
+# Currently, any paths containing "/CVS/" or "/RCS/" are
+# stripped out (ignored).
+#
+# This script is written to use only basic shell features, as
+# not all shells have advanced features.
+#
+# Author: Darryl Okahata
+# Created: Thu Apr 27 17:12:14 2000
+# Modified: Tue Jun 19 09:47:45 2001 (Darryl Okahata) darrylo@soco.agilent.com
+# Language: Shell-script
+# Package: N/A
+# Status: Experimental
+#
+# (C) Copyright 2000, Darryl Okahata, all rights reserved.
+#
+###############################################################################
+#
+# Usage:
+#
+# cscope-indexer [ -v ] [-f database_file ] [-i list_file ] [ -l ] [ -r ]
+#
+# where:
+#
+# -f database_file
+# Specifies the cscope database file (default: cscope.out).
+#
+# -i list_file
+# Specifies the name of the file into which the list of files
+# to index is placed (default: cscope.files).
+#
+# -l
+# Suppress the generation/updating of the cscope database
+# file. Only a list of files is generated.
+#
+# -r
+# Recurse into subdirectories to locate files to index.
+# Without this option, only the current directory is
+# searched.
+#
+# -v
+# Be verbose. Output simple progress messages.
+#
+#
+###############################################################################
+set -e
+
+# May have to edit this:
+PATH="/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin:$PATH"
+export PATH
+
+LIST_ONLY=
+DIR='.'
+LIST_FILE='cscope.files'
+DATABASE_FILE='cscope.out'
+RECURSE=
+VERBOSE=
+export DIR RECURSE # Need to pass these to subprocesses
+
+while [ -n "$1" ]
+do
+ case "$1" in
+ -f)
+ if [ "X$2" = "X" ]
+ then
+ echo "$0: No database file specified" >&2
+ exit 1
+ fi
+ DATABASE_FILE="$2"
+ shift
+ ;;
+ -i)
+ if [ "X$2" = "X" ]
+ then
+ echo "$0: No list file specified" >&2
+ exit 1
+ fi
+ LIST_FILE="$2"
+ shift
+ ;;
+ -l)
+ LIST_ONLY=1
+ ;;
+ -r)
+ RECURSE=1
+ ;;
+ -v)
+ VERBOSE=1
+ ;;
+ *)
+ DIR="$1"
+ ;;
+ esac
+ shift
+done
+
+cd $DIR
+
+if [ "X$VERBOSE" != "X" ]
+then
+ echo "Creating list of files to index ..."
+fi
+
+(
+ if [ "X$RECURSE" = "X" ]
+ then
+ # Ugly, inefficient, but it works.
+ for f in *
+ do
+ echo "$DIR/$f"
+ done
+ else
+ find $DIR \( -type f -o -type l \)
+ fi
+) | \
+ egrep -i '\.([chly](xx|pp)*|cc|hh)$' | \
+ sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e 's/^\.\///' | \
+ sort > $LIST_FILE
+
+if [ "X$VERBOSE" != "X" ]
+then
+ echo "Creating list of files to index ... done"
+fi
+
+if [ "X$LIST_ONLY" != "X" ]
+then
+ exit 0
+fi
+
+if [ "X$VERBOSE" != "X" ]
+then
+ echo "Indexing files ..."
+fi
+
+cscope -b -i $LIST_FILE -f $DATABASE_FILE
+
+if [ "X$VERBOSE" != "X" ]
+then
+ echo "Indexing files ... done"
+fi
+
+exit 0
diff --git a/dot.bashrc b/dot.bashrc
index 84278c9..05c937a 100644
--- a/dot.bashrc
+++ b/dot.bashrc
@@ -1,108 +1,109 @@
# -*- mode: sh; -*-
##############################################################################
[ -z "$PS1" ] && return
+export PATH=$HOME/dotfiles:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/rpx/sys/bin:$PATH
export PATH=$HOME/opt/bin:$PATH
export PATH=$HOME/.cabal/bin:$PATH
export PATH=/usr/lib/postgresql/8.4/bin:$PATH
export PATH=/opt/ghc/6.10.4/bin:$PATH
export PATH=$HOME/android-sdk-linux_86/tools:$PATH
export MANPATH=$HOME/rpx/sys/man:$MANPATH
export HISTCONTROL=ignoreboth
export HISTFILESIZE=1000000
export HISTSIZE=1000000
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
export PS1='\u@\h\$ '
export EDITOR=emacs
export VISUAL=$EDITOR
if [ "$EMACS" = "t" ]; then
export PAGER=cat
fi
alias emacs='emacs -nw'
shopt -s histappend
shopt -s checkwinsize
function rmtmp
{
find . -name \*~ -print0 | xargs -0 rm -f
}
function now
{
date +%Y%m%d%H%M%S
}
# buzz
function bzlogin
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Login -buzz
}
function bzcons
{
java -cp $HOME/dotfiles/oacurl-1.0.0.jar com.google.oacurl.Fetch https://www.googleapis.com/buzz/v1/activities/@me/@consumption?prettyprint=true
}
function sfs
{
USAGE="Usage: sfs [on|off]"
if [ -z "$1" -o -n "$2" ]; then
echo "$USAGE"
return 1
elif [ "$1" != "on" -a "$1" != "off" ]; then
echo "$USAGE"
return 1
fi
SFS_HOSTS="`cat ~/.sfs_hosts 2>/dev/null`"
if [ -z "$SFS_HOSTS" ]; then
echo "no remote hosts configured"
return 0
fi
MY_UID=`id | sed -e's/^uid=\([0-9]*\).*/\1/'`
MY_GID=`id | sed -e's/.* gid=\([0-9]*\).*/\1/'`
for x in $SFS_HOSTS
do
if [ "$1" = "on" ]; then
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "$x already mounted"
else
echo "mounting $x"
mkdir -p $HOME/mnt/$x
sshfs -C -o idmap=user -o uid=$MY_UID -o gid=$MY_GID -o reconnect $x: $HOME/mnt/$x
fi
else
mount | grep "^$x" >/dev/null
if [ "$?" = "0" ]; then
echo "unmounting $x"
fusermount -u $HOME/mnt/$x
else
echo "$x not mounted"
fi
fi
done
}
##############################################################################
# local stuff
if [ -f $HOME/.bashrc.local ]; then
. $HOME/.bashrc.local
fi
diff --git a/dot.emacs b/dot.emacs
index b92a4e1..dd20ebc 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,56 +1,57 @@
; -*- mode: lisp; -*-
(setq load-path (cons "~/dotfiles" load-path))
(require 'git)
+(require 'xcscope)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(setq tab-width 2 indent-tabs-mode nil)
(define-key c-mode-map "\C-m" 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
diff --git a/xcscope.el b/xcscope.el
new file mode 100644
index 0000000..ce382a4
--- /dev/null
+++ b/xcscope.el
@@ -0,0 +1,2463 @@
+; -*-Emacs-Lisp-*-
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;
+; File: xcscope.el
+; RCS: $RCSfile: xcscope.el,v $ $Revision: 1.14 $ $Date: 2002/04/10 16:59:00 $ $Author: darrylo $
+; Description: cscope interface for (X)Emacs
+; Author: Darryl Okahata
+; Created: Wed Apr 19 17:03:38 2000
+; Modified: Thu Apr 4 17:22:22 2002 (Darryl Okahata) darrylo@soco.agilent.com
+; Language: Emacs-Lisp
+; Package: N/A
+; Status: Experimental
+;
+; (C) Copyright 2000, 2001, 2002, Darryl Okahata <darrylo@sonic.net>,
+; all rights reserved.
+; GNU Emacs enhancements (C) Copyright 2001,
+; Triet H. Lai <thlai@mail.usyd.edu.au>
+; Fuzzy matching and navigation code (C) Copyright 2001,
+; Steven Elliott <selliott4@austin.rr.com>
+;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; ALPHA VERSION 0.96
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; This is a cscope interface for (X)Emacs.
+;; It currently runs under Unix only.
+;;
+;; Using cscope, you can easily search for where symbols are used and defined.
+;; Cscope is designed to answer questions like:
+;;
+;; Where is this variable used?
+;; What is the value of this preprocessor symbol?
+;; Where is this function in the source files?
+;; What functions call this function?
+;; What functions are called by this function?
+;; Where does the message "out of space" come from?
+;; Where is this source file in the directory structure?
+;; What files include this header file?
+;;
+;; Send comments to one of: darrylo@soco.agilent.com
+;; darryl_okahata@agilent.com
+;; darrylo@sonic.net
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; ***** INSTALLATION *****
+;;
+;; * NOTE: this interface currently runs under Unix only.
+;;
+;; This module needs a shell script called "cscope-indexer", which
+;; should have been supplied along with this emacs-lisp file. The
+;; purpose of "cscope-indexer" is to create and optionally maintain
+;; the cscope databases. If all of your source files are in one
+;; directory, you don't need this script; it's very nice to have,
+;; though, as it handles recursive subdirectory indexing, and can be
+;; used in a nightly or weekly cron job to index very large source
+;; repositories. See the beginning of the file, "cscope-indexer", for
+;; usage information.
+;;
+;; Installation steps:
+;;
+;; 0. (It is, of course, assumed that cscope is already properly
+;; installed on the current system.)
+;;
+;; 1. Install the "cscope-indexer" script into some convenient
+;; directory in $PATH. The only real constraint is that (X)Emacs
+;; must be able to find and execute it. You may also have to edit
+;; the value of PATH in the script, although this is unlikely; the
+;; majority of people should be able to use the script, "as-is".
+;;
+;; 2. Make sure that the "cscope-indexer" script is executable. In
+;; particular, if you had to ftp this file, it is probably no
+;; longer executable.
+;;
+;; 3. Put this emacs-lisp file somewhere where (X)Emacs can find it. It
+;; basically has to be in some directory listed in "load-path".
+;;
+;; 4. Edit your ~/.emacs file to add the line:
+;;
+;; (require 'xcscope)
+;;
+;; 5. If you intend to use xcscope.el often you can optionally edit your
+;; ~/.emacs file to add keybindings that reduce the number of keystrokes
+;; required. For example, the following will add "C-f#" keybindings, which
+;; are easier to type than the usual "C-c s" prefixed keybindings. Note
+;; that specifying "global-map" instead of "cscope:map" makes the
+;; keybindings available in all buffers:
+;;
+;; (define-key global-map [(control f3)] 'cscope-set-initial-directory)
+;; (define-key global-map [(control f4)] 'cscope-unset-initial-directory)
+;; (define-key global-map [(control f5)] 'cscope-find-this-symbol)
+;; (define-key global-map [(control f6)] 'cscope-find-global-definition)
+;; (define-key global-map [(control f7)]
+;; 'cscope-find-global-definition-no-prompting)
+;; (define-key global-map [(control f8)] 'cscope-pop-mark)
+;; (define-key global-map [(control f9)] 'cscope-next-symbol)
+;; (define-key global-map [(control f10)] 'cscope-next-file)
+;; (define-key global-map [(control f11)] 'cscope-prev-symbol)
+;; (define-key global-map [(control f12)] 'cscope-prev-file)
+;; (define-key global-map [(meta f9)] 'cscope-display-buffer)
+;; (defin-ekey global-map [(meta f10)] 'cscope-display-buffer-toggle)
+;;
+;; 6. Restart (X)Emacs. That's it.
+;;
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; ***** USING THIS MODULE *****
+;;
+;; * Basic usage:
+;;
+;; If all of your C/C++/lex/yacc source files are in the same
+;; directory, you can just start using this module. If your files are
+;; spread out over multiple directories, see "Advanced usage", below.
+;;
+;; Just edit a source file, and use the pull-down or pop-up (button 3)
+;; menus to select one of:
+;;
+;; Find symbol
+;; Find global definition
+;; Find called functions
+;; Find functions calling a function
+;; Find text string
+;; Find egrep pattern
+;; Find a file
+;; Find files #including a file
+;;
+;; The cscope database will be automatically created in the same
+;; directory as the source files (assuming that you've never used
+;; cscope before), and a buffer will pop-up displaying the results.
+;; You can then use button 2 (the middle button) on the mouse to edit
+;; the selected file, or you can move the text cursor over a selection
+;; and press [Enter].
+;;
+;; Hopefully, the interface should be fairly intuitive.
+;;
+;;
+;; * Locating the cscope databases:
+;;
+;; This module will first use the variable, `cscope-database-regexps',
+;; to search for a suitable database directory. If a database location
+;; cannot be found using this variable then a search is begun at the
+;; variable, `cscope-initial-directory', if set, or the current
+;; directory otherwise. If the directory is not a cscope database
+;; directory then the directory's parent, parent's parent, etc. is
+;; searched until a cscope database directory is found, or the root
+;; directory is reached. If the root directory is reached, the current
+;; directory will be used.
+;;
+;; A cscope database directory is one in which EITHER a cscope database
+;; file (e.g., "cscope.out") OR a cscope file list (e.g.,
+;; "cscope.files") exists. If only "cscope.files" exists, the
+;; corresponding "cscope.out" will be automatically created by cscope
+;; when a search is done. By default, the cscope database file is called
+;; "cscope.out", but this can be changed (on a global basis) via the
+;; variable, `cscope-database-file'. There is limited support for cscope
+;; databases that are named differently than that given by
+;; `cscope-database-file', using the variable, `cscope-database-regexps'.
+;;
+;; Note that the variable, `cscope-database-regexps', is generally not
+;; needed, as the normal hierarchical database search is sufficient
+;; for placing and/or locating the cscope databases. However, there
+;; may be cases where it makes sense to place the cscope databases
+;; away from where the source files are kept; in this case, this
+;; variable is used to determine the mapping. One use for this
+;; variable is when you want to share the database file with other
+;; users; in this case, the database may be located in a directory
+;; separate from the source files.
+;;
+;; Setting the variable, `cscope-initial-directory', is useful when a
+;; search is to be expanded by specifying a cscope database directory
+;; that is a parent of the directory that this module would otherwise
+;; use. For example, consider a project that contains the following
+;; cscope database directories:
+;;
+;; /users/jdoe/sources
+;; /users/jdoe/sources/proj1
+;; /users/jdoe/sources/proj2
+;;
+;; If a search is initiated from a .c file in /users/jdoe/sources/proj1
+;; then (assuming the variable, `cscope-database-regexps', is not set)
+;; /users/jdoe/sources/proj1 will be used as the cscope data base directory.
+;; Only matches in files in /users/jdoe/sources/proj1 will be found. This
+;; can be remedied by typing "C-c s a" and then "M-del" to remove single
+;; path element in order to use a cscope database directory of
+;; /users/jdoe/sources. Normal searching can be restored by typing "C-c s A".
+;;
+;;
+;; * Keybindings:
+;;
+;; All keybindings use the "C-c s" prefix, but are usable only while
+;; editing a source file, or in the cscope results buffer:
+;;
+;; C-c s s Find symbol.
+;; C-c s d Find global definition.
+;; C-c s g Find global definition (alternate binding).
+;; C-c s G Find global definition without prompting.
+;; C-c s c Find functions calling a function.
+;; C-c s C Find called functions (list functions called
+;; from a function).
+;; C-c s t Find text string.
+;; C-c s e Find egrep pattern.
+;; C-c s f Find a file.
+;; C-c s i Find files #including a file.
+;;
+;; These pertain to navigation through the search results:
+;;
+;; C-c s b Display *cscope* buffer.
+;; C-c s B Auto display *cscope* buffer toggle.
+;; C-c s n Next symbol.
+;; C-c s N Next file.
+;; C-c s p Previous symbol.
+;; C-c s P Previous file.
+;; C-c s u Pop mark.
+;;
+;; These pertain to setting and unsetting the variable,
+;; `cscope-initial-directory', (location searched for the cscope database
+;; directory):
+;;
+;; C-c s a Set initial directory.
+;; C-c s A Unset initial directory.
+;;
+;; These pertain to cscope database maintenance:
+;;
+;; C-c s L Create list of files to index.
+;; C-c s I Create list and index.
+;; C-c s E Edit list of files to index.
+;; C-c s W Locate this buffer's cscope directory
+;; ("W" --> "where").
+;; C-c s S Locate this buffer's cscope directory.
+;; (alternate binding: "S" --> "show").
+;; C-c s T Locate this buffer's cscope directory.
+;; (alternate binding: "T" --> "tell").
+;; C-c s D Dired this buffer's directory.
+;;
+;;
+;; * Advanced usage:
+;;
+;; If the source files are spread out over multiple directories,
+;; you've got a few choices:
+;;
+;; [ NOTE: you will need to have the script, "cscope-indexer",
+;; properly installed in order for the following to work. ]
+;;
+;; 1. If all of the directories exist below a common directory
+;; (without any extraneous, unrelated subdirectories), you can tell
+;; this module to place the cscope database into the top-level,
+;; common directory. This assumes that you do not have any cscope
+;; databases in any of the subdirectories. If you do, you should
+;; delete them; otherwise, they will take precedence over the
+;; top-level database.
+;;
+;; If you do have cscope databases in any subdirectory, the
+;; following instructions may not work right.
+;;
+;; It's pretty easy to tell this module to use a top-level, common
+;; directory:
+;;
+;; a. Make sure that the menu pick, "Cscope/Index recursively", is
+;; checked (the default value).
+;;
+;; b. Select the menu pick, "Cscope/Create list and index", and
+;; specify the top-level directory. This will run the script,
+;; "cscope-indexer", in the background, so you can do other
+;; things if indexing takes a long time. A list of files to
+;; index will be created in "cscope.files", and the cscope
+;; database will be created in "cscope.out".
+;;
+;; Once this has been done, you can then use the menu picks
+;; (described in "Basic usage", above) to search for symbols.
+;;
+;; Note, however, that, if you add or delete source files, you'll
+;; have to either rebuild the database using the above procedure,
+;; or edit the file, "cscope.files" to add/delete the names of the
+;; source files. To edit this file, you can use the menu pick,
+;; "Cscope/Edit list of files to index".
+;;
+;;
+;; 2. If most of the files exist below a common directory, but a few
+;; are outside, you can use the menu pick, "Cscope/Create list of
+;; files to index", and specify the top-level directory. Make sure
+;; that "Cscope/Index recursively", is checked before you do so,
+;; though. You can then edit the list of files to index using the
+;; menu pick, "Cscope/Edit list of files to index". Just edit the
+;; list to include any additional source files not already listed.
+;;
+;; Once you've created, edited, and saved the list, you can then
+;; use the menu picks described under "Basic usage", above, to
+;; search for symbols. The first time you search, you will have to
+;; wait a while for cscope to fully index the source files, though.
+;; If you have a lot of source files, you may want to manually run
+;; cscope to build the database:
+;;
+;; cd top-level-directory # or wherever
+;; rm -f cscope.out # not always necessary
+;; cscope -b
+;;
+;;
+;; 3. If the source files are scattered in many different, unrelated
+;; places, you'll have to manually create cscope.files and put a
+;; list of all pathnames into it. Then build the database using:
+;;
+;; cd some-directory # wherever cscope.files exists
+;; rm -f cscope.out # not always necessary
+;; cscope -b
+;;
+;; Next, read the documentation for the variable,
+;; "cscope-database-regexps", and set it appropriately, such that
+;; the above-created cscope database will be referenced when you
+;; edit a related source file.
+;;
+;; Once this has been done, you can then use the menu picks
+;; described under "Basic usage", above, to search for symbols.
+;;
+;;
+;; * Interesting configuration variables:
+;;
+;; "cscope-truncate-lines"
+;; This is the value of `truncate-lines' to use in cscope
+;; buffers; the default is the current setting of
+;; `truncate-lines'. This variable exists because it can be
+;; easier to read cscope buffers with truncated lines, while
+;; other buffers do not have truncated lines.
+;;
+;; "cscope-use-relative-paths"
+;; If non-nil, use relative paths when creating the list of files
+;; to index. The path is relative to the directory in which the
+;; cscope database will be created. If nil, absolute paths will
+;; be used. Absolute paths are good if you plan on moving the
+;; database to some other directory (if you do so, you'll
+;; probably also have to modify `cscope-database-regexps').
+;; Absolute paths may also be good if you share the database file
+;; with other users (you'll probably want to specify some
+;; automounted network path for this).
+;;
+;; "cscope-index-recursively"
+;; If non-nil, index files in the current directory and all
+;; subdirectories. If nil, only files in the current directory
+;; are indexed. This variable is only used when creating the
+;; list of files to index, or when creating the list of files and
+;; the corresponding cscope database.
+;;
+;; "cscope-name-line-width"
+;; The width of the combined "function name:line number" field in
+;; the cscope results buffer. If negative, the field is
+;; left-justified.
+;;
+;; "cscope-do-not-update-database"
+;; If non-nil, never check and/or update the cscope database when
+;; searching. Beware of setting this to non-nil, as this will
+;; disable automatic database creation, updating, and
+;; maintenance.
+;;
+;; "cscope-display-cscope-buffer"
+;; If non-nil, display the *cscope* buffer after each search
+;; (default). This variable can be set in order to reduce the
+;; number of keystrokes required to navigate through the matches.
+;;
+;; "cscope-database-regexps"
+;; List to force directory-to-cscope-database mappings.
+;; This is a list of `(REGEXP DBLIST [ DBLIST ... ])', where:
+;;
+;; REGEXP is a regular expression matched against the current buffer's
+;; current directory. The current buffer is typically some source file,
+;; and you're probably searching for some symbol in or related to this
+;; file. Basically, this regexp is used to relate the current directory
+;; to a cscope database. You need to start REGEXP with "^" if you want
+;; to match from the beginning of the current directory.
+;;
+;; DBLIST is a list that contains one or more of:
+;;
+;; ( DBDIR )
+;; ( DBDIR ( OPTIONS ) )
+;; ( t )
+;; t
+;;
+;; Here, DBDIR is a directory (or a file) that contains a cscope
+;; database. If DBDIR is a directory, then it is expected that the
+;; cscope database, if present, has the filename given by the variable,
+;; `cscope-database-file'; if DBDIR is a file, then DBDIR is the path
+;; name to a cscope database file (which does not have to be the same as
+;; that given by `cscope-database-file'). If only DBDIR is specified,
+;; then that cscope database will be searched without any additional
+;; cscope command-line options. If OPTIONS is given, then OPTIONS is a
+;; list of strings, where each string is a separate cscope command-line
+;; option.
+;;
+;; In the case of "( t )", this specifies that the search is to use the
+;; normal hierarchical database search. This option is used to
+;; explicitly search using the hierarchical database search either before
+;; or after other cscope database directories.
+;;
+;; If "t" is specified (not inside a list), this tells the searching
+;; mechanism to stop searching if a match has been found (at the point
+;; where "t" is encountered). This is useful for those projects that
+;; consist of many subprojects. You can specify the most-used
+;; subprojects first, followed by a "t", and then followed by a master
+;; cscope database directory that covers all subprojects. This will
+;; cause the most-used subprojects to be searched first (hopefully
+;; quickly), and the search will then stop if a match was found. If not,
+;; the search will continue using the master cscope database directory.
+;;
+;; Here, `cscope-database-regexps' is generally not used, as the normal
+;; hierarchical database search is sufficient for placing and/or locating
+;; the cscope databases. However, there may be cases where it makes
+;; sense to place the cscope databases away from where the source files
+;; are kept; in this case, this variable is used to determine the
+;; mapping.
+;;
+;; This module searches for the cscope databases by first using this
+;; variable; if a database location cannot be found using this variable,
+;; then the current directory is searched, then the parent, then the
+;; parent's parent, until a cscope database directory is found, or the
+;; root directory is reached. If the root directory is reached, the
+;; current directory will be used.
+;;
+;; A cscope database directory is one in which EITHER a cscope database
+;; file (e.g., "cscope.out") OR a cscope file list (e.g.,
+;; "cscope.files") exists. If only "cscope.files" exists, the
+;; corresponding "cscope.out" will be automatically created by cscope
+;; when a search is done. By default, the cscope database file is called
+;; "cscope.out", but this can be changed (on a global basis) via the
+;; variable, `cscope-database-file'. There is limited support for cscope
+;; databases that are named differently than that given by
+;; `cscope-database-file', using the variable, `cscope-database-regexps'.
+;;
+;; Here is an example of `cscope-database-regexps':
+;;
+;; (setq cscope-database-regexps
+;; '(
+;; ( "^/users/jdoe/sources/proj1"
+;; ( t )
+;; ( "/users/jdoe/sources/proj2")
+;; ( "/users/jdoe/sources/proj3/mycscope.out")
+;; ( "/users/jdoe/sources/proj4")
+;; t
+;; ( "/some/master/directory" ("-d" "-I/usr/local/include") )
+;; )
+;; ( "^/users/jdoe/sources/gnome/"
+;; ( "/master/gnome/database" ("-d") )
+;; )
+;; ))
+;;
+;; If the current buffer's directory matches the regexp,
+;; "^/users/jdoe/sources/proj1", then the following search will be
+;; done:
+;;
+;; 1. First, the normal hierarchical database search will be used to
+;; locate a cscope database.
+;;
+;; 2. Next, searches will be done using the cscope database
+;; directories, "/users/jdoe/sources/proj2",
+;; "/users/jdoe/sources/proj3/mycscope.out", and
+;; "/users/jdoe/sources/proj4". Note that, instead of the file,
+;; "cscope.out", the file, "mycscope.out", will be used in the
+;; directory "/users/jdoe/sources/proj3".
+;;
+;; 3. If a match was found, searching will stop.
+;;
+;; 4. If a match was not found, searching will be done using
+;; "/some/master/directory", and the command-line options "-d"
+;; and "-I/usr/local/include" will be passed to cscope.
+;;
+;; If the current buffer's directory matches the regexp,
+;; "^/users/jdoe/sources/gnome", then the following search will be
+;; done:
+;;
+;; The search will be done only using the directory,
+;; "/master/gnome/database". The "-d" option will be passed to
+;; cscope.
+;;
+;; If the current buffer's directory does not match any of the above
+;; regexps, then only the normal hierarchical database search will be
+;; done.
+;;
+;;
+;; * Other notes:
+;;
+;; 1. The script, "cscope-indexer", uses a sed command to determine
+;; what is and is not a C/C++/lex/yacc source file. It's idea of a
+;; source file may not correspond to yours.
+;;
+;; 2. This module is called, "xcscope", because someone else has
+;; already written a "cscope.el" (although it's quite old).
+;;
+;;
+;; * KNOWN BUGS:
+;;
+;; 1. Cannot handle whitespace in directory or file names.
+;;
+;; 2. By default, colored faces are used to display results. If you happen
+;; to use a black background, part of the results may be invisible
+;; (because the foreground color may be black, too). There are at least
+;; two solutions for this:
+;;
+;; 2a. Turn off colored faces, by setting `cscope-use-face' to `nil',
+;; e.g.:
+;;
+;; (setq cscope-use-face nil)
+;;
+;; 2b. Explicitly set colors for the faces used by cscope. The faces
+;; are:
+;;
+;; cscope-file-face
+;; cscope-function-face
+;; cscope-line-number-face
+;; cscope-line-face
+;; cscope-mouse-face
+;;
+;; The face most likely to cause problems (e.g., black-on-black
+;; color) is `cscope-line-face'.
+;;
+;; 3. The support for cscope databases different from that specified by
+;; `cscope-database-file' is quirky. If the file does not exist, it
+;; will not be auto-created (unlike files names by
+;; `cscope-database-file'). You can manually force the file to be
+;; created by using touch(1) to create a zero-length file; the
+;; database will be created the next time a search is done.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'easymenu)
+
+
+(defgroup cscope nil
+ "Cscope interface for (X)Emacs.
+Using cscope, you can easily search for where symbols are used and defined.
+It is designed to answer questions like:
+
+ Where is this variable used?
+ What is the value of this preprocessor symbol?
+ Where is this function in the source files?
+ What functions call this function?
+ What functions are called by this function?
+ Where does the message \"out of space\" come from?
+ Where is this source file in the directory structure?
+ What files include this header file?
+"
+ :prefix "cscope-"
+ :group 'tools)
+
+
+(defcustom cscope-do-not-update-database nil
+ "*If non-nil, never check and/or update the cscope database when searching.
+Beware of setting this to non-nil, as this will disable automatic database
+creation, updating, and maintenance."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-database-regexps nil
+ "*List to force directory-to-cscope-database mappings.
+This is a list of `(REGEXP DBLIST [ DBLIST ... ])', where:
+
+REGEXP is a regular expression matched against the current buffer's
+current directory. The current buffer is typically some source file,
+and you're probably searching for some symbol in or related to this
+file. Basically, this regexp is used to relate the current directory
+to a cscope database. You need to start REGEXP with \"^\" if you want
+to match from the beginning of the current directory.
+
+DBLIST is a list that contains one or more of:
+
+ ( DBDIR )
+ ( DBDIR ( OPTIONS ) )
+ ( t )
+ t
+
+Here, DBDIR is a directory (or a file) that contains a cscope database.
+If DBDIR is a directory, then it is expected that the cscope database,
+if present, has the filename given by the variable,
+`cscope-database-file'; if DBDIR is a file, then DBDIR is the path name
+to a cscope database file (which does not have to be the same as that
+given by `cscope-database-file'). If only DBDIR is specified, then that
+cscope database will be searched without any additional cscope
+command-line options. If OPTIONS is given, then OPTIONS is a list of
+strings, where each string is a separate cscope command-line option.
+
+In the case of \"( t )\", this specifies that the search is to use the
+normal hierarchical database search. This option is used to
+explicitly search using the hierarchical database search either before
+or after other cscope database directories.
+
+If \"t\" is specified (not inside a list), this tells the searching
+mechanism to stop searching if a match has been found (at the point
+where \"t\" is encountered). This is useful for those projects that
+consist of many subprojects. You can specify the most-used
+subprojects first, followed by a \"t\", and then followed by a master
+cscope database directory that covers all subprojects. This will
+cause the most-used subprojects to be searched first (hopefully
+quickly), and the search will then stop if a match was found. If not,
+the search will continue using the master cscope database directory.
+
+Here, `cscope-database-regexps' is generally not used, as the normal
+hierarchical database search is sufficient for placing and/or locating
+the cscope databases. However, there may be cases where it makes
+sense to place the cscope databases away from where the source files
+are kept; in this case, this variable is used to determine the
+mapping.
+
+This module searches for the cscope databases by first using this
+variable; if a database location cannot be found using this variable,
+then the current directory is searched, then the parent, then the
+parent's parent, until a cscope database directory is found, or the
+root directory is reached. If the root directory is reached, the
+current directory will be used.
+
+A cscope database directory is one in which EITHER a cscope database
+file (e.g., \"cscope.out\") OR a cscope file list (e.g.,
+\"cscope.files\") exists. If only \"cscope.files\" exists, the
+corresponding \"cscope.out\" will be automatically created by cscope
+when a search is done. By default, the cscope database file is called
+\"cscope.out\", but this can be changed (on a global basis) via the
+variable, `cscope-database-file'. There is limited support for cscope
+databases that are named differently than that given by
+`cscope-database-file', using the variable, `cscope-database-regexps'.
+
+Here is an example of `cscope-database-regexps':
+
+ (setq cscope-database-regexps
+ '(
+ ( \"^/users/jdoe/sources/proj1\"
+ ( t )
+ ( \"/users/jdoe/sources/proj2\")
+ ( \"/users/jdoe/sources/proj3/mycscope.out\")
+ ( \"/users/jdoe/sources/proj4\")
+ t
+ ( \"/some/master/directory\" (\"-d\" \"-I/usr/local/include\") )
+ )
+ ( \"^/users/jdoe/sources/gnome/\"
+ ( \"/master/gnome/database\" (\"-d\") )
+ )
+ ))
+
+If the current buffer's directory matches the regexp,
+\"^/users/jdoe/sources/proj1\", then the following search will be
+done:
+
+ 1. First, the normal hierarchical database search will be used to
+ locate a cscope database.
+
+ 2. Next, searches will be done using the cscope database
+ directories, \"/users/jdoe/sources/proj2\",
+ \"/users/jdoe/sources/proj3/mycscope.out\", and
+ \"/users/jdoe/sources/proj4\". Note that, instead of the file,
+ \"cscope.out\", the file, \"mycscope.out\", will be used in the
+ directory \"/users/jdoe/sources/proj3\".
+
+ 3. If a match was found, searching will stop.
+
+ 4. If a match was not found, searching will be done using
+ \"/some/master/directory\", and the command-line options \"-d\"
+ and \"-I/usr/local/include\" will be passed to cscope.
+
+If the current buffer's directory matches the regexp,
+\"^/users/jdoe/sources/gnome\", then the following search will be
+done:
+
+ The search will be done only using the directory,
+ \"/master/gnome/database\". The \"-d\" option will be passed to
+ cscope.
+
+If the current buffer's directory does not match any of the above
+regexps, then only the normal hierarchical database search will be
+done.
+
+"
+ :type '(repeat (list :format "%v"
+ (choice :value ""
+ (regexp :tag "Buffer regexp")
+ string)
+ (choice :value ""
+ (directory :tag "Cscope database directory")
+ string)
+ (string :value ""
+ :tag "Optional cscope command-line arguments")
+ ))
+ :group 'cscope)
+(defcustom cscope-name-line-width -30
+ "*The width of the combined \"function name:line number\" field in the
+cscope results buffer. If negative, the field is left-justified."
+ :type 'integer
+ :group 'cscope)
+
+
+(defcustom cscope-truncate-lines truncate-lines
+ "*The value of `truncate-lines' to use in cscope buffers.
+This variable exists because it can be easier to read cscope buffers
+with truncated lines, while other buffers do not have truncated lines."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-display-times t
+ "*If non-nil, display how long each search took.
+The elasped times are in seconds. Floating-point support is required
+for this to work."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-program "cscope"
+ "*The pathname of the cscope executable to use."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-index-file "cscope.files"
+ "*The name of the cscope file list file."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-database-file "cscope.out"
+ "*The name of the cscope database file."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-edit-single-match t
+ "*If non-nil and only one match is output, edit the matched location."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-display-cscope-buffer t
+ "*If non-nil automatically display the *cscope* buffer after each search."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-stop-at-first-match-dir nil
+ "*If non-nil, stop searching through multiple databases if a match is found.
+This option is useful only if multiple cscope database directories are being
+used. When multiple databases are searched, setting this variable to non-nil
+will cause searches to stop when a search outputs anything; no databases after
+this one will be searched."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-use-relative-paths t
+ "*If non-nil, use relative paths when creating the list of files to index.
+The path is relative to the directory in which the cscope database
+will be created. If nil, absolute paths will be used. Absolute paths
+are good if you plan on moving the database to some other directory
+(if you do so, you'll probably also have to modify
+\`cscope-database-regexps\'). Absolute paths may also be good if you
+share the database file with other users (you\'ll probably want to
+specify some automounted network path for this)."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-index-recursively t
+ "*If non-nil, index files in the current directory and all subdirectories.
+If nil, only files in the current directory are indexed. This
+variable is only used when creating the list of files to index, or
+when creating the list of files and the corresponding cscope database."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-no-mouse-prompts nil
+ "*If non-nil, use the symbol under the cursor instead of prompting.
+Do not prompt for a value, except for when seaching for a egrep pattern
+or a file."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-suppress-empty-matches t
+ "*If non-nil, delete empty matches.")
+
+
+(defcustom cscope-indexing-script "cscope-indexer"
+ "*The shell script used to create cscope indices."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-symbol-chars "A-Za-z0-9_"
+ "*A string containing legal characters in a symbol.
+The current syntax table should really be used for this."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-filename-chars "-.,/A-Za-z0-9_~!@#$%&+=\\\\"
+ "*A string containing legal characters in a symbol.
+The current syntax table should really be used for this."
+ :type 'string
+ :group 'cscope)
+
+
+(defcustom cscope-allow-arrow-overlays t
+ "*If non-nil, use an arrow overlay to show target lines.
+Arrow overlays are only used when the following functions are used:
+
+ cscope-show-entry-other-window
+ cscope-show-next-entry-other-window
+ cscope-show-prev-entry-other-window
+
+The arrow overlay is removed when other cscope functions are used.
+Note that the arrow overlay is not an actual part of the text, and can
+be removed by quitting the cscope buffer."
+ :type 'boolean
+ :group 'cscope)
+
+
+(defcustom cscope-overlay-arrow-string "=>"
+ "*The overlay string to use when displaying arrow overlays."
+ :type 'string
+ :group 'cscope)
+
+
+(defvar cscope-minor-mode-hooks nil
+ "List of hooks to call when entering cscope-minor-mode.")
+
+
+(defconst cscope-separator-line
+ "-------------------------------------------------------------------------------\n"
+ "Line of text to use as a visual separator.
+Must end with a newline.")
+
+
+;;;;
+;;;; Faces for fontification
+;;;;
+
+(defcustom cscope-use-face t
+ "*Whether to use text highlighting (à la font-lock) or not."
+ :group 'cscope
+ :type '(boolean))
+
+
+(defface cscope-file-face
+ '((((class color) (background dark))
+ (:foreground "yellow"))
+ (((class color) (background light))
+ (:foreground "blue"))
+ (t (:bold t)))
+ "Face used to highlight file name in the *cscope* buffer."
+ :group 'cscope)
+
+
+(defface cscope-function-face
+ '((((class color) (background dark))
+ (:foreground "cyan"))
+ (((class color) (background light))
+ (:foreground "magenta"))
+ (t (:bold t)))
+ "Face used to highlight function name in the *cscope* buffer."
+ :group 'cscope)
+
+
+(defface cscope-line-number-face
+ '((((class color) (background dark))
+ (:foreground "red"))
+ (((class color) (background light))
+ (:foreground "red"))
+ (t (:bold t)))
+ "Face used to highlight line number in the *cscope* buffer."
+ :group 'cscope)
+
+
+(defface cscope-line-face
+ '((((class color) (background dark))
+ (:foreground "green"))
+ (((class color) (background light))
+ (:foreground "black"))
+ (t (:bold nil)))
+ "Face used to highlight the rest of line in the *cscope* buffer."
+ :group 'cscope)
+
+
+(defface cscope-mouse-face
+ '((((class color) (background dark))
+ (:foreground "white" :background "blue"))
+ (((class color) (background light))
+ (:foreground "white" :background "blue"))
+ (t (:bold nil)))
+ "Face used when mouse pointer is within the region of an entry."
+ :group 'cscope)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Probably, nothing user-customizable past this point.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defconst cscope-running-in-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
+
+(defvar cscope-list-entry-keymap nil
+ "The keymap used in the *cscope* buffer which lists search results.")
+(if cscope-list-entry-keymap
+ nil
+ (setq cscope-list-entry-keymap (make-keymap))
+ (suppress-keymap cscope-list-entry-keymap)
+ ;; The following section does not appear in the "Cscope" menu.
+ (if cscope-running-in-xemacs
+ (define-key cscope-list-entry-keymap [button2] 'cscope-mouse-select-entry-other-window)
+ (define-key cscope-list-entry-keymap [mouse-2] 'cscope-mouse-select-entry-other-window))
+ (define-key cscope-list-entry-keymap [return] 'cscope-select-entry-other-window)
+ (define-key cscope-list-entry-keymap " " 'cscope-show-entry-other-window)
+ (define-key cscope-list-entry-keymap "o" 'cscope-select-entry-one-window)
+ (define-key cscope-list-entry-keymap "q" 'cscope-bury-buffer)
+ (define-key cscope-list-entry-keymap "Q" 'cscope-quit)
+ (define-key cscope-list-entry-keymap "h" 'cscope-help)
+ (define-key cscope-list-entry-keymap "?" 'cscope-help)
+ ;; The following line corresponds to be beginning of the "Cscope" menu.
+ (define-key cscope-list-entry-keymap "s" 'cscope-find-this-symbol)
+ (define-key cscope-list-entry-keymap "d" 'cscope-find-this-symbol)
+ (define-key cscope-list-entry-keymap "g" 'cscope-find-global-definition)
+ (define-key cscope-list-entry-keymap "G"
+ 'cscope-find-global-definition-no-prompting)
+ (define-key cscope-list-entry-keymap "c" 'cscope-find-functions-calling-this-function)
+ (define-key cscope-list-entry-keymap "C" 'cscope-find-called-functions)
+ (define-key cscope-list-entry-keymap "t" 'cscope-find-this-text-string)
+ (define-key cscope-list-entry-keymap "e" 'cscope-find-egrep-pattern)
+ (define-key cscope-list-entry-keymap "f" 'cscope-find-this-file)
+ (define-key cscope-list-entry-keymap "i" 'cscope-find-files-including-file)
+ ;; --- (The '---' indicates that this line corresponds to a menu separator.)
+ (define-key cscope-list-entry-keymap "n" 'cscope-next-symbol)
+ (define-key cscope-list-entry-keymap "N" 'cscope-next-file)
+ (define-key cscope-list-entry-keymap "p" 'cscope-prev-symbol)
+ (define-key cscope-list-entry-keymap "P" 'cscope-prev-file)
+ (define-key cscope-list-entry-keymap "u" 'cscope-pop-mark)
+ ;; ---
+ (define-key cscope-list-entry-keymap "a" 'cscope-set-initial-directory)
+ (define-key cscope-list-entry-keymap "A" 'cscope-unset-initial-directory)
+ ;; ---
+ (define-key cscope-list-entry-keymap "L" 'cscope-create-list-of-files-to-index)
+ (define-key cscope-list-entry-keymap "I" 'cscope-index-files)
+ (define-key cscope-list-entry-keymap "E" 'cscope-edit-list-of-files-to-index)
+ (define-key cscope-list-entry-keymap "W" 'cscope-tell-user-about-directory)
+ (define-key cscope-list-entry-keymap "S" 'cscope-tell-user-about-directory)
+ (define-key cscope-list-entry-keymap "T" 'cscope-tell-user-about-directory)
+ (define-key cscope-list-entry-keymap "D" 'cscope-dired-directory)
+ ;; The previous line corresponds to be end of the "Cscope" menu.
+ )
+
+
+(defvar cscope-list-entry-hook nil
+ "*Hook run after cscope-list-entry-mode entered.")
+
+
+(defun cscope-list-entry-mode ()
+ "Major mode for jumping/showing entry from the list in the *cscope* buffer.
+
+\\{cscope-list-entry-keymap}"
+ (use-local-map cscope-list-entry-keymap)
+ (setq buffer-read-only t
+ mode-name "cscope"
+ major-mode 'cscope-list-entry-mode
+ overlay-arrow-string cscope-overlay-arrow-string)
+ (or overlay-arrow-position
+ (setq overlay-arrow-position (make-marker)))
+ (run-hooks 'cscope-list-entry-hook))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar cscope-output-buffer-name "*cscope*"
+ "The name of the cscope output buffer.")
+
+
+(defvar cscope-info-buffer-name "*cscope-info*"
+ "The name of the cscope information buffer.")
+
+
+(defvar cscope-process nil
+ "The current cscope process.")
+(make-variable-buffer-local 'cscope-process)
+
+
+(defvar cscope-process-output nil
+ "A buffer for holding partial cscope process output.")
+(make-variable-buffer-local 'cscope-process-output)
+
+
+(defvar cscope-command-args nil
+ "Internal variable for holding major command args to pass to cscope.")
+(make-variable-buffer-local 'cscope-command-args)
+
+
+(defvar cscope-start-directory nil
+ "Internal variable used to save the initial start directory.
+The results buffer gets reset to this directory when a search has
+completely finished.")
+(make-variable-buffer-local 'cscope-start-directory)
+
+
+(defvar cscope-search-list nil
+ "A list of (DIR . FLAGS) entries.
+This is a list of database directories to search. Each entry in the list
+is a (DIR . FLAGS) cell. DIR is the directory to search, and FLAGS are the
+flags to pass to cscope when using this database directory. FLAGS can be
+nil (meaning, \"no flags\").")
+(make-variable-buffer-local 'cscope-search-list)
+
+
+(defvar cscope-searched-dirs nil
+ "The list of database directories already searched.")
+(make-variable-buffer-local 'cscope-searched-dirs)
+
+
+(defvar cscope-filter-func nil
+ "Internal variable for holding the filter function to use (if any) when
+searching.")
+(make-variable-buffer-local 'cscope-filter-func)
+
+
+(defvar cscope-sentinel-func nil
+ "Internal variable for holding the sentinel function to use (if any) when
+searching.")
+(make-variable-buffer-local 'cscope-filter-func)
+
+
+(defvar cscope-last-file nil
+ "The file referenced by the last line of cscope process output.")
+(make-variable-buffer-local 'cscope-last-file)
+
+
+(defvar cscope-start-time nil
+ "The search start time, in seconds.")
+(make-variable-buffer-local 'cscope-start-time)
+
+
+(defvar cscope-first-match nil
+ "The first match result output by cscope.")
+(make-variable-buffer-local 'cscope-first-match)
+
+
+(defvar cscope-first-match-point nil
+ "Buffer location of the first match.")
+(make-variable-buffer-local 'cscope-first-match-point)
+
+
+(defvar cscope-item-start nil
+ "The point location of the start of a search's output, before header info.")
+(make-variable-buffer-local 'cscope-output-start)
+
+
+(defvar cscope-output-start nil
+ "The point location of the start of a search's output.")
+(make-variable-buffer-local 'cscope-output-start)
+
+
+(defvar cscope-matched-multiple nil
+ "Non-nil if cscope output multiple matches.")
+(make-variable-buffer-local 'cscope-matched-multiple)
+
+
+(defvar cscope-stop-at-first-match-dir-meta nil
+ "")
+(make-variable-buffer-local 'cscope-stop-at-first-match-dir-meta)
+
+
+(defvar cscope-symbol nil
+ "The last symbol searched for.")
+
+
+(defvar cscope-adjust t
+ "True if the symbol searched for (cscope-symbol) should be on
+the line specified by the cscope database. In such cases the point will be
+adjusted if need be (fuzzy matching).")
+
+
+(defvar cscope-adjust-range 1000
+ "How far the point should be adjusted if the symbol is not on the line
+specified by the cscope database.")
+
+
+(defvar cscope-marker nil
+ "The location from which cscope was invoked.")
+
+
+(defvar cscope-marker-window nil
+ "The window which should contain cscope-marker. This is the window from
+which cscope-marker is set when searches are launched from the *cscope*
+buffer.")
+
+
+(defvar cscope-marker-ring-length 16
+ "Length of the cscope marker ring.")
+
+
+(defvar cscope-marker-ring (make-ring cscope-marker-ring-length)
+ "Ring of markers which are locations from which cscope was invoked.")
+
+
+(defvar cscope-initial-directory nil
+ "When set the directory in which searches for the cscope database
+directory should begin.")
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar cscope:map nil
+ "The cscope keymap.")
+(if cscope:map
+ nil
+ (setq cscope:map (make-sparse-keymap))
+ ;; The following line corresponds to be beginning of the "Cscope" menu.
+ (define-key cscope:map "\C-css" 'cscope-find-this-symbol)
+ (define-key cscope:map "\C-csd" 'cscope-find-global-definition)
+ (define-key cscope:map "\C-csg" 'cscope-find-global-definition)
+ (define-key cscope:map "\C-csG" 'cscope-find-global-definition-no-prompting)
+ (define-key cscope:map "\C-csc" 'cscope-find-functions-calling-this-function)
+ (define-key cscope:map "\C-csC" 'cscope-find-called-functions)
+ (define-key cscope:map "\C-cst" 'cscope-find-this-text-string)
+ (define-key cscope:map "\C-cse" 'cscope-find-egrep-pattern)
+ (define-key cscope:map "\C-csf" 'cscope-find-this-file)
+ (define-key cscope:map "\C-csi" 'cscope-find-files-including-file)
+ ;; --- (The '---' indicates that this line corresponds to a menu separator.)
+ (define-key cscope:map "\C-csb" 'cscope-display-buffer)
+ (define-key cscope:map "\C-csB" 'cscope-display-buffer-toggle)
+ (define-key cscope:map "\C-csn" 'cscope-next-symbol)
+ (define-key cscope:map "\C-csN" 'cscope-next-file)
+ (define-key cscope:map "\C-csp" 'cscope-prev-symbol)
+ (define-key cscope:map "\C-csP" 'cscope-prev-file)
+ (define-key cscope:map "\C-csu" 'cscope-pop-mark)
+ ;; ---
+ (define-key cscope:map "\C-csa" 'cscope-set-initial-directory)
+ (define-key cscope:map "\C-csA" 'cscope-unset-initial-directory)
+ ;; ---
+ (define-key cscope:map "\C-csL" 'cscope-create-list-of-files-to-index)
+ (define-key cscope:map "\C-csI" 'cscope-index-files)
+ (define-key cscope:map "\C-csE" 'cscope-edit-list-of-files-to-index)
+ (define-key cscope:map "\C-csW" 'cscope-tell-user-about-directory)
+ (define-key cscope:map "\C-csS" 'cscope-tell-user-about-directory)
+ (define-key cscope:map "\C-csT" 'cscope-tell-user-about-directory)
+ (define-key cscope:map "\C-csD" 'cscope-dired-directory))
+ ;; The previous line corresponds to be end of the "Cscope" menu.
+
+(easy-menu-define cscope:menu
+ (list cscope:map cscope-list-entry-keymap)
+ "cscope menu"
+ '("Cscope"
+ [ "Find symbol" cscope-find-this-symbol t ]
+ [ "Find global definition" cscope-find-global-definition t ]
+ [ "Find global definition no prompting"
+ cscope-find-global-definition-no-prompting t ]
+ [ "Find functions calling a function"
+ cscope-find-functions-calling-this-function t ]
+ [ "Find called functions" cscope-find-called-functions t ]
+ [ "Find text string" cscope-find-this-text-string t ]
+ [ "Find egrep pattern" cscope-find-egrep-pattern t ]
+ [ "Find a file" cscope-find-this-file t ]
+ [ "Find files #including a file"
+ cscope-find-files-including-file t ]
+ "-----------"
+ [ "Display *cscope* buffer" cscope-display-buffer t ]
+ [ "Auto display *cscope* buffer toggle"
+ cscope-display-buffer-toggle t ]
+ [ "Next symbol" cscope-next-symbol t ]
+ [ "Next file" cscope-next-file t ]
+ [ "Previous symbol" cscope-prev-symbol t ]
+ [ "Previous file" cscope-prev-file t ]
+ [ "Pop mark" cscope-pop-mark t ]
+ "-----------"
+ ( "Cscope Database"
+ [ "Set initial directory"
+ cscope-set-initial-directory t ]
+ [ "Unset initial directory"
+ cscope-unset-initial-directory t ]
+ "-----------"
+ [ "Create list of files to index"
+ cscope-create-list-of-files-to-index t ]
+ [ "Create list and index"
+ cscope-index-files t ]
+ [ "Edit list of files to index"
+ cscope-edit-list-of-files-to-index t ]
+ [ "Locate this buffer's cscope directory"
+ cscope-tell-user-about-directory t ]
+ [ "Dired this buffer's cscope directory"
+ cscope-dired-directory t ]
+ )
+ "-----------"
+ ( "Options"
+ [ "Auto edit single match"
+ (setq cscope-edit-single-match
+ (not cscope-edit-single-match))
+ :style toggle :selected cscope-edit-single-match ]
+ [ "Auto display *cscope* buffer"
+ (setq cscope-display-cscope-buffer
+ (not cscope-display-cscope-buffer))
+ :style toggle :selected cscope-display-cscope-buffer ]
+ [ "Stop at first matching database"
+ (setq cscope-stop-at-first-match-dir
+ (not cscope-stop-at-first-match-dir))
+ :style toggle
+ :selected cscope-stop-at-first-match-dir ]
+ [ "Never update cscope database"
+ (setq cscope-do-not-update-database
+ (not cscope-do-not-update-database))
+ :style toggle :selected cscope-do-not-update-database ]
+ [ "Index recursively"
+ (setq cscope-index-recursively
+ (not cscope-index-recursively))
+ :style toggle :selected cscope-index-recursively ]
+ [ "Suppress empty matches"
+ (setq cscope-suppress-empty-matches
+ (not cscope-suppress-empty-matches))
+ :style toggle :selected cscope-suppress-empty-matches ]
+ [ "Use relative paths"
+ (setq cscope-use-relative-paths
+ (not cscope-use-relative-paths))
+ :style toggle :selected cscope-use-relative-paths ]
+ [ "No mouse prompts" (setq cscope-no-mouse-prompts
+ (not cscope-no-mouse-prompts))
+ :style toggle :selected cscope-no-mouse-prompts ]
+ )
+ ))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Internal functions and variables
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar cscope-common-text-plist
+ (let (plist)
+ (setq plist (plist-put plist 'mouse-face 'cscope-mouse-face))
+ plist)
+ "List of common text properties to be added to the entry line.")
+
+
+(defun cscope-insert-with-text-properties (text filename &optional line-number)
+ "Insert an entry with given TEXT, add entry attributes as text properties.
+The text properties to be added:
+- common property: mouse-face,
+- properties are used to open target file and its location: cscope-file,
+ cscope-line-number"
+ (let ((plist cscope-common-text-plist)
+ beg end)
+ (setq beg (point))
+ (insert text)
+ (setq end (point)
+ plist (plist-put plist 'cscope-file filename))
+ (if line-number
+ (progn
+ (if (stringp line-number)
+ (setq line-number (string-to-number line-number)))
+ (setq plist (plist-put plist 'cscope-line-number line-number))
+ ))
+ (add-text-properties beg end plist)
+ ))
+
+
+(if cscope-running-in-xemacs
+ (progn
+ (defalias 'cscope-event-window 'event-window)
+ (defalias 'cscope-event-point 'event-point)
+ (defalias 'cscope-recenter 'recenter)
+ )
+ (defun cscope-event-window (event)
+ "Return the window at which the mouse EVENT occurred."
+ (posn-window (event-start event)))
+ (defun cscope-event-point (event)
+ "Return the point at which the mouse EVENT occurred."
+ (posn-point (event-start event)))
+ (defun cscope-recenter (&optional n window)
+ "Center point in WINDOW and redisplay frame. With N, put point on line N."
+ (save-selected-window
+ (if (windowp window)
+ (select-window window))
+ (recenter n)))
+ )
+
+
+(defun cscope-show-entry-internal (file line-number
+ &optional save-mark-p window arrow-p)
+ "Display the buffer corresponding to FILE and LINE-NUMBER
+in some window. If optional argument WINDOW is given,
+display the buffer in that WINDOW instead. The window is
+not selected. Save point on mark ring before goto
+LINE-NUMBER if optional argument SAVE-MARK-P is non-nil.
+Put `overlay-arrow-string' if arrow-p is non-nil.
+Returns the window displaying BUFFER."
+ (let (buffer old-pos old-point new-point forward-point backward-point
+ line-end line-length)
+ (if (and (stringp file)
+ (integerp line-number))
+ (progn
+ (unless (file-readable-p file)
+ (error "%s is not readable or exists" file))
+ (setq buffer (find-file-noselect file))
+ (if (windowp window)
+ (set-window-buffer window buffer)
+ (setq window (display-buffer buffer)))
+ (set-buffer buffer)
+ (if (> line-number 0)
+ (progn
+ (setq old-pos (point))
+ (goto-line line-number)
+ (setq old-point (point))
+ (if (and cscope-adjust cscope-adjust-range)
+ (progn
+ ;; Calculate the length of the line specified by cscope.
+ (end-of-line)
+ (setq line-end (point))
+ (goto-char old-point)
+ (setq line-length (- line-end old-point))
+
+ ;; Search forward and backward for the pattern.
+ (setq forward-point (search-forward
+ cscope-symbol
+ (+ old-point
+ cscope-adjust-range) t))
+ (goto-char old-point)
+ (setq backward-point (search-backward
+ cscope-symbol
+ (- old-point
+ cscope-adjust-range) t))
+ (if forward-point
+ (progn
+ (if backward-point
+ (setq new-point
+ ;; Use whichever of forward-point or
+ ;; backward-point is closest to old-point.
+ ;; Give forward-point a line-length advantage
+ ;; so that if the symbol is on the current
+ ;; line the current line is chosen.
+ (if (<= (- (- forward-point line-length)
+ old-point)
+ (- old-point backward-point))
+ forward-point
+ backward-point))
+ (setq new-point forward-point)))
+ (if backward-point
+ (setq new-point backward-point)
+ (setq new-point old-point)))
+ (goto-char new-point)
+ (beginning-of-line)
+ (setq new-point (point)))
+ (setq new-point old-point))
+ (set-window-point window new-point)
+ (if (and cscope-allow-arrow-overlays arrow-p)
+ (set-marker overlay-arrow-position (point))
+ (set-marker overlay-arrow-position nil))
+ (or (not save-mark-p)
+ (= old-pos (point))
+ (push-mark old-pos))
+ ))
+
+ (if cscope-marker
+ (progn ;; The search was successful. Save the marker so it
+ ;; can be returned to by cscope-pop-mark.
+ (ring-insert cscope-marker-ring cscope-marker)
+ ;; Unset cscope-marker so that moving between matches
+ ;; (cscope-next-symbol, etc.) does not fill
+ ;; cscope-marker-ring.
+ (setq cscope-marker nil)))
+ (setq cscope-marker-window window)
+ )
+ (message "No entry found at point."))
+ )
+ window)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; functions in *cscope* buffer which lists the search results
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun cscope-select-entry-other-window ()
+ "Display the entry at point in other window, select the window.
+Push current point on mark ring and select the entry window."
+ (interactive)
+ (let ((file (get-text-property (point) 'cscope-file))
+ (line-number (get-text-property (point) 'cscope-line-number))
+ window)
+ (setq window (cscope-show-entry-internal file line-number t))
+ (if (windowp window)
+ (select-window window))
+ ))
+
+
+(defun cscope-select-entry-one-window ()
+ "Display the entry at point in one window, select the window."
+ (interactive)
+ (let ((file (get-text-property (point) 'cscope-file))
+ (line-number (get-text-property (point) 'cscope-line-number))
+ window)
+ (setq window (cscope-show-entry-internal file line-number t))
+ (if (windowp window)
+ (progn
+ (select-window window)
+ (sit-for 0) ;; Redisplay hack to allow delete-other-windows
+ ;; to continue displaying the correct location.
+ (delete-other-windows window)
+ ))
+ ))
+
+
+(defun cscope-select-entry-specified-window (window)
+ "Display the entry at point in a specified window, select the window."
+ (interactive)
+ (let ((file (get-text-property (point) 'cscope-file))
+ (line-number (get-text-property (point) 'cscope-line-number)))
+ (setq window (cscope-show-entry-internal file line-number t window))
+ (if (windowp window)
+ (select-window window))
+ ))
+
+
+(defun cscope-mouse-select-entry-other-window (event)
+ "Display the entry over which the mouse event occurred, select the window."
+ (interactive "e")
+ (let ((ep (cscope-event-point event))
+ (win (cscope-event-window event))
+ buffer file line-number window)
+ (if ep
+ (progn
+ (setq buffer (window-buffer win)
+ file (get-text-property ep 'cscope-file buffer)
+ line-number (get-text-property ep 'cscope-line-number buffer))
+ (select-window win)
+ (setq window (cscope-show-entry-internal file line-number t))
+ (if (windowp window)
+ (select-window window))
+ )
+ (message "No entry found at point.")
+ )
+ ))
+
+
+(defun cscope-show-entry-other-window ()
+ "Display the entry at point in other window.
+Point is not saved on mark ring."
+ (interactive)
+ (let ((file (get-text-property (point) 'cscope-file))
+ (line-number (get-text-property (point) 'cscope-line-number)))
+ (cscope-show-entry-internal file line-number nil nil t)
+ ))
+
+
+(defun cscope-buffer-search (do-symbol do-next)
+ "The body of the following four functions."
+ (let* (line-number old-point point
+ (search-file (not do-symbol))
+ (search-prev (not do-next))
+ (direction (if do-next 1 -1))
+ (old-buffer (current-buffer))
+ (old-buffer-window (get-buffer-window old-buffer))
+ (buffer (get-buffer cscope-output-buffer-name))
+ (buffer-window (get-buffer-window (or buffer (error "The *cscope* buffer does not exist yet"))))
+ )
+ (set-buffer buffer)
+ (setq old-point (point))
+ (forward-line direction)
+ (setq point (point))
+ (setq line-number (get-text-property point 'cscope-line-number))
+ (while (or (not line-number)
+ (or (and do-symbol (= line-number -1))
+ (and search-file (/= line-number -1))))
+ (forward-line direction)
+ (setq point (point))
+ (if (or (and do-next (>= point (point-max)))
+ (and search-prev (<= point (point-min))))
+ (progn
+ (goto-char old-point)
+ (error "The %s of the *cscope* buffer has been reached"
+ (if do-next "end" "beginning"))))
+ (setq line-number (get-text-property point 'cscope-line-number)))
+ (if (eq old-buffer buffer) ;; In the *cscope* buffer.
+ (cscope-show-entry-other-window)
+ (cscope-select-entry-specified-window old-buffer-window) ;; else
+ (if (windowp buffer-window)
+ (set-window-point buffer-window point)))
+ (set-buffer old-buffer)
+ ))
+
+
+(defun cscope-display-buffer ()
+ "Display the *cscope* buffer."
+ (interactive)
+ (let ((buffer (get-buffer cscope-output-buffer-name)))
+ (if buffer
+ (pop-to-buffer buffer)
+ (error "The *cscope* buffer does not exist yet"))))
+
+
+(defun cscope-display-buffer-toggle ()
+ "Toggle cscope-display-cscope-buffer, which corresponds to
+\"Auto display *cscope* buffer\"."
+ (interactive)
+ (setq cscope-display-cscope-buffer (not cscope-display-cscope-buffer))
+ (message "The cscope-display-cscope-buffer variable is now %s."
+ (if cscope-display-cscope-buffer "set" "unset")))
+
+
+(defun cscope-next-symbol ()
+ "Move to the next symbol in the *cscope* buffer."
+ (interactive)
+ (cscope-buffer-search t t))
+
+
+(defun cscope-next-file ()
+ "Move to the next file in the *cscope* buffer."
+ (interactive)
+ (cscope-buffer-search nil t))
+
+
+(defun cscope-prev-symbol ()
+ "Move to the previous symbol in the *cscope* buffer."
+ (interactive)
+ (cscope-buffer-search t nil))
+
+
+(defun cscope-prev-file ()
+ "Move to the previous file in the *cscope* buffer."
+ (interactive)
+ (cscope-buffer-search nil nil))
+
+
+(defun cscope-pop-mark ()
+ "Pop back to where cscope was last invoked."
+ (interactive)
+
+ ;; This function is based on pop-tag-mark, which can be found in
+ ;; lisp/progmodes/etags.el.
+
+ (if (ring-empty-p cscope-marker-ring)
+ (error "There are no marked buffers in the cscope-marker-ring yet"))
+ (let* ( (marker (ring-remove cscope-marker-ring 0))
+ (old-buffer (current-buffer))
+ (marker-buffer (marker-buffer marker))
+ marker-window
+ (marker-point (marker-position marker))
+ (cscope-buffer (get-buffer cscope-output-buffer-name)) )
+
+ ;; After the following both cscope-marker-ring and cscope-marker will be
+ ;; in the state they were immediately after the last search. This way if
+ ;; the user now makes a selection in the previously generated *cscope*
+ ;; buffer things will behave the same way as if that selection had been
+ ;; made immediately after the last search.
+ (setq cscope-marker marker)
+
+ (if marker-buffer
+ (if (eq old-buffer cscope-buffer)
+ (progn ;; In the *cscope* buffer.
+ (set-buffer marker-buffer)
+ (setq marker-window (display-buffer marker-buffer))
+ (set-window-point marker-window marker-point)
+ (select-window marker-window))
+ (switch-to-buffer marker-buffer))
+ (error "The marked buffer has been deleted"))
+ (goto-char marker-point)
+ (set-buffer old-buffer)))
+
+
+(defun cscope-set-initial-directory (cs-id)
+ "Set the cscope-initial-directory variable. The
+cscope-initial-directory variable, when set, specifies the directory
+where searches for the cscope database directory should begin. This
+overrides the current directory, which would otherwise be used."
+ (interactive "DCscope Initial Directory: ")
+ (setq cscope-initial-directory cs-id))
+
+
+(defun cscope-unset-initial-directory ()
+ "Unset the cscope-initial-directory variable."
+ (interactive)
+ (setq cscope-initial-directory nil)
+ (message "The cscope-initial-directory variable is now unset."))
+
+
+(defun cscope-help ()
+ (interactive)
+ (message
+ (format "RET=%s, SPC=%s, o=%s, n=%s, p=%s, q=%s, h=%s"
+ "Select"
+ "Show"
+ "SelectOneWin"
+ "ShowNext"
+ "ShowPrev"
+ "Quit"
+ "Help")))
+
+
+(defun cscope-bury-buffer ()
+ "Clean up cscope, if necessary, and bury the buffer."
+ (interactive)
+ (let ()
+ (if overlay-arrow-position
+ (set-marker overlay-arrow-position nil))
+ (setq overlay-arrow-position nil
+ overlay-arrow-string nil)
+ (bury-buffer (get-buffer cscope-output-buffer-name))
+ ))
+
+
+(defun cscope-quit ()
+ (interactive)
+ (cscope-bury-buffer)
+ (kill-buffer cscope-output-buffer-name)
+ )
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun cscope-canonicalize-directory (dir)
+ (or dir
+ (setq dir default-directory))
+ (setq dir (file-name-as-directory
+ (expand-file-name (substitute-in-file-name dir))))
+ dir
+ )
+
+
+(defun cscope-search-directory-hierarchy (directory)
+ "Look for a cscope database in the directory hierarchy.
+Starting from DIRECTORY, look upwards for a cscope database."
+ (let (this-directory database-dir)
+ (catch 'done
+ (if (file-regular-p directory)
+ (throw 'done directory))
+ (setq directory (cscope-canonicalize-directory directory)
+ this-directory directory)
+ (while this-directory
+ (if (or (file-exists-p (concat this-directory cscope-database-file))
+ (file-exists-p (concat this-directory cscope-index-file)))
+ (progn
+ (setq database-dir this-directory)
+ (throw 'done database-dir)
+ ))
+ (if (string-match "^\\(/\\|[A-Za-z]:[\\/]\\)$" this-directory)
+ (throw 'done directory))
+ (setq this-directory (file-name-as-directory
+ (file-name-directory
+ (directory-file-name this-directory))))
+ ))
+ ))
+
+
+(defun cscope-find-info (top-directory)
+ "Locate a suitable cscope database directory.
+First, `cscope-database-regexps' is used to search for a suitable
+database directory. If a database location cannot be found using this
+variable, then the current directory is searched, then the parent,
+then the parent's parent, until a cscope database directory is found,
+or the root directory is reached. If the root directory is reached,
+the current directory will be used."
+ (let (info regexps dir-regexp this-directory)
+ (setq top-directory (cscope-canonicalize-directory
+ (or top-directory cscope-initial-directory)))
+ (catch 'done
+ ;; Try searching using `cscope-database-regexps' ...
+ (setq regexps cscope-database-regexps)
+ (while regexps
+ (setq dir-regexp (car (car regexps)))
+ (cond
+ ( (stringp dir-regexp)
+ (if (string-match dir-regexp top-directory)
+ (progn
+ (setq info (cdr (car regexps)))
+ (throw 'done t)
+ )) )
+ ( (and (symbolp dir-regexp) dir-regexp)
+ (progn
+ (setq info (cdr (car regexps)))
+ (throw 'done t)
+ ) ))
+ (setq regexps (cdr regexps))
+ )
+
+ ;; Try looking in the directory hierarchy ...
+ (if (setq this-directory
+ (cscope-search-directory-hierarchy top-directory))
+ (progn
+ (setq info (list (list this-directory)))
+ (throw 'done t)
+ ))
+
+ ;; Should we add any more places to look?
+
+ ) ;; end catch
+ (if (not info)
+ (setq info (list (list top-directory))))
+ info
+ ))
+
+
+(defun cscope-make-entry-line (func-name line-number line)
+ ;; The format of entry line:
+ ;; func-name[line-number]______line
+ ;; <- cscope-name-line-width ->
+ ;; `format' of Emacs doesn't have "*s" spec.
+ (let* ((fmt (format "%%%ds %%s" cscope-name-line-width))
+ (str (format fmt (format "%s[%s]" func-name line-number) line))
+ beg end)
+ (if cscope-use-face
+ (progn
+ (setq end (length func-name))
+ (put-text-property 0 end 'face 'cscope-function-face str)
+ (setq beg (1+ end)
+ end (+ beg (length line-number)))
+ (put-text-property beg end 'face 'cscope-line-number-face str)
+ (setq end (length str)
+ beg (- end (length line)))
+ (put-text-property beg end 'face 'cscope-line-face str)
+ ))
+ str))
+
+
+(defun cscope-process-filter (process output)
+ "Accept cscope process output and reformat it for human readability.
+Magic text properties are added to allow the user to select lines
+using the mouse."
+ (let ( (old-buffer (current-buffer)) )
+ (unwind-protect
+ (progn
+ (set-buffer (process-buffer process))
+ ;; Make buffer-read-only nil
+ (let (buffer-read-only line file function-name line-number moving)
+ (setq moving (= (point) (process-mark process)))
+ (save-excursion
+ (goto-char (process-mark process))
+ ;; Get the output thus far ...
+ (if cscope-process-output
+ (setq cscope-process-output (concat cscope-process-output
+ output))
+ (setq cscope-process-output output))
+ ;; Slice and dice it into lines.
+ ;; While there are whole lines left ...
+ (while (and cscope-process-output
+ (string-match "\\([^\n]+\n\\)\\(\\(.\\|\n\\)*\\)"
+ cscope-process-output))
+ (setq file nil
+ glimpse-stripped-directory nil
+ )
+ ;; Get a line
+ (setq line (substring cscope-process-output
+ (match-beginning 1) (match-end 1)))
+ (setq cscope-process-output (substring cscope-process-output
+ (match-beginning 2)
+ (match-end 2)))
+ (if (= (length cscope-process-output) 0)
+ (setq cscope-process-output nil))
+
+ ;; This should always match.
+ (if (string-match
+ "^\\([^ \t]+\\)[ \t]+\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\(.*\\)\n"
+ line)
+ (progn
+ (let (str)
+ (setq file (substring line (match-beginning 1)
+ (match-end 1))
+ function-name (substring line (match-beginning 2)
+ (match-end 2))
+ line-number (substring line (match-beginning 3)
+ (match-end 3))
+ line (substring line (match-beginning 4)
+ (match-end 4))
+ )
+ ;; If the current file is not the same as the previous
+ ;; one ...
+ (if (not (and cscope-last-file
+ (string= file cscope-last-file)))
+ (progn
+ ;; The current file is different.
+
+ ;; Insert a separating blank line if
+ ;; necessary.
+ (if cscope-last-file (insert "\n"))
+ ;; Insert the file name
+ (setq str (concat "*** " file ":"))
+ (if cscope-use-face
+ (put-text-property 0 (length str)
+ 'face 'cscope-file-face
+ str))
+ (cscope-insert-with-text-properties
+ str
+ (expand-file-name file)
+ ;; Yes, -1 is intentional
+ -1)
+ (insert "\n")
+ ))
+ (if (not cscope-first-match)
+ (setq cscope-first-match-point (point)))
+ ;; ... and insert the line, with the
+ ;; appropriate indentation.
+ (cscope-insert-with-text-properties
+ (cscope-make-entry-line function-name
+ line-number
+ line)
+ (expand-file-name file)
+ line-number)
+ (insert "\n")
+ (setq cscope-last-file file)
+ (if cscope-first-match
+ (setq cscope-matched-multiple t)
+ (setq cscope-first-match
+ (cons (expand-file-name file)
+ (string-to-number line-number))))
+ ))
+ (insert line "\n")
+ ))
+ (set-marker (process-mark process) (point))
+ )
+ (if moving
+ (goto-char (process-mark process)))
+ (set-buffer-modified-p nil)
+ ))
+ (set-buffer old-buffer))
+ ))
+
+
+(defun cscope-process-sentinel (process event)
+ "Sentinel for when the cscope process dies."
+ (let* ( (buffer (process-buffer process)) window update-window
+ (done t) (old-buffer (current-buffer))
+ (old-buffer-window (get-buffer-window old-buffer)) )
+ (set-buffer buffer)
+ (save-window-excursion
+ (save-excursion
+ (if (or (and (setq window (get-buffer-window buffer))
+ (= (window-point window) (point-max)))
+ (= (point) (point-max)))
+ (progn
+ (setq update-window t)
+ ))
+ (delete-process process)
+ (let (buffer-read-only continue)
+ (goto-char (point-max))
+ (if (and cscope-suppress-empty-matches
+ (= cscope-output-start (point)))
+ (delete-region cscope-item-start (point-max))
+ (progn
+ (if (not cscope-start-directory)
+ (setq cscope-start-directory default-directory))
+ (insert cscope-separator-line)
+ ))
+ (setq continue
+ (and cscope-search-list
+ (not (and cscope-first-match
+ cscope-stop-at-first-match-dir
+ (not cscope-stop-at-first-match-dir-meta)))))
+ (if continue
+ (setq continue (cscope-search-one-database)))
+ (if continue
+ (progn
+ (setq done nil)
+ )
+ (progn
+ (insert "\nSearch complete.")
+ (if cscope-display-times
+ (let ( (times (current-time)) cscope-stop elapsed-time )
+ (setq cscope-stop (+ (* (car times) 65536.0)
+ (car (cdr times))
+ (* (car (cdr (cdr times))) 1.0E-6)))
+ (setq elapsed-time (- cscope-stop cscope-start-time))
+ (insert (format " Search time = %.2f seconds."
+ elapsed-time))
+ ))
+ (setq cscope-process nil)
+ (if cscope-running-in-xemacs
+ (setq modeline-process ": Search complete"))
+ (if cscope-start-directory
+ (setq default-directory cscope-start-directory))
+ (if (not cscope-first-match)
+ (message "No matches were found."))
+ )
+ ))
+ (set-buffer-modified-p nil)
+ ))
+ (if (and done cscope-first-match-point update-window)
+ (if window
+ (set-window-point window cscope-first-match-point)
+ (goto-char cscope-first-match-point))
+ )
+ (cond
+ ( (not done) ;; we're not done -- do nothing for now
+ (if update-window
+ (if window
+ (set-window-point window (point-max))
+ (goto-char (point-max))))
+ )
+ ( cscope-first-match
+ (if cscope-display-cscope-buffer
+ (if (and cscope-edit-single-match (not cscope-matched-multiple))
+ (cscope-show-entry-internal(car cscope-first-match)
+ (cdr cscope-first-match) t))
+ (cscope-select-entry-specified-window old-buffer-window))
+ )
+ )
+ (if (and done (eq old-buffer buffer) cscope-first-match)
+ (cscope-help))
+ (set-buffer old-buffer)
+ ))
+
+
+(defun cscope-search-one-database ()
+ "Pop a database entry from cscope-search-list and do a search there."
+ (let ( next-item options cscope-directory database-file outbuf done
+ base-database-file-name)
+ (setq outbuf (get-buffer-create cscope-output-buffer-name))
+ (save-excursion
+ (catch 'finished
+ (set-buffer outbuf)
+ (setq options '("-L"))
+ (while (and (not done) cscope-search-list)
+ (setq next-item (car cscope-search-list)
+ cscope-search-list (cdr cscope-search-list)
+ base-database-file-name cscope-database-file
+ )
+ (if (listp next-item)
+ (progn
+ (setq cscope-directory (car next-item))
+ (if (not (stringp cscope-directory))
+ (setq cscope-directory
+ (cscope-search-directory-hierarchy
+ default-directory)))
+ (if (file-regular-p cscope-directory)
+ (progn
+ ;; Handle the case where `cscope-directory' is really
+ ;; a full path name to a cscope database.
+ (setq base-database-file-name
+ (file-name-nondirectory cscope-directory)
+ cscope-directory
+ (file-name-directory cscope-directory))
+ ))
+ (setq cscope-directory
+ (file-name-as-directory cscope-directory))
+ (if (not (member cscope-directory cscope-searched-dirs))
+ (progn
+ (setq cscope-searched-dirs (cons cscope-directory
+ cscope-searched-dirs)
+ done t)
+ ))
+ )
+ (progn
+ (if (and cscope-first-match
+ cscope-stop-at-first-match-dir
+ cscope-stop-at-first-match-dir-meta)
+ (throw 'finished nil))
+ ))
+ )
+ (if (not done)
+ (throw 'finished nil))
+ (if (car (cdr next-item))
+ (let (newopts)
+ (setq newopts (car (cdr next-item)))
+ (if (not (listp newopts))
+ (error (format "Cscope options must be a list: %s" newopts)))
+ (setq options (append options newopts))
+ ))
+ (if cscope-command-args
+ (setq options (append options cscope-command-args)))
+ (setq database-file (concat cscope-directory base-database-file-name)
+ cscope-searched-dirs (cons cscope-directory
+ cscope-searched-dirs)
+ )
+
+ ;; The database file and the directory containing the database file
+ ;; must both be writable.
+ (if (or (not (file-writable-p database-file))
+ (not (file-writable-p (file-name-directory database-file)))
+ cscope-do-not-update-database)
+ (setq options (cons "-d" options)))
+
+ (goto-char (point-max))
+ (setq cscope-item-start (point))
+ (if (string= base-database-file-name cscope-database-file)
+ (insert "\nDatabase directory: " cscope-directory "\n"
+ cscope-separator-line)
+ (insert "\nDatabase directory/file: "
+ cscope-directory base-database-file-name "\n"
+ cscope-separator-line))
+ ;; Add the correct database file to search
+ (setq options (cons base-database-file-name options))
+ (setq options (cons "-f" options))
+ (setq cscope-output-start (point))
+ (setq default-directory cscope-directory)
+ (if cscope-filter-func
+ (progn
+ (setq cscope-process-output nil
+ cscope-last-file nil
+ )
+ (setq cscope-process
+ (apply 'start-process "cscope" outbuf
+ cscope-program options))
+ (set-process-filter cscope-process cscope-filter-func)
+ (set-process-sentinel cscope-process cscope-sentinel-func)
+ (set-marker (process-mark cscope-process) (point))
+ (process-kill-without-query cscope-process)
+ (if cscope-running-in-xemacs
+ (setq modeline-process ": Searching ..."))
+ (setq buffer-read-only t)
+ )
+ (apply 'call-process cscope-program nil outbuf t options)
+ )
+ t
+ ))
+ ))
+
+
+(defun cscope-call (msg args &optional directory filter-func sentinel-func)
+ "Generic function to call to process cscope requests.
+ARGS is a list of command-line arguments to pass to the cscope
+process. DIRECTORY is the current working directory to use (generally,
+the directory in which the cscope database is located, but not
+necessarily), if different that the current one. FILTER-FUNC and
+SENTINEL-FUNC are optional process filter and sentinel, respectively."
+ (let ( (outbuf (get-buffer-create cscope-output-buffer-name))
+ (old-buffer (current-buffer)) )
+ (if cscope-process
+ (error "A cscope search is still in progress -- only one at a time is allowed"))
+ (setq directory (cscope-canonicalize-directory
+ (or cscope-initial-directory directory)))
+ (if (eq outbuf old-buffer) ;; In the *cscope* buffer.
+ (if cscope-marker-window
+ (progn
+ ;; Assume that cscope-marker-window is the window, from the
+ ;; users perspective, from which the search was launched and the
+ ;; window that should be returned to upon cscope-pop-mark.
+ (set-buffer (window-buffer cscope-marker-window))
+ (setq cscope-marker (point-marker))
+ (set-buffer old-buffer)))
+ (progn ;; Not in the *cscope buffer.
+ ;; Set the cscope-marker-window to whichever window this search
+ ;; was launched from.
+ (setq cscope-marker-window (get-buffer-window old-buffer))
+ (setq cscope-marker (point-marker))))
+ (save-excursion
+ (set-buffer outbuf)
+ (if cscope-display-times
+ (let ( (times (current-time)) )
+ (setq cscope-start-time (+ (* (car times) 65536.0) (car (cdr times))
+ (* (car (cdr (cdr times))) 1.0E-6)))))
+ (setq default-directory directory
+ cscope-start-directory nil
+ cscope-search-list (cscope-find-info directory)
+ cscope-searched-dirs nil
+ cscope-command-args args
+ cscope-filter-func filter-func
+ cscope-sentinel-func sentinel-func
+ cscope-first-match nil
+ cscope-first-match-point nil
+ cscope-stop-at-first-match-dir-meta (memq t cscope-search-list)
+ cscope-matched-multiple nil
+ buffer-read-only nil)
+ (buffer-disable-undo)
+ (erase-buffer)
+ (setq truncate-lines cscope-truncate-lines)
+ (if msg
+ (insert msg "\n"))
+ (cscope-search-one-database)
+ )
+ (if cscope-display-cscope-buffer
+ (progn
+ (pop-to-buffer outbuf)
+ (cscope-help))
+ (set-buffer outbuf))
+ (goto-char (point-max))
+ (cscope-list-entry-mode)
+ ))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar cscope-unix-index-process-buffer-name "*cscope-indexing-buffer*"
+ "The name of the buffer to use for displaying indexing status/progress.")
+
+
+(defvar cscope-unix-index-process-buffer nil
+ "The buffer to use for displaying indexing status/progress.")
+
+
+(defvar cscope-unix-index-process nil
+ "The current indexing process.")
+
+
+(defun cscope-unix-index-files-sentinel (process event)
+ "Simple sentinel to print a message saying that indexing is finished."
+ (let (buffer)
+ (save-window-excursion
+ (save-excursion
+ (setq buffer (process-buffer process))
+ (set-buffer buffer)
+ (goto-char (point-max))
+ (insert cscope-separator-line "\nIndexing finished\n")
+ (delete-process process)
+ (setq cscope-unix-index-process nil)
+ (set-buffer-modified-p nil)
+ ))
+ ))
+
+
+(defun cscope-unix-index-files-internal (top-directory header-text args)
+ "Core function to call the indexing script."
+ (let ()
+ (save-excursion
+ (setq top-directory (cscope-canonicalize-directory top-directory))
+ (setq cscope-unix-index-process-buffer
+ (get-buffer-create cscope-unix-index-process-buffer-name))
+ (display-buffer cscope-unix-index-process-buffer)
+ (set-buffer cscope-unix-index-process-buffer)
+ (setq buffer-read-only nil)
+ (setq default-directory top-directory)
+ (buffer-disable-undo)
+ (erase-buffer)
+ (if header-text
+ (insert header-text))
+ (setq args (append args
+ (list "-v"
+ "-i" cscope-index-file
+ "-f" cscope-database-file
+ (if cscope-use-relative-paths
+ "." top-directory))))
+ (if cscope-index-recursively
+ (setq args (cons "-r" args)))
+ (setq cscope-unix-index-process
+ (apply 'start-process "cscope-indexer"
+ cscope-unix-index-process-buffer
+ cscope-indexing-script args))
+ (set-process-sentinel cscope-unix-index-process
+ 'cscope-unix-index-files-sentinel)
+ (process-kill-without-query cscope-unix-index-process)
+ )
+ ))
+
+
+(defun cscope-index-files (top-directory)
+ "Index files in a directory.
+This function creates a list of files to index, and then indexes
+the listed files.
+The variable, \"cscope-index-recursively\", controls whether or not
+subdirectories are indexed."
+ (interactive "DIndex files in directory: ")
+ (let ()
+ (cscope-unix-index-files-internal
+ top-directory
+ (format "Creating cscope index `%s' in:\n\t%s\n\n%s"
+ cscope-database-file top-directory cscope-separator-line)
+ nil)
+ ))
+
+
+(defun cscope-create-list-of-files-to-index (top-directory)
+ "Create a list of files to index.
+The variable, \"cscope-index-recursively\", controls whether or not
+subdirectories are indexed."
+ (interactive "DCreate file list in directory: ")
+ (let ()
+ (cscope-unix-index-files-internal
+ top-directory
+ (format "Creating cscope file list `%s' in:\n\t%s\n\n"
+ cscope-index-file top-directory)
+ '("-l"))
+ ))
+
+
+(defun cscope-edit-list-of-files-to-index ()
+ "Search for and edit the list of files to index.
+If this functions causes a new file to be edited, that means that a
+cscope.out file was found without a corresponding cscope.files file."
+ (interactive)
+ (let (info directory file)
+ (setq info (cscope-find-info nil))
+ (if (/= (length info) 1)
+ (error "There is no unique cscope database directory!"))
+ (setq directory (car (car info)))
+ (if (not (stringp directory))
+ (setq directory
+ (cscope-search-directory-hierarchy default-directory)))
+ (setq file (concat (file-name-as-directory directory) cscope-index-file))
+ (find-file file)
+ (message (concat "File: " file))
+ ))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun cscope-tell-user-about-directory ()
+ "Display the name of the directory containing the cscope database."
+ (interactive)
+ (let (info directory)
+ (setq info (cscope-find-info nil))
+ (if (= (length info) 1)
+ (progn
+ (setq directory (car (car info)))
+ (message (concat "Cscope directory: " directory))
+ )
+ (let ( (outbuf (get-buffer-create cscope-info-buffer-name)) )
+ (display-buffer outbuf)
+ (save-excursion
+ (set-buffer outbuf)
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert "Cscope search directories:\n")
+ (while info
+ (if (listp (car info))
+ (progn
+ (setq directory (car (car info)))
+ (if (not (stringp directory))
+ (setq directory
+ (cscope-search-directory-hierarchy
+ default-directory)))
+ (insert "\t" directory "\n")
+ ))
+ (setq info (cdr info))
+ )
+ )
+ ))
+ ))
+
+
+(defun cscope-dired-directory ()
+ "Run dired upon the cscope database directory.
+If possible, the cursor is moved to the name of the cscope database
+file."
+ (interactive)
+ (let (info directory buffer p1 p2 pos)
+ (setq info (cscope-find-info nil))
+ (if (/= (length info) 1)
+ (error "There is no unique cscope database directory!"))
+ (setq directory (car (car info)))
+ (if (not (stringp directory))
+ (setq directory
+ (cscope-search-directory-hierarchy default-directory)))
+ (setq buffer (dired-noselect directory nil))
+ (switch-to-buffer buffer)
+ (set-buffer buffer)
+ (save-excursion
+ (goto-char (point-min))
+ (setq p1 (search-forward cscope-index-file nil t))
+ (if p1
+ (setq p1 (- p1 (length cscope-index-file))))
+ )
+ (save-excursion
+ (goto-char (point-min))
+ (setq p2 (search-forward cscope-database-file nil t))
+ (if p2
+ (setq p2 (- p2 (length cscope-database-file))))
+ )
+ (cond
+ ( (and p1 p2)
+ (if (< p1 p2)
+ (setq pos p1)
+ (setq pos p2))
+ )
+ ( p1
+ (setq pos p1)
+ )
+ ( p2
+ (setq pos p2)
+ )
+ )
+ (if pos
+ (set-window-point (get-buffer-window buffer) pos))
+ ))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun cscope-extract-symbol-at-cursor (extract-filename)
+ (let* ( (symbol-chars (if extract-filename
+ cscope-filename-chars
+ cscope-symbol-chars))
+ (symbol-char-regexp (concat "[" symbol-chars "]"))
+ )
+ (save-excursion
+ (buffer-substring-no-properties
+ (progn
+ (if (not (looking-at symbol-char-regexp))
+ (re-search-backward "\\w" nil t))
+ (skip-chars-backward symbol-chars)
+ (point))
+ (progn
+ (skip-chars-forward symbol-chars)
+ (point)
+ )))
+ ))
+
+
+(defun cscope-prompt-for-symbol (prompt extract-filename)
+ "Prompt the user for a cscope symbol."
+ (let (sym)
+ (setq sym (cscope-extract-symbol-at-cursor extract-filename))
+ (if (or (not sym)
+ (string= sym "")
+ (not (and cscope-running-in-xemacs
+ cscope-no-mouse-prompts current-mouse-event
+ (or (mouse-event-p current-mouse-event)
+ (misc-user-event-p current-mouse-event))))
+ ;; Always prompt for symbol in dired mode.
+ (eq major-mode 'dired-mode)
+ )
+ (setq sym (read-from-minibuffer prompt sym))
+ sym)
+ ))
+
+
+(defun cscope-find-this-symbol (symbol)
+ "Locate a symbol in source code."
+ (interactive (list
+ (cscope-prompt-for-symbol "Find this symbol: " nil)
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding symbol: %s" symbol)
+ (list "-0" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-global-definition (symbol)
+ "Find a symbol's global definition."
+ (interactive (list
+ (cscope-prompt-for-symbol "Find this global definition: " nil)
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding global definition: %s" symbol)
+ (list "-1" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-global-definition-no-prompting ()
+ "Find a symbol's global definition without prompting."
+ (interactive)
+ (let ( (symbol (cscope-extract-symbol-at-cursor nil))
+ (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding global definition: %s" symbol)
+ (list "-1" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-called-functions (symbol)
+ "Display functions called by a function."
+ (interactive (list
+ (cscope-prompt-for-symbol
+ "Find functions called by this function: " nil)
+ ))
+ (let ( (cscope-adjust nil) ) ;; Disable fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding functions called by: %s" symbol)
+ (list "-2" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-functions-calling-this-function (symbol)
+ "Display functions calling a function."
+ (interactive (list
+ (cscope-prompt-for-symbol
+ "Find functions calling this function: " nil)
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding functions calling: %s" symbol)
+ (list "-3" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-this-text-string (symbol)
+ "Locate where a text string occurs."
+ (interactive (list
+ (cscope-prompt-for-symbol "Find this text string: " nil)
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding text string: %s" symbol)
+ (list "-4" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-egrep-pattern (symbol)
+ "Run egrep over the cscope database."
+ (interactive (list
+ (let (cscope-no-mouse-prompts)
+ (cscope-prompt-for-symbol "Find this egrep pattern: " nil))
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding egrep pattern: %s" symbol)
+ (list "-6" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-this-file (symbol)
+ "Locate a file."
+ (interactive (list
+ (let (cscope-no-mouse-prompts)
+ (cscope-prompt-for-symbol "Find this file: " t))
+ ))
+ (let ( (cscope-adjust nil) ) ;; Disable fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding file: %s" symbol)
+ (list "-7" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+(defun cscope-find-files-including-file (symbol)
+ "Locate all files #including a file."
+ (interactive (list
+ (let (cscope-no-mouse-prompts)
+ (cscope-prompt-for-symbol
+ "Find files #including this file: " t))
+ ))
+ (let ( (cscope-adjust t) ) ;; Use fuzzy matching.
+ (setq cscope-symbol symbol)
+ (cscope-call (format "Finding files #including file: %s" symbol)
+ (list "-8" symbol) nil 'cscope-process-filter
+ 'cscope-process-sentinel)
+ ))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar cscope-minor-mode nil
+ "")
+(make-variable-buffer-local 'cscope-minor-mode)
+(put 'cscope-minor-mode 'permanent-local t)
+
+
+(defun cscope-minor-mode (&optional arg)
+ ""
+ (progn
+ (setq cscope-minor-mode (if (null arg) t (car arg)))
+ (if cscope-minor-mode
+ (progn
+ (easy-menu-add cscope:menu cscope:map)
+ (run-hooks 'cscope-minor-mode-hooks)
+ ))
+ cscope-minor-mode
+ ))
+
+
+(defun cscope:hook ()
+ ""
+ (progn
+ (cscope-minor-mode)
+ ))
+
+
+(or (assq 'cscope-minor-mode minor-mode-map-alist)
+ (setq minor-mode-map-alist (cons (cons 'cscope-minor-mode cscope:map)
+ minor-mode-map-alist)))
+
+(add-hook 'c-mode-hook (function cscope:hook))
+(add-hook 'c++-mode-hook (function cscope:hook))
+(add-hook 'dired-mode-hook (function cscope:hook))
+
+(provide 'xcscope)
|
IvanPulleyn/dotfiles
|
359145b5ce4958d30241a99c028df901fb8bf812
|
kill timeclock forever
|
diff --git a/dot.emacs b/dot.emacs
index 2693aae..b92a4e1 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,67 +1,56 @@
; -*- mode: lisp; -*-
(setq load-path (cons "~/dotfiles" load-path))
(require 'git)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(setq tab-width 2 indent-tabs-mode nil)
(define-key c-mode-map "\C-m" 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
-;; timeclock
-;; (timeclock-modeline-display 1)
-;; (timeclock-query-project-off)
-;; (remove-hook 'timeclock-out-hook 'timeclock-query-comment)
-;; (setq timeclock-workday (* 60 60 12))
-
-;; (define-key ctl-x-map "ti" 'timeclock-in)
-;; (define-key ctl-x-map "to" 'timeclock-out)
-;; (define-key ctl-x-map "tc" 'timeclock-change)
-;; (define-key ctl-x-map "tg" 'timeclock-generate-report-by-day-by-project-new-buffer)
-;; (define-key ctl-x-map "tr" 'timeclock-reread-log)
diff --git a/timeclock-janrain.el b/timeclock-janrain.el
deleted file mode 100644
index d86c529..0000000
--- a/timeclock-janrain.el
+++ /dev/null
@@ -1,285 +0,0 @@
-;;; timeclock-janrain.el -- Add-ons for timeclock.el and timeclock-x.el
-;;
-;; Version: 1.6
-;;
-;;; History:
-;;
-;; 1.1 Initial revision.
-;; 1.2 Added "by day/by project" report generator. Sort the output of
-;; "by-project".
-;; 1.3 Fixed a startup issue and a bug.
-;; 1.4 Added the "new-buffer" versions of the report generators.
-;; Replaced string< with string> since apparently some versions
-;; of Emacs don't define the former. Added totals and averages
-;; to reports and nice formatting for times.
-;; 1.5 Added timeclock-seconds-to-string-function.
-;; 1.6 Use string-lessp instead of string> (the latter is not a
-;; standard Elisp function but defined in bbdb.el).
-;;
-;;; Todo:
-;;
-;; Add a "by project/by day" report generator.
-;;
-;;; Code:
-
-(provide 'timeclock-janrain)
-(require 'timeclock-x)
-
-;; timeclock-x acts weird if this dir doesn't exist:
-(mkdir "~/.timeclock/" t)
-;; Must do this before timeclock-initialize to avoid the stupid prompt:
-(timeclock-query-project-on t)
-(timeclock-initialize)
-
-(defcustom timeclock-seconds-to-string-function 'timeclock-seconds-to-float-string
- "Function to use to convert seconds into strings when
-generating reports."
- :type 'function
- :group 'timeclock)
-
-(defun timeclock-seconds-to-float-string (seconds &optional reverse-leader)
- "Convert SECONDS into hours as a floating point string.
-If REVERSE-LEADER is non-nil, it means to output a \"+\" if the
-time value is negative, rather than a \"-\". This is used when
-negative time values have an inverted meaning (such as with time
-remaining, where negative time really means overtime)."
- (format "%s%.2f"
- (if (< seconds 0) (if reverse-leader "+" "-") "")
- (/ (abs seconds) 60.0 60.0)))
-
-(defun timeclock-generate-project-list ()
- "Generate a list of projects."
- (interactive)
- (dolist (proj (timeclock-by-project))
- (insert (car proj) "\n")))
-
-(defun timeclock-generate-report-by-project (&optional fmt)
- "Generate a report of hours spent on each project based on the
-current timelog file. By default, the report is in plain text; a
-prefix argument adds additional markup: 1 results in table
-output, 2 in HTML."
- (interactive "P")
- (setq fmt (timeclock-normalize-fmt fmt))
- (let ((data (timeclock-by-project)) (total-time 0) (tfmt "%7s"))
- ;; Output the header.
- (choose fmt
- '()
- '(progn
- (table-insert 2 (+ (length data) 2))
- (timeclock-insert-header-row fmt "Project" "Time spent"))
- '(progn
- (insert "<table border=1 cellpadding=3>")
- (timeclock-insert-header-row fmt "Project" "Time spent")))
- ;; Output the body.
- (dolist (proj data)
- (let ((time (car (cdr proj))))
- (setq total-time (+ total-time time))
- (timeclock-insert-row fmt
- (car proj)
- (format tfmt
- (funcall timeclock-seconds-to-string-function time)))))
- ;; Output the totals.
- (timeclock-insert-row fmt
- "TOTAL "
- (format tfmt
- (funcall timeclock-seconds-to-string-function total-time)))
- ;; Output the footer.
- (choose fmt
- '()
- '()
- '(insert "\n</table>"))))
-
-(defun timeclock-generate-report-by-project-new-buffer (&optional fmt)
- "Same as timeclock-generate-report-by-project, but generates
-the report in a new buffer."
- (interactive "P")
- (setq fmt (timeclock-normalize-fmt fmt))
- (timeclock-generate-new-buffer fmt)
- (timeclock-generate-report-by-project fmt))
-
-(defun timeclock-generate-report-by-day-by-project (&optional fmt)
- "Generate a report by day of hours spent on each project based
-on the current timelog file. By default, the report is in plain
-text; a prefix argument adds additional markup: 1 results in
-table output, 2 in HTML."
- (interactive "P")
- (setq fmt (timeclock-normalize-fmt fmt))
- (let ((data (timeclock-by-day-by-project))
- (rows 0) tmp (total-days 0) (total-time 0) (tfmt "%7s"))
- ;; Calculate number of rows.
- (setq tmp data)
- (dolist (day tmp)
- (dolist (entry (cdr day))
- (setq rows (+ rows 1))))
- ;; Output the header.
- (choose fmt
- '()
- '(progn
- (table-insert 3 (+ rows 3))
- (timeclock-insert-header-row fmt "Day" "Project" "Time spent"))
- '(progn
- (insert "<table border=1 cellpadding=3>")
- (timeclock-insert-header-row fmt "Day" "Project" "Time spent")))
- ;; Output the body.
- (dolist (day data)
- (let ((first t) (curr-day (car day)))
- (setq total-days (+ total-days 1))
- (dolist (entry (cdr day))
- (let ((time (car (cdr entry))))
- (setq total-time (+ total-time time))
- (if first
- (progn
- (timeclock-insert-row fmt
- curr-day
- (car entry)
- (format tfmt
- (funcall timeclock-seconds-to-string-function
- time)))
- (setq first nil))
- (timeclock-insert-row fmt
- (choose fmt " " "" "")
- (car entry)
- (format tfmt
- (funcall timeclock-seconds-to-string-function
- time))))))))
- ;; Output the totals/average.
- (timeclock-insert-row fmt
- (format "%-10d" total-days)
- "TOTAL "
- (format tfmt
- (funcall timeclock-seconds-to-string-function
- total-time)))
- (timeclock-insert-row fmt
- (choose fmt " " "" " ")
- "AVERAGE "
- (format tfmt
- (funcall timeclock-seconds-to-string-function
- (/ total-time total-days))))
- ;; Output the footer.
- (choose fmt
- '()
- '()
- '(insert "\n</table>"))))
-
-(defun timeclock-generate-report-by-day-by-project-new-buffer (&optional fmt)
- "Same as timeclock-generate-report-by-day-by-project, but
-generates the report in a new buffer."
- (interactive "P")
- (setq fmt (timeclock-normalize-fmt fmt))
- (timeclock-generate-new-buffer fmt)
- (timeclock-generate-report-by-day-by-project fmt))
-
-(defun timeclock-normalize-fmt (fmt)
- "Normalize the format selector."
- (if fmt () (setq fmt 0))
- (if (> fmt 2) (setq fmt 2))
- (if (< fmt 0) (setq fmt 0))
- fmt)
-
-(defun timeclock-generate-new-buffer (fmt)
- "Create and switch to a new buffer with appropriate major mode."
- (switch-to-buffer (generate-new-buffer "*timeclock report*"))
- (choose fmt
- '(text-mode)
- '(text-mode)
- '(html-mode)))
-
-(defun timeclock-by-project (&optional project-alist)
- "Return the times spent summed up by project as an alist of
-alists in the format (PROJECT TIME)."
- (let (sums)
- (dolist (proj (or project-alist (timeclock-project-alist)) sums)
- (let ((p (car proj)) (s (timeclock-entry-list-length (cdr proj))))
- (setq sums (cons (list p s) sums))))
- (sort sums (lambda (a b) (string-lessp (car a) (car b))))))
-
-(defun timeclock-by-day-by-project (&optional day-alist)
- "Return the times spent by day summed up by project as an alist
-of alists in the format (DAY (PROJECT TIME) (PROJECT TIME) ...)."
- (let (result)
- (dolist (day (or day-alist (timeclock-day-alist)))
- (let ((sums (make-hash-table :test 'equal :size 13)) ptimes)
- ;; Build a hash of total project times for this day.
- (dolist (entry (cdr (cdr day)))
- (let (sum
- (proj (timeclock-entry-project entry))
- (len (timeclock-entry-length entry)))
- (setq sum (gethash proj sums 0))
- (puthash proj (+ sum len) sums)))
- ;; Convert the hash into a list.
- (maphash (lambda (k v) (setq ptimes (cons (list k v) ptimes))) sums)
- ;; Sort the list
- (setq ptimes (sort ptimes (lambda (a b) (string-lessp (car a) (car b)))))
- ;; Add an entry for the current day to the result.
- (setq result (cons (cons (car day) ptimes) result))))
- ;; Sort the result.
- (sort result (lambda (a b) (string-lessp (car b) (car a))))))
-
-(defun timeclock-insert-row (fmt &rest vals)
- (choose fmt
- '(insert "\n") ; text
- '() ; table
- '(insert "\n<tr>")) ; html
- (let ((first t))
- (dolist (val vals)
- (timeclock-insert-cell fmt first val)
- (setq first nil)))
- (choose fmt
- '() ; text
- '() ; table
- '(insert "\n</tr>"))) ; html
-
-(defun timeclock-insert-cell (fmt first text)
- (if first
- (choose fmt
- '() ; text
- '() ; table
- '(insert "\n <td>")) ; html
- (choose fmt
- '(insert "\t") ; text
- '() ; table
- '(insert "\n <td>"))) ; html
- (timeclock-insert-text fmt text)
- (choose fmt
- '() ; text
- '(table-forward-cell) ; table
- '(insert "</td>"))) ; html
-
-(defun timeclock-insert-header-row (fmt &rest vals)
- (choose fmt
- '(insert "\n") ; text
- '() ; table
- '(insert "\n<tr>")) ; html
- (let ((first t))
- (dolist (val vals)
- (timeclock-insert-header-cell fmt first val)
- (setq first nil)))
- (choose fmt
- '() ; text
- '() ; table
- '(insert "\n</tr>"))) ; html
-
-(defun timeclock-insert-header-cell (fmt first text)
- (if first
- (choose fmt
- '() ; text
- '() ; table
- '(insert "\n <th>")) ; html
- (choose fmt
- '(insert "\t") ; text
- '() ; table
- '(insert "\n <th>"))) ; html
- (timeclock-insert-text fmt text)
- (choose fmt
- '() ; text
- '(table-forward-cell) ; table
- '(insert "</th>"))) ; html
-
-(defun timeclock-insert-text (fmt text)
- (choose fmt
- '(insert text) ; text
- '(table--cell-insert-char text) ; table
- '(insert text))) ; html
-
-(defun choose (fmt &rest alt)
- (eval (nth fmt alt)))
|
IvanPulleyn/dotfiles
|
bbea4011e555f470b881e2c2f2d67a4c1f73a21f
|
fix global-font-lock-mode
|
diff --git a/dot.emacs b/dot.emacs
index ef1e6f7..2693aae 100644
--- a/dot.emacs
+++ b/dot.emacs
@@ -1,69 +1,67 @@
; -*- mode: lisp; -*-
(setq load-path (cons "~/dotfiles" load-path))
(require 'git)
-;; (require 'timeclock)
-;; (require 'timeclock-janrain)
(autoload 'doc-mode "doc-mode")
(autoload 'javascript-mode "javascript" nil t)
(autoload 'graphviz-dot-mode "graphviz-dot-mode")
-(setq global-font-lock-mode 1)
+(global-font-lock-mode 1)
(setq indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq line-move-visual nil)
(setq column-number-mode t)
(put 'narrow-to-region 'disabled nil)
;; file extensions
(setq auto-mode-alist
(append auto-mode-alist
'(
("\\.[hg]s$" . haskell-mode)
("\\.doc$" . doc-mode)
("\\.dot$" . graphviz-dot-mode)
("\\.hi$" . haskell-mode)
("\\.hsc$" . haskell-mode)
("\\.js$" . javascript-mode)
("\\.l[hg]s$" . literate-haskell-mode)
("\\.erb$" . html-mode)
("\\.rhtml$" . html-mode)
)))
(setq completion-ignored-extensions
(append completion-ignored-extensions
'(
".d"
".x"
)))
;; c-mode
(defun my-c-mode-common-hook ()
(setq tab-width 2 indent-tabs-mode nil)
(define-key c-mode-map "\C-m" 'newline-and-indent))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; function keys
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'dabbrev-expand)
(global-set-key [f5] 'kill-this-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'font-lock-fontify-buffer)
(global-set-key [f8] 'indent-region)
(global-set-key [f9] 'next-error)
(global-set-key [f10] 'compile)
;; timeclock
;; (timeclock-modeline-display 1)
;; (timeclock-query-project-off)
;; (remove-hook 'timeclock-out-hook 'timeclock-query-comment)
;; (setq timeclock-workday (* 60 60 12))
;; (define-key ctl-x-map "ti" 'timeclock-in)
;; (define-key ctl-x-map "to" 'timeclock-out)
;; (define-key ctl-x-map "tc" 'timeclock-change)
;; (define-key ctl-x-map "tg" 'timeclock-generate-report-by-day-by-project-new-buffer)
;; (define-key ctl-x-map "tr" 'timeclock-reread-log)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.