1
my $ops := QAST::MASTCompiler.operations();
2
my $MVM_reg_int64 := 4;
3
my $MVM_reg_num64 := 6;
7
$ops.add_hll_op('nqp', 'preinc', -> $qastcomp, $op {
9
unless nqp::istype($var, QAST::Var) {
10
nqp::die("Pre-increment can only work on a variable");
12
$qastcomp.as_mast(QAST::Op.new(
18
QAST::IVal.new( :value(1) )
22
$ops.add_hll_op('nqp', 'predec', -> $qastcomp, $op {
24
unless nqp::istype($var, QAST::Var) {
25
nqp::die("Pre-decrement can only work on a variable");
27
$qastcomp.as_mast(QAST::Op.new(
33
QAST::IVal.new( :value(1) )
37
$ops.add_hll_op('nqp', 'postinc', -> $qastcomp, $op {
39
my $tmp := QAST::Op.unique('tmp');
40
unless nqp::istype($var, QAST::Var) {
41
nqp::die("Post-increment can only work on a variable");
43
$qastcomp.as_mast(QAST::Op.new(
49
QAST::Var.new( :name($tmp), :scope('local'), :decl('var'), :returns($var.returns) ),
57
QAST::Var.new( :name($tmp), :scope('local'), :returns($var.returns) ),
58
QAST::IVal.new( :value(1) )
64
$ops.add_hll_op('nqp', 'postdec', -> $qastcomp, $op {
66
my $tmp := QAST::Op.unique('tmp');
67
unless nqp::istype($var, QAST::Var) {
68
nqp::die("Post-decrement can only work on a variable");
70
$qastcomp.as_mast(QAST::Op.new(
76
QAST::Var.new( :name($tmp), :scope('local'), :decl('var') ),
84
QAST::Var.new( :name($tmp), :scope('local') ),
85
QAST::IVal.new( :value(1) )
91
$ops.add_hll_op('nqp', 'numify', -> $qastcomp, $op {
92
$qastcomp.as_mast($op[0], :want($MVM_reg_num64))
95
$ops.add_hll_op('nqp', 'stringify', -> $qastcomp, $op {
96
$qastcomp.as_mast($op[0], :want($MVM_reg_str))
99
$ops.add_hll_op('nqp', 'falsey', -> $qastcomp, $op {
100
unless $op.list == 1 {
101
nqp::die('falsey op requires one child');
103
my $val := $qastcomp.as_mast($op[0]);
104
if $val.result_kind == $MVM_reg_int64 {
105
my $not_reg := $*REGALLOC.fresh_register($MVM_reg_int64);
106
my @ins := $val.instructions;
107
push_op(@ins, 'not_i', $not_reg, $val.result_reg);
108
MAST::InstructionList.new(@ins, $not_reg, $MVM_reg_int64)
110
elsif $val.result_kind == $MVM_reg_obj {
111
my $not_reg := $*REGALLOC.fresh_register($MVM_reg_int64);
112
my @ins := $val.instructions;
113
push_op(@ins, 'isfalse', $not_reg, $val.result_reg);
114
MAST::InstructionList.new(@ins, $not_reg, $MVM_reg_int64)
116
elsif $val.result_kind == $MVM_reg_str {
117
my $not_reg := $*REGALLOC.fresh_register($MVM_reg_int64);
118
my @ins := $val.instructions;
119
push_op(@ins, 'isfalse_s', $not_reg, $val.result_reg);
120
MAST::InstructionList.new(@ins, $not_reg, $MVM_reg_int64)
123
nqp::die("This case of nqp falsey op NYI");
127
# NQP object unbox, which also must somewhat handle coercion.
131
sub push_op(@dest, $op, *@args) {
132
#$op := $op.name if nqp::istype($op, QAST::Op);
133
nqp::push(@dest, MAST::Op.new(