summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2007-09-07 17:21:21 +0000
committerRich Hickey <richhickey@gmail.com>2007-09-07 17:21:21 +0000
commit2eb4e3d4f77718e04645eb59f629b31d9f85e166 (patch)
treeb83311b664f13056a4172558077a57fad691f0b6 /src
parented021e912e1d3c23ff533961d9564e8b9c184ea1 (diff)
added vector expressions
Diffstat (limited to 'src')
-rw-r--r--src/jvm/clojure/lang/Compiler.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java
index 24c170f0..f0de498c 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -923,6 +923,37 @@ static String munge(String name){
return sb.toString();
}
+static class VectorExpr implements Expr{
+ final IPersistentVector args;
+ final static Method vectorMethod = Method.getMethod("clojure.lang.IPersistentVector vector(Object[])");
+
+
+ public VectorExpr(IPersistentVector args){
+ this.args = args;
+ }
+
+ public Object eval() throws Exception{
+ IPersistentVector ret = PersistentVector.EMPTY;
+ for(int i = 0; i < args.count(); i++)
+ ret = (IPersistentVector) ret.cons(((Expr) args.nth(i)).eval());
+ return ret;
+ }
+
+ public void emit(C context, FnExpr fn, GeneratorAdapter gen){
+ MethodExpr.emitArgsAsArray(args, fn, gen);
+ gen.invokeStatic(RT_TYPE, vectorMethod);
+ if(context == C.STATEMENT)
+ gen.pop();
+ }
+
+ public static Expr parse(C context, IPersistentVector form) throws Exception{
+ IPersistentVector args = PersistentVector.EMPTY;
+ for(int i = 0; i < form.count(); i++)
+ args = (IPersistentVector) args.cons(analyze(C.EXPRESSION, form.nth(i)));
+ return new VectorExpr(args);
+ }
+}
+
static class InvokeExpr implements Expr{
final Expr fexpr;
final IPersistentVector args;
@@ -1586,6 +1617,8 @@ private static Expr analyze(C context, Object form, String name) throws Exceptio
return new CharExpr((Character) form);
else if(form instanceof ISeq)
return analyzeSeq(context, (ISeq) form, name);
+ else if(form instanceof IPersistentVector)
+ return VectorExpr.parse(context, (IPersistentVector) form);
// else
throw new UnsupportedOperationException();