Skip to content

Commit

Permalink
allows loop to evaluate to primitive values
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
cgrand authored and stuarthalloway committed Dec 22, 2012
1 parent 17ce750 commit 6ce5cf6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/jvm/clojure/lang/Compiler.java
Expand Up @@ -300,6 +300,9 @@ public enum C{
EVAL
}

private class Recur {};
static final public Class RECUR_CLASS = Recur.class;

interface Expr{
Object eval() ;

Expand Down Expand Up @@ -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()));
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -6216,7 +6223,7 @@ public boolean hasJavaClass() {
}

public Class getJavaClass() {
return null;
return RECUR_CLASS;
}

static class Parser implements IParser{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6ce5cf6

Please sign in to comment.