Skip to content

Commit

Permalink
[truffle] Implement nqp::tclc
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterDuke17 committed Jul 1, 2018
1 parent 3b6bba5 commit a5f75c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nqp-truffle.nqp
Expand Up @@ -148,6 +148,8 @@ class QAST::OperationsTruffle {
});
}

add_simple_op('tclc', $STR, [$STR]);

# explicit takeclosure is used by the JVM backend we no-op it.
add_op('takeclosure', sub ($comp, $node, :$want) {
$comp.as_truffle($node[0], :want($want));
Expand Down
@@ -0,0 +1,30 @@
package org.perl6.nqp.truffle.nodes.expression;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeInfo;
import org.perl6.nqp.truffle.nodes.NQPNode;
import org.perl6.nqp.dsl.Deserializer;

@NodeInfo(shortName = "tclc")
public final class NQPTclcNode extends NQPNode {
@Child private NQPNode argNode;

@Deserializer
public NQPTclcNode(NQPNode argNode) {
this.argNode = argNode;
}

static String codepointToTitleCase(int codepoint) {
if (codepoint == 223) return "Ss";
return new String(Character.toChars(Character.toTitleCase(codepoint)));
}

@Override
public String executeStr(VirtualFrame frame) {
String in = argNode.executeStr(frame);
if (in.length() == 0)
return in;
int first = in.codePointAt(0);
return codepointToTitleCase(first)
+ in.substring(Character.charCount(first)).toLowerCase();
}
}

0 comments on commit a5f75c6

Please sign in to comment.