Skip to content

Commit a5f75c6

Browse files
committed
[truffle] Implement nqp::tclc
1 parent 3b6bba5 commit a5f75c6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

nqp-truffle.nqp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class QAST::OperationsTruffle {
148148
});
149149
}
150150

151+
add_simple_op('tclc', $STR, [$STR]);
152+
151153
# explicit takeclosure is used by the JVM backend we no-op it.
152154
add_op('takeclosure', sub ($comp, $node, :$want) {
153155
$comp.as_truffle($node[0], :want($want));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.perl6.nqp.truffle.nodes.expression;
2+
import com.oracle.truffle.api.frame.VirtualFrame;
3+
import com.oracle.truffle.api.nodes.NodeInfo;
4+
import org.perl6.nqp.truffle.nodes.NQPNode;
5+
import org.perl6.nqp.dsl.Deserializer;
6+
7+
@NodeInfo(shortName = "tclc")
8+
public final class NQPTclcNode extends NQPNode {
9+
@Child private NQPNode argNode;
10+
11+
@Deserializer
12+
public NQPTclcNode(NQPNode argNode) {
13+
this.argNode = argNode;
14+
}
15+
16+
static String codepointToTitleCase(int codepoint) {
17+
if (codepoint == 223) return "Ss";
18+
return new String(Character.toChars(Character.toTitleCase(codepoint)));
19+
}
20+
21+
@Override
22+
public String executeStr(VirtualFrame frame) {
23+
String in = argNode.executeStr(frame);
24+
if (in.length() == 0)
25+
return in;
26+
int first = in.codePointAt(0);
27+
return codepointToTitleCase(first)
28+
+ in.substring(Character.charCount(first)).toLowerCase();
29+
}
30+
}

0 commit comments

Comments
 (0)