Skip to content

Commit b64648d

Browse files
committed
[truffle] Use @specialization when boolifing stuff
1 parent 987a270 commit b64648d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.perl6.nqp.truffle.nodes;
2+
3+
import com.oracle.truffle.api.dsl.Specialization;
4+
import org.perl6.nqp.truffle.runtime.NQPListIterator;
5+
import org.perl6.nqp.truffle.runtime.NQPNull;
6+
7+
public abstract class NQPToBooleanNode extends NQPBaseNode {
8+
public abstract boolean executeBoolean(Object value);
9+
10+
@Specialization
11+
protected boolean doString(String value) {
12+
return ((String) value != "") ? true : false;
13+
}
14+
15+
@Specialization
16+
protected boolean doLong(Long value) {
17+
return ((long) value) != 0 ? true : false;
18+
}
19+
20+
@Specialization
21+
protected boolean doDouble(Double value) {
22+
return ((double) value) != 0 ? true : false;
23+
}
24+
25+
@Specialization
26+
protected boolean doNQPListIterator(NQPListIterator value) {
27+
return ((NQPListIterator) value).boolify();
28+
}
29+
30+
@Specialization
31+
protected boolean doNQPNull(Object value) {
32+
return false;
33+
}
34+
35+
protected final boolean isNull(Object value) {
36+
return value == NQPNull.SINGLETON;
37+
}
38+
}

0 commit comments

Comments
 (0)