Skip to content

Commit

Permalink
added assign and assignunchecked ops
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuomingliang committed Jul 17, 2013
1 parent 5dc5893 commit c5b1e85
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
14 changes: 14 additions & 0 deletions lib/MAST/Ops.nqp
Expand Up @@ -1324,6 +1324,20 @@ class MAST::Ops {
$MVM_operand_write_reg +| $MVM_operand_int64,
$MVM_operand_read_reg +| $MVM_operand_num64
]
),
'assign', nqp::hash(
'code', 174,
'operands', [
$MVM_operand_read_reg +| $MVM_operand_obj,
$MVM_operand_read_reg +| $MVM_operand_obj
]
),
'assignunchecked', nqp::hash(
'code', 175,
'operands', [
$MVM_operand_read_reg +| $MVM_operand_obj,
$MVM_operand_read_reg +| $MVM_operand_obj
]
)
],
[
Expand Down
2 changes: 2 additions & 0 deletions nqp-cc/src/QASTOperationsMAST.nqp
Expand Up @@ -1591,6 +1591,8 @@ QAST::MASTOperations.add_core_moarop_mapping('settypecache', 'settypecache', 0);
QAST::MASTOperations.add_core_moarop_mapping('isinvokable', 'isinvokable');
QAST::MASTOperations.add_core_moarop_mapping('setinvokespec', 'setinvokespec', 0);
QAST::MASTOperations.add_core_moarop_mapping('setcontspec', 'setcontspec', 0);
QAST::MASTOperations.add_core_moarop_mapping('assign', 'assign', 0);
QAST::MASTOperations.add_core_moarop_mapping('assignunchecked', 'assignunchecked', 0);

# defined - overridden by HLL, but by default same as .DEFINITE.
QAST::MASTOperations.add_core_moarop_mapping('defined', 'isconcrete');
Expand Down
52 changes: 38 additions & 14 deletions src/core/interp.c
Expand Up @@ -1007,24 +1007,48 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
cur_op += 6;
break;
}
case MVM_OP_ceil_n:
{
MVMnum64 num = GET_REG(cur_op, 2).n64;
MVMint64 abs = (MVMint64)num;
if (num > abs) num = ++abs;
GET_REG(cur_op, 0).i64 = num;
cur_op += 4;
case MVM_OP_ceil_n:{
MVMnum64 num = GET_REG(cur_op, 2).n64;
MVMint64 abs = (MVMint64)num;
if (num > abs) num = ++abs;
GET_REG(cur_op, 0).i64 = num;
cur_op += 4;
break;
}
case MVM_OP_floor_n: {
MVMnum64 num = GET_REG(cur_op, 2).n64;
MVMint64 abs = (MVMint64)num;
if (num < abs) num = --abs;
GET_REG(cur_op, 0).i64 = num;
cur_op += 4;
break;
}
case MVM_OP_assign: {
MVMObject *cont = GET_REG(cur_op, 0).o;
MVMRegister value;
MVMContainerSpec *spec = STABLE(cont)->container_spec;
if (spec) {
DECONT(tc, GET_REG(cur_op, 2).o, value);
spec->store(tc, cont, value.o);
} else {
MVM_exception_throw_adhoc(tc, "Cannot assign to an immutable value");
}
cur_op += 4;
break;
case MVM_OP_floor_n:
{
MVMnum64 num = GET_REG(cur_op, 2).n64;
MVMint64 abs = (MVMint64)num;
if (num < abs) num = --abs;
GET_REG(cur_op, 0).i64 = num;
cur_op += 4;
}
case MVM_OP_assignunchecked: {
MVMObject *cont = GET_REG(cur_op, 0).o;
MVMRegister value;
MVMContainerSpec *spec = STABLE(cont)->container_spec;
if (spec) {
DECONT(tc, GET_REG(cur_op, 2).o, value);
spec->store_unchecked(tc, cont, value.o);
} else {
MVM_exception_throw_adhoc(tc, "Cannot assign to an immutable value");
}
cur_op += 4;
break;
}
default: {
MVM_panic(MVM_exitcode_invalidopcode, "Invalid opcode executed (corrupt bytecode stream?) bank %u opcode %u",
MVM_OP_BANK_primitives, *(cur_op-1));
Expand Down
2 changes: 2 additions & 0 deletions src/core/oplist
Expand Up @@ -173,6 +173,8 @@ BANK 0 primitives
0xAB lexprimspec w(int64) r(obj) r(str)
0xAC ceil_n w(int64) r(num64)
0xAD floor_n w(int64) r(num64)
0xAE assign r(obj) r(obj)
0xAF assignunchecked r(obj) r(obj)

BANK 1 dev
0x00 sleep r(int64)
Expand Down
14 changes: 13 additions & 1 deletion src/core/ops.c
Expand Up @@ -1052,6 +1052,18 @@ static MVMOpInfo MVM_op_info_primitives[] = {
2,
{ MVM_operand_write_reg | MVM_operand_int64, MVM_operand_read_reg | MVM_operand_num64 }
},
{
MVM_OP_assign,
"assign",
2,
{ MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj }
},
{
MVM_OP_assignunchecked,
"assignunchecked",
2,
{ MVM_operand_read_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj }
},
};
static MVMOpInfo MVM_op_info_dev[] = {
{
Expand Down Expand Up @@ -3125,7 +3137,7 @@ static MVMOpInfo *MVM_op_info[] = {
static unsigned char MVM_op_banks = 8;

static unsigned char MVM_opcounts_by_bank[] = {
174,
176,
2,
52,
55,
Expand Down
2 changes: 2 additions & 0 deletions src/core/ops.h
Expand Up @@ -185,6 +185,8 @@
#define MVM_OP_lexprimspec 171
#define MVM_OP_ceil_n 172
#define MVM_OP_floor_n 173
#define MVM_OP_assign 174
#define MVM_OP_assignunchecked 175

/* Op name defines for bank dev. */
#define MVM_OP_sleep 0
Expand Down

0 comments on commit c5b1e85

Please sign in to comment.