Permalink
Browse files

allows loop to evaluate to primitive values

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent 17ce750 commit 6ce5cf6fea3ecf6f11e8b1824d1c1494c478774a @cgrand cgrand committed with stuarthalloway Nov 21, 2012
Showing with 19 additions and 4 deletions.
  1. +19 −4 src/jvm/clojure/lang/Compiler.java
@@ -300,6 +300,9 @@ static Object elideMeta(Object m){
EVAL
}
+private class Recur {};
+static final public Class RECUR_CLASS = Recur.class;
+
interface Expr{
Object eval() ;
@@ -2618,6 +2621,8 @@ public boolean hasJavaClass() {
&& elseExpr.hasJavaClass()
&&
(thenExpr.getJavaClass() == elseExpr.getJavaClass()
+ || thenExpr.getJavaClass() == RECUR_CLASS
+ || elseExpr.getJavaClass() == RECUR_CLASS
|| (thenExpr.getJavaClass() == null && !elseExpr.getJavaClass().isPrimitive())
|| (elseExpr.getJavaClass() == null && !thenExpr.getJavaClass().isPrimitive()));
}
@@ -2627,7 +2632,9 @@ public boolean canEmitPrimitive(){
{
return thenExpr instanceof MaybePrimitiveExpr
&& elseExpr instanceof MaybePrimitiveExpr
- && thenExpr.getJavaClass() == elseExpr.getJavaClass()
+ && (thenExpr.getJavaClass() == elseExpr.getJavaClass()
+ || thenExpr.getJavaClass() == RECUR_CLASS
+ || elseExpr.getJavaClass() == RECUR_CLASS)
&& ((MaybePrimitiveExpr)thenExpr).canEmitPrimitive()
&& ((MaybePrimitiveExpr)elseExpr).canEmitPrimitive();
}
@@ -2639,7 +2646,7 @@ public boolean canEmitPrimitive(){
public Class getJavaClass() {
Class thenClass = thenExpr.getJavaClass();
- if(thenClass != null)
+ if(thenClass != null && thenClass != RECUR_CLASS)
return thenClass;
return elseExpr.getJavaClass();
}
@@ -6111,7 +6118,7 @@ public boolean canEmitPrimitive(){
}
-public static class RecurExpr implements Expr{
+public static class RecurExpr implements Expr, MaybePrimitiveExpr{
public final IPersistentVector args;
public final IPersistentVector loopLocals;
final int line;
@@ -6216,7 +6223,7 @@ public boolean hasJavaClass() {
}
public Class getJavaClass() {
- return null;
+ return RECUR_CLASS;
}
static class Parser implements IParser{
@@ -6280,6 +6287,14 @@ else if(primc == double.class)
return new RecurExpr(loopLocals, args, line, column, source);
}
}
+
+ public boolean canEmitPrimitive() {
+ return true;
+ }
+
+ public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen) {
+ emit(context, objx, gen);
+ }
}
private static LocalBinding registerLocal(Symbol sym, Symbol tag, Expr init, boolean isArg) {

0 comments on commit 6ce5cf6

Please sign in to comment.