Skip to content

Commit c2120c5

Browse files
committed
[truffle] Generate op classes for ops that have _i, _s, etc. suffixes
1 parent dd16ea0 commit c2120c5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/vm/jvm/bin/write_a_node.nqp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ sub add_simple_op($name, $return_type, $args) {
2525
$out := $out ~ '' ~ "\n";
2626

2727
$out := $out ~ "@NodeInfo(shortName = \"$name\")" ~ "\n";
28-
my $jvm_name := 'NQP' ~ ucfirst(subst($name, /_(\w)/, -> $match {nqp::uc($match[0])})) ~ 'Node';
28+
my $java_name := 'NQP' ~ ucfirst($name) ~ 'Node';
2929

30-
$out := $out ~ "public final class $jvm_name extends NQPNode \{" ~ "\n";
30+
for <_i Int _n Num _s Str _I Bigint _u UInt _b CodeBlock> -> $suffix, $java_suffix {
31+
$java_name := subst($java_name, /$suffix/, $java_suffix);
32+
}
33+
34+
$out := $out ~ "public final class $java_name extends NQPNode \{" ~ "\n";
3135

3236
my @children;
3337

@@ -59,7 +63,7 @@ sub add_simple_op($name, $return_type, $args) {
5963
$out := $out ~ "\n";
6064
$out := $out ~ " @Deserializer\n";
6165

62-
$out := $out ~ " public $jvm_name({nqp::join(', ', @sig)}) \{" ~ "\n";
66+
$out := $out ~ " public $java_name({nqp::join(', ', @sig)}) \{" ~ "\n";
6367
for @children -> $child {
6468
$out := $out ~ " this.$child = $child;" ~ "\n";
6569
}
@@ -81,7 +85,7 @@ sub add_simple_op($name, $return_type, $args) {
8185

8286
$out := $out ~ "\}" ~ "\n";
8387

84-
my $path := "src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/$package/$jvm_name.java";
88+
my $path := "src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/$package/$java_name.java";
8589
if (nqp::stat($path, nqp::const::STAT_EXISTS) == 1) {
8690
say("Did NOT OVERWRITE $path");
8791
} else {
@@ -91,5 +95,5 @@ sub add_simple_op($name, $return_type, $args) {
9195
}
9296

9397

94-
add_simple_op('CoerceIntToStr', $STR, [$INT]);
98+
add_simple_op('add_i', $INT, [$INT, $INT]);
9599

src/vm/jvm/dsl/org/perl6/nqp/dsl/Processor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ public class Processor extends AbstractProcessor {
3030

3131
private String opNameFromClassName(String className) {
3232
return className.replaceFirst("^" + Pattern.quote(prefix), "")
33-
.replaceFirst("Node$", "")
33+
.replaceFirst("IntNode$", "_i")
34+
.replaceFirst("NumNode$", "_n")
35+
.replaceFirst("StrNode$", "_s")
36+
.replaceFirst("BigintNode$", "_I")
37+
.replaceFirst("UIntNode$", "_u")
38+
.replaceFirst("CodeBlock$", "_b")
3439
.toLowerCase();
3540
}
3641

0 commit comments

Comments
 (0)