Permalink
Browse files

Increment PC by 1 instead of 4 in m0_poke_caller and c implementation

Undo workaround for the m0 c implementation. This allows the c and perl
implementations to both pass the m0_poke_caller test.
  • Loading branch information...
1 parent 6a75a09 commit fa5c366a7384acafbf59f3a631613af1a23534f0 @nbrown nbrown committed Apr 25, 2012
Showing with 42 additions and 42 deletions.
  1. +39 −39 src/m0/c/m0_ops.c
  2. +3 −3 t/m0/integration/m0_poke_caller.m0
View
@@ -113,14 +113,14 @@ m0_op_convert_i_n( M0_CallFrame *frame, const unsigned char *ops )
static void
m0_op_goto( M0_CallFrame *frame, const unsigned char *ops )
{
- frame->registers[PC] = 4*(256 * ops[1] + ops[2]);
+ frame->registers[PC] = 256 * ops[1] + ops[2];
}
static void
m0_op_goto_if( M0_CallFrame *frame, const unsigned char *ops )
{
if( frame->registers[ops[3]] )
- frame->registers[PC] = 4*(256 * ops[1] + ops[2]);
+ frame->registers[PC] = 256 * ops[1] + ops[2];
}
static void
@@ -320,156 +320,156 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
const unsigned long op_count = bytecode->op_count;
/* XXX: access violation -- so produce an error? */
- if (pc / 4 >= op_count)
+ if (pc >= op_count)
return 0;
else {
- const unsigned char op = ops[pc];
+ const unsigned char op = ops[4*pc];
switch (op) {
case (M0_SET_IMM):
- m0_op_set_imm( cf, &ops[pc] );
+ m0_op_set_imm( cf, &ops[4*pc] );
break;
case (M0_DEREF):
- m0_op_deref( cf, &ops[pc] );
+ m0_op_deref( cf, &ops[4*pc] );
break;
case (M0_PRINT_S):
- m0_op_print_s( cf, &ops[pc] );
+ m0_op_print_s( cf, &ops[4*pc] );
break;
case (M0_PRINT_I):
- m0_op_print_i( cf, &ops[pc] );
+ m0_op_print_i( cf, &ops[4*pc] );
break;
case (M0_NOOP):
break;
case (M0_ADD_I):
- m0_op_add_i( cf, &ops[pc] );
+ m0_op_add_i( cf, &ops[4*pc] );
break;
case (M0_ADD_N):
- m0_op_add_n( cf, &ops[pc] );
+ m0_op_add_n( cf, &ops[4*pc] );
break;
case (M0_SUB_I):
- m0_op_sub_i( cf, &ops[pc] );
+ m0_op_sub_i( cf, &ops[4*pc] );
break;
case (M0_SUB_N):
- m0_op_sub_n( cf, &ops[pc] );
+ m0_op_sub_n( cf, &ops[4*pc] );
break;
case (M0_GOTO):
- m0_op_goto( cf, &ops[pc] );
+ m0_op_goto( cf, &ops[4*pc] );
break;
case (M0_GOTO_IF):
- m0_op_goto_if( cf, &ops[pc] );
+ m0_op_goto_if( cf, &ops[4*pc] );
break;
case (M0_MULT_I):
- m0_op_mult_i( cf, &ops[pc] );
+ m0_op_mult_i( cf, &ops[4*pc] );
break;
case (M0_MULT_N):
- m0_op_mult_n( cf, &ops[pc] );
+ m0_op_mult_n( cf, &ops[4*pc] );
break;
case (M0_DIV_I):
- m0_op_div_i( cf, &ops[pc] );
+ m0_op_div_i( cf, &ops[4*pc] );
break;
case (M0_DIV_N):
- m0_op_div_n( cf, &ops[pc] );
+ m0_op_div_n( cf, &ops[4*pc] );
break;
case (M0_MOD_I):
- m0_op_mod_i( cf, &ops[pc] );
+ m0_op_mod_i( cf, &ops[4*pc] );
break;
case (M0_MOD_N):
- m0_op_mod_n( cf, &ops[pc] );
+ m0_op_mod_n( cf, &ops[4*pc] );
break;
case (M0_AND):
- m0_op_and( cf, &ops[pc] );
+ m0_op_and( cf, &ops[4*pc] );
break;
case (M0_OR):
- m0_op_or( cf, &ops[pc] );
+ m0_op_or( cf, &ops[4*pc] );
break;
case (M0_XOR):
- m0_op_xor( cf, &ops[pc] );
+ m0_op_xor( cf, &ops[4*pc] );
break;
case (M0_LSHR):
- m0_op_lshr( cf, &ops[pc] );
+ m0_op_lshr( cf, &ops[4*pc] );
break;
case (M0_ASHR):
- m0_op_ashr( cf, &ops[pc] );
+ m0_op_ashr( cf, &ops[4*pc] );
break;
case (M0_SHL):
- m0_op_shl( cf, &ops[pc] );
+ m0_op_shl( cf, &ops[4*pc] );
break;
case (M0_GOTO_CHUNK):
- m0_op_goto_chunk( cf, &ops[pc] );
+ m0_op_goto_chunk( cf, &ops[4*pc] );
break;
case (M0_SET_BYTE):
- m0_op_set_byte( cf, &ops[pc] );
+ m0_op_set_byte( cf, &ops[4*pc] );
break;
case (M0_SET_WORD):
- m0_op_set_word( cf, &ops[pc] );
+ m0_op_set_word( cf, &ops[4*pc] );
break;
case (M0_SET):
- m0_op_set( cf, &ops[pc] );
+ m0_op_set( cf, &ops[4*pc] );
break;
case (M0_GET_BYTE):
- m0_op_get_byte( cf, &ops[pc] );
+ m0_op_get_byte( cf, &ops[4*pc] );
break;
case (M0_GET_WORD):
- m0_op_get_word( cf, &ops[pc] );
+ m0_op_get_word( cf, &ops[4*pc] );
break;
case (M0_ITON):
- m0_op_convert_i_n( cf, &ops[pc] );
+ m0_op_convert_i_n( cf, &ops[4*pc] );
break;
case (M0_NTOI):
- m0_op_convert_n_i( cf, &ops[pc] );
+ m0_op_convert_n_i( cf, &ops[4*pc] );
break;
case (M0_GC_ALLOC):
- m0_op_gc_alloc( cf, &ops[pc]);
+ m0_op_gc_alloc( cf, &ops[4*pc]);
break;
case (M0_SET_REF):
- m0_op_set_ref( cf, &ops[pc]);
+ m0_op_set_ref( cf, &ops[4*pc]);
break;
case (M0_EXIT):
- m0_op_exit( cf, &ops[pc]);
+ m0_op_exit( cf, &ops[4*pc]);
break;
default:
fprintf( stderr, "Unimplemented op: %d (%d, %d, %d)\n",
- op, ops[pc + 1], ops[pc + 2], ops[pc + 3] );
+ op, ops[4*pc + 1], ops[4*pc + 2], ops[4*pc + 3] );
break;
}
}
cf = (M0_CallFrame*)cf->registers[CF];
/* only branching ops definitely change the pc */
if (pc == (const unsigned long)cf->registers[PC])
- cf->registers[PC] += 4;
+ cf->registers[PC]++;
}
return 0;
@@ -117,14 +117,14 @@ init_cf_retpc:
# 1 register needed
# Set the return PC for the current cf so that control flow will resume at
# the 'retpc' label.
- set_imm I13, 0, 40
+ set_imm I13, 0, 10
add_i RETPC, PC, I13
init_cf_pc:
# 3 register needed (2x I, 1x P)
# Set the new call frame's PC to the 'post_set' label so that when it's
# activated, control flow will continue as normal.
- set_imm I12, 0, 12
+ set_imm I12, 0, 3
add_i I12, I12, PC
set_imm I9, 0, PC
set_ref P0, I9, I12
@@ -161,7 +161,7 @@ restore_cf:
set_cf_pc:
# Set PCF[PC] to the invoke_cf + 1 so that when we invoke PCF with
# "set CF, PCF, x", control flow will continue at the next instruction.
- set_imm I1, 0, 20
+ set_imm I1, 0, 5
add_i I1, PC, I1
set_imm I9, 0, PC
set_ref PCF, I9, I1

0 comments on commit fa5c366

Please sign in to comment.