Skip to content

Commit

Permalink
[truffle] Add num to int coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Sep 4, 2018
1 parent 1e47d6e commit ff08442
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vm/jvm/Truffle.nqp
Expand Up @@ -700,6 +700,12 @@ class QAST::TruffleCompiler does SerializeOnce {
}
}

if $desired == $INT {
if $got == $NUM {
return TAST.new($INT, ['coerce-num-to-int', $tast.tree]);
}
}

# TODO - Perl 6 proper does it differently than nqp
if $got == $OBJ {
if $desired == $STR {
Expand Down
@@ -0,0 +1,25 @@
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.truffle.runtime.Coercions;

import org.perl6.nqp.dsl.Deserializer;

@NodeInfo(description = "coerce an num to int")
public final class NQPCoerceNumToIntNode extends NQPStrNode {
@Child private NQPNode argNode;

@Deserializer("coerce-num-to-int")
public NQPCoerceNumToIntNode(NQPNode argNode) {
this.argNode = argNode;
}


@Override
public long executeInt(VirtualFrame frame) {
return (long)argNode.executeNum(frame);
}
}

0 comments on commit ff08442

Please sign in to comment.