-
-
Save MasterDuke17/f11307a8724e2d9969d2dbb9109c4a95 to your computer and use it in GitHub Desktop.
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
diff --git a/nqp-truffle.nqp b/nqp-truffle.nqp | |
index a64a2860b..9e264dbad 100644 | |
--- a/nqp-truffle.nqp | |
+++ b/nqp-truffle.nqp | |
@@ -111,6 +111,8 @@ class QAST::OperationsTruffle { | |
add_simple_op('uc', $T_STR, [$T_STR]); | |
+ add_simple_op('chars', $T_INT, [$T_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)); | |
@@ -259,6 +261,17 @@ class QAST::TruffleCompiler { | |
} | |
} | |
+ if $got == $T_INT { | |
+ if $desired == $T_STR { | |
+ return TAST.new($T_STR, ['smart-stringify', $tast.tree]); | |
+ } | |
+ } | |
+ | |
+ if $got == $T_STR { | |
+ if $desired == $T_INT { | |
+ return TAST.new($T_INT, ['smart-intify', $tast.tree]); | |
+ } | |
+ } | |
say("Can't coerce $got to $desired"); | |
$tast; | |
diff --git a/src/vm/jvm/bin/write_a_node.nqp b/src/vm/jvm/bin/write_a_node.nqp | |
index 021f5bd06..147268b06 100644 | |
--- a/src/vm/jvm/bin/write_a_node.nqp | |
+++ b/src/vm/jvm/bin/write_a_node.nqp | |
@@ -117,5 +117,5 @@ sub add_simple_op($name, $return_type, $args) { | |
} | |
-add_simple_op('concat', $T_STR, [$T_STR, $T_STR]); | |
+add_simple_op('chars', $T_INT, [$T_STR]); | |
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/truffle/TruffleCompiler.java b/src/vm/jvm/runtime/org/perl6/nqp/truffle/TruffleCompiler.java | |
index 609b3b194..55dbe79d5 100644 | |
--- a/src/vm/jvm/runtime/org/perl6/nqp/truffle/TruffleCompiler.java | |
+++ b/src/vm/jvm/runtime/org/perl6/nqp/truffle/TruffleCompiler.java | |
@@ -23,6 +23,7 @@ import org.perl6.nqp.truffle.nodes.expression.NQPBoxNQPStr; | |
import org.perl6.nqp.truffle.nodes.expression.NQPNullNode; | |
import org.perl6.nqp.truffle.nodes.expression.NQPLcNode; | |
import org.perl6.nqp.truffle.nodes.expression.NQPUcNode; | |
+import org.perl6.nqp.truffle.nodes.expression.NQPCharsNode; | |
import org.perl6.nqp.truffle.nodes.io.NQPSayNode; | |
import org.perl6.nqp.truffle.nodes.io.NQPPrintNode; | |
@@ -139,6 +140,8 @@ public class TruffleCompiler { | |
return new NQPLcNode(build(node.at_pos_boxed(tc, 1), scope, tc)); | |
case "uc": | |
return new NQPUcNode(build(node.at_pos_boxed(tc, 1), scope, tc)); | |
+ case "chars": | |
+ return new NQPCharsNode(build(node.at_pos_boxed(tc, 1), scope, tc)); | |
default: | |
throw new IllegalArgumentException("Wrong node type: " + node.at_pos_boxed(tc, 0).get_str(tc)); | |
} | |
diff --git a/src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPSmartStringifyNode.java b/src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPSmartStringifyNode.java | |
index 92b9a4326..5410ab6a2 100644 | |
--- a/src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPSmartStringifyNode.java | |
+++ b/src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPSmartStringifyNode.java | |
@@ -64,6 +64,6 @@ public final class NQPSmartStringifyNode extends NQPNode { | |
} else if (value instanceof Long) { | |
return ((Long) value).toString(); | |
} | |
- throw new RuntimeException("can't smart stringify"); | |
+ throw new RuntimeException("can't smart stringify a " + value.getClass().getName()); | |
} | |
} |
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
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; | |
@NodeInfo(shortName = "chars") | |
public final class NQPCharsNode extends NQPNode { | |
@Child private NQPNode aNode; | |
public NQPCharsNode(NQPNode aNode) { | |
this.aNode = aNode; | |
} | |
public long executeInteger(VirtualFrame frame) { | |
return aNode.executeString(frame).length(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment