Skip to content
Permalink
Browse files

Remove p6bool extop

  • Loading branch information...
niner committed Aug 14, 2018
1 parent 170ffd4 commit 7e69c6408bf390336672b1ae1fda9d6528c02e91
Showing with 18 additions and 63 deletions.
  1. +2 −48 src/vm/moar/Perl6/Ops.nqp
  2. +16 −15 src/vm/moar/ops/perl6_ops.c
@@ -26,9 +26,9 @@ use MASTNodes;
MAST::ExtOpRegistry.register_extop('p6init');
MAST::ExtOpRegistry.register_extop('p6settypes',
$MVM_operand_obj +| $MVM_operand_read_reg);
MAST::ExtOpRegistry.register_extop('p6bool',
MAST::ExtOpRegistry.register_extop('p6reprname',
$MVM_operand_obj +| $MVM_operand_write_reg,
$MVM_operand_int64 +| $MVM_operand_read_reg);
$MVM_operand_obj +| $MVM_operand_read_reg);
MAST::ExtOpRegistry.register_extop('p6capturelex',
$MVM_operand_obj +| $MVM_operand_write_reg,
$MVM_operand_obj +| $MVM_operand_read_reg);
@@ -256,51 +256,6 @@ $ops.add_hll_moarop_mapping('perl6', 'p6finddispatcher', 'p6finddispatcher');
$ops.add_hll_moarop_mapping('perl6', 'p6argsfordispatcher', 'p6argsfordispatcher');
$ops.add_hll_moarop_mapping('perl6', 'p6decodelocaltime', 'p6decodelocaltime');
$ops.add_hll_moarop_mapping('perl6', 'p6staticouter', 'p6staticouter');
my $p6bool := -> $qastcomp, $op {
# We never want a container here, so mark as decont context.
my @ops;
my $exprres := $qastcomp.as_mast($op[0], :want-decont);
push_ilist(@ops, $exprres);

# Go by result kind.
my $res_reg := $*REGALLOC.fresh_o();
my $cond_kind := $exprres.result_kind;
if $cond_kind == $MVM_reg_int64 {
nqp::push(@ops, MAST::ExtOp.new( :op('p6bool'), :cu($qastcomp.mast_compunit),
$res_reg, $exprres.result_reg ));
}
elsif $cond_kind == $MVM_reg_num64 {
my $tmp_reg := $*REGALLOC.fresh_i();
my $zero_reg := $*REGALLOC.fresh_n();
nqp::push(@ops, MAST::Op.new( :op('const_n64'), $zero_reg, MAST::NVal.new( :value(0.0) ) ));
nqp::push(@ops, MAST::Op.new( :op('eq_n'), $tmp_reg, $exprres.result_reg, $zero_reg ));
nqp::push(@ops, MAST::ExtOp.new( :op('p6bool'), :cu($qastcomp.mast_compunit),
$res_reg, $tmp_reg ));
$*REGALLOC.release_register($zero_reg, $MVM_reg_num64);
$*REGALLOC.release_register($tmp_reg, $MVM_reg_int64);
}
elsif $cond_kind == $MVM_reg_str {
my $tmp_reg := $*REGALLOC.fresh_i();
nqp::push(@ops, MAST::Op.new( :op('istrue_s'), $tmp_reg, $exprres.result_reg ));
nqp::push(@ops, MAST::ExtOp.new( :op('p6bool'), :cu($qastcomp.mast_compunit),
$res_reg, $tmp_reg ));
$*REGALLOC.release_register($tmp_reg, $MVM_reg_int64);
}
elsif $cond_kind == $MVM_reg_obj {
my $tmp_reg := $*REGALLOC.fresh_i();
nqp::push(@ops, MAST::Op.new( :op('decont'), $res_reg, $exprres.result_reg ));
nqp::push(@ops, MAST::Op.new( :op('istrue'), $tmp_reg, $res_reg ));
nqp::push(@ops, MAST::ExtOp.new( :op('p6bool'), :cu($qastcomp.mast_compunit),
$res_reg, $tmp_reg ));
$*REGALLOC.release_register($tmp_reg, $MVM_reg_int64);
}
else {
nqp::die('Unknown register type in p6bool');
}
$*REGALLOC.release_register($exprres.result_reg, $exprres.result_kind);
MAST::InstructionList.new(@ops, $res_reg, $MVM_reg_obj)
};
$ops.add_hll_op('perl6', 'p6bool', $p6bool);
$ops.add_hll_op('perl6', 'p6invokehandler', -> $qastcomp, $op {
$qastcomp.as_mast(QAST::Op.new( :op('call'), $op[0], $op[1] ));
});
@@ -347,7 +302,6 @@ $ops.add_hll_op('perl6', 'p6sink', -> $qastcomp, $op {

# Make some of them also available from NQP land, since we use them in the
# metamodel and bootstrap.
$ops.add_hll_op('nqp', 'p6bool', $p6bool);
$ops.add_hll_moarop_mapping('nqp', 'p6init', 'p6init');
$ops.add_hll_moarop_mapping('nqp', 'p6settypes', 'p6settypes', 0);
$ops.add_hll_moarop_mapping('nqp', 'p6inpre', 'p6inpre');
@@ -44,8 +44,6 @@ static int initialized = 0;
/* Types we need. */
static MVMObject *Mu = NULL;
static MVMObject *Any = NULL;
static MVMObject *True = NULL;
static MVMObject *False = NULL;

/* Useful string constants. */
static MVMString *str_dispatcher = NULL;
@@ -82,8 +80,6 @@ static void p6settypes(MVMThreadContext *tc, MVMuint8 *cur_op) {
MVMROOT(tc, conf, {
get_type(tc, conf, "Mu", Mu);
get_type(tc, conf, "Any", Any);
get_type(tc, conf, "True", True);
get_type(tc, conf, "False", False);
});

/* Strings. */
@@ -106,19 +102,24 @@ static void discover_create(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns
tfacts->type = type;
}

/* Turns zero to False and non-zero to True. */
static MVMuint8 s_p6bool[] = {
static MVMuint8 s_p6reprname[] = {
MVM_operand_obj | MVM_operand_write_reg,
MVM_operand_int64 | MVM_operand_read_reg,
MVM_operand_obj | MVM_operand_read_reg,
};
static void p6bool(MVMThreadContext *tc, MVMuint8 *cur_op) {
GET_REG(tc, 0).o = GET_REG(tc, 2).i64 ? True : False;
static void p6reprname(MVMThreadContext *tc, MVMuint8 *cur_op) {
MVMObject *obj = GET_REG(tc, 2).o;
MVMROOT(tc, obj, {
MVMObject *name = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTStr);
MVMROOT(tc, name, {
MVMString *str = MVM_string_utf8_decode(tc, tc->instance->VMString,
obj->st->REPR->name, strlen(obj->st->REPR->name));
MVM_repr_set_str(tc, name, str);
GET_REG(tc, 0).o = name;
});
});
}
static void p6bool_discover(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
discover_create(tc, g, ins, STABLE(True)->WHAT);
#ifdef MVM_SPESH_FACT_KNOWN_BOX_SRC
MVM_spesh_get_facts(tc, g, ins->operands[0])->flags |= MVM_SPESH_FACT_KNOWN_BOX_SRC;
#endif
static void p6reprname_discover(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
discover_create(tc, g, ins, tc->instance->boot_types.BOOTStr);
}

static MVMuint8 s_p6capturelex[] = {
@@ -483,7 +484,7 @@ static void p6invokeunder(MVMThreadContext *tc, MVMuint8 *cur_op) {
MVM_DLL_EXPORT void Rakudo_ops_init(MVMThreadContext *tc) {
MVM_ext_register_extop(tc, "p6init", p6init, 0, NULL, NULL, NULL, 0);
MVM_ext_register_extop(tc, "p6settypes", p6settypes, 1, s_p6settypes, NULL, NULL, 0);
MVM_ext_register_extop(tc, "p6bool", p6bool, 2, s_p6bool, NULL, p6bool_discover, MVM_EXTOP_PURE);
MVM_ext_register_extop(tc, "p6reprname", p6reprname, 2, s_p6reprname, NULL, p6reprname_discover, MVM_EXTOP_PURE | MVM_EXTOP_ALLOCATING);
MVM_ext_register_extop(tc, "p6capturelex", p6capturelex, 2, s_p6capturelex, NULL, NULL, 0);
MVM_ext_register_extop(tc, "p6capturelexwhere", p6capturelexwhere, 2, s_p6capturelexwhere, NULL, NULL, 0);
MVM_ext_register_extop(tc, "p6getouterctx", p6getouterctx, 2, s_p6getouterctx, NULL, NULL, MVM_EXTOP_PURE | MVM_EXTOP_ALLOCATING);

0 comments on commit 7e69c64

Please sign in to comment.
You can’t perform that action at this time.