Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[truffle] Missing part of moving boolification to specialization
- Loading branch information
Showing
1 changed file
with
8 additions
and
17 deletions.
There are no files selected for viewing
25 changes: 8 additions & 17 deletions
25
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/NQPNodeWithBoolification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |