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
Showing
3 changed files
with
71 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
31 changes: 31 additions & 0 deletions
31
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPOrdatNode.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,31 @@ | ||
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.NQPIntNode; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "ordat") | ||
public final class NQPOrdatNode extends NQPIntNode { | ||
@Child private NQPNode strNode; | ||
@Child private NQPNode offsetNode; | ||
|
||
@Deserializer | ||
public NQPOrdatNode(NQPNode strNode, NQPNode offsetNode) { | ||
this.strNode = strNode; | ||
this.offsetNode = offsetNode; | ||
} | ||
|
||
@Override | ||
public long executeInt(VirtualFrame frame) { | ||
String str = strNode.executeStr(frame); | ||
long offset = offsetNode.executeInt(frame); | ||
|
||
if (offset < 0 || offset >= str.length()) { | ||
return -1; | ||
} | ||
else { | ||
return str.codePointAt((int)offset); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPOrdfirstNode.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,27 @@ | ||
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.NQPIntNode; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "ordfirst") | ||
public final class NQPOrdfirstNode extends NQPIntNode { | ||
@Child private NQPNode argNode; | ||
|
||
@Deserializer | ||
public NQPOrdfirstNode(NQPNode argNode) { | ||
this.argNode = argNode; | ||
} | ||
|
||
@Override | ||
public long executeInt(VirtualFrame frame) { | ||
String str = argNode.executeStr(frame); | ||
if (str.isEmpty()) { | ||
return -1; | ||
} | ||
else { | ||
return str.codePointAt(0); | ||
} | ||
} | ||
} |
Looks like a duplicate ‘ordbaseat’ here.