Skip to content

Commit

Permalink
[truffle] Missing part of moving boolification to specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jul 24, 2018
1 parent b64648d commit 0817412
Showing 1 changed file with 8 additions and 17 deletions.
@@ -1,25 +1,16 @@
package org.perl6.nqp.truffle.nodes;


import org.perl6.nqp.truffle.nodes.NQPNode;
import org.perl6.nqp.truffle.runtime.NQPListIterator;
import org.perl6.nqp.truffle.runtime.NQPNull;
import com.oracle.truffle.api.CompilerDirectives;

public abstract class NQPNodeWithBoolification extends NQPNode {
/* TODO - proper checking */
protected boolean toBoolean(Object arg) {
if (arg instanceof String) {
return ((String) arg != "") ? true : false;
} else if (arg instanceof Long) {
return ((long) arg) != 0 ? true : false;
} else if (arg instanceof Double) {
return ((double) arg) != 0 ? true : false;
} else if (arg instanceof NQPListIterator) {
return ((NQPListIterator) arg).boolify();
} else if (arg == NQPNull.SINGLETON) {
return false;
} else {
throw new RuntimeException("Can't boolify");
@Child private NQPToBooleanNode toBooleanCast;

protected boolean toBoolean(Object value) {
if (toBooleanCast == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toBooleanCast = insert(NQPToBooleanNodeGen.create());
}
return toBooleanCast.executeBoolean(value);
}
}

0 comments on commit 0817412

Please sign in to comment.