File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
runtime/org/perl6/nqp/truffle/nodes/expression Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -818,6 +818,9 @@ class QAST::TruffleCompiler does SerializeOnce {
818
818
if $ got == $ NUM {
819
819
return TAST. new ($ INT , [' coerce-num-to-int' , $ tast . tree ]);
820
820
}
821
+ if $ got == $ STR {
822
+ return TAST. new ($ INT , [' coerce-str-to-int' , $ tast . tree ]);
823
+ }
821
824
}
822
825
823
826
# TODO - Perl 6 proper does it differently than nqp
Original file line number Diff line number Diff line change
1
+ package org .perl6 .nqp .truffle .nodes .expression ;
2
+ import com .oracle .truffle .api .frame .VirtualFrame ;
3
+ import com .oracle .truffle .api .nodes .NodeInfo ;
4
+ import org .perl6 .nqp .truffle .nodes .NQPNode ;
5
+ import org .perl6 .nqp .truffle .nodes .NQPIntNode ;
6
+ import org .perl6 .nqp .dsl .Deserializer ;
7
+
8
+ @ NodeInfo (shortName = "coerce an str to int" )
9
+ public final class NQPCoerceStrToIntNode extends NQPIntNode {
10
+ @ Child private NQPNode argNode ;
11
+
12
+ @ Deserializer ("coerce-str-to-int" )
13
+ public NQPCoerceStrToIntNode (NQPNode argNode ) {
14
+ this .argNode = argNode ;
15
+ }
16
+
17
+ @ Override
18
+ public long executeInt (VirtualFrame frame ) {
19
+ String value = argNode .executeStr (frame );
20
+ try {
21
+ return Long .parseLong (value );
22
+ }
23
+ catch (NumberFormatException e ) {
24
+ return 0 ;
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments