Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbb7753
commit 3c84804
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPChrNode.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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.truffle.nodes.NQPStrNode; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "chr") | ||
public final class NQPChrNode extends NQPStrNode { | ||
@Child private NQPNode argNode; | ||
|
||
@Deserializer | ||
public NQPChrNode(NQPNode argNode) { | ||
this.argNode = argNode; | ||
} | ||
|
||
@Override | ||
public String executeStr(VirtualFrame frame) { | ||
long ord = argNode.executeInt(frame); | ||
|
||
if (ord < 0) | ||
throw new RuntimeException("chr codepoint cannot be negative"); | ||
|
||
return (new StringBuffer()).append(Character.toChars((int)ord)).toString(); | ||
} | ||
} |