Permalink
Browse files

Merge branch 'm0' of github.com:parrot/parrot into m0

Conflicts:
	src/m0/c/m0_ops.c
  • Loading branch information...
2 parents 3c62ec9 + 2a1224a commit 405d94d4d97f93f4569438bd4b63eb36b6fe2130 Jimmy Zhuo committed Apr 2, 2012
@@ -44,5 +44,16 @@ enum CF_NAMED_REGS {
SPILLCF
};
+typedef enum {
+ INVALID,
+ NAMED,
+ INTEGER,
+ NUMBER,
+ STRING,
+ POINTER
+} M0_RegisterType;
+
+
+
# define M0_INTERP_STRUCTURES_H 1
#endif
View
@@ -304,11 +304,14 @@ read_from_stream( FILE *stream, size_t bytes ) {
else {
void *data = malloc( bytes );
+fprintf(stdout, "M %d\n", *(int *)data);
+//fprintf(stdout, "M %.15g\n", *(double*)data);
if (fread(data, 1, bytes, stream) != bytes) {
free( data );
return NULL;
}
-
+//fprintf(stdout, "A %.15g\n", * (double *)data);
+fprintf(stdout, "A %d\n", * (int *)data);
return data;
}
}
View
@@ -91,13 +91,18 @@ m0_op_sub_n( M0_CallFrame *frame, const unsigned char *ops )
static void
m0_op_convert_n_i( M0_CallFrame *frame, const unsigned char *ops )
{
- frame->registers[ops[1]] = (double)(frame->registers[ops[2]]);
+ int64_t *r2 = (int64_t*) &(frame->registers[ops[2]]);
+ float *r1 = (float*) &(frame->registers[ops[1]]);
+ frame->registers[ops[1]] = (uint64_t)0;
+ *r1 = (*r2);
}
static void
m0_op_convert_i_n( M0_CallFrame *frame, const unsigned char *ops )
{
- frame->registers[ops[1]] = (int)(frame->registers[ops[2]]);
+ float *r2 = (float*) &(frame->registers[ops[2]]);
+ int64_t *r1 = (int64_t*) &(frame->registers[ops[1]]);
+ *r1 = *r2;
}
static void
@@ -121,20 +126,50 @@ m0_op_mult_i( M0_CallFrame *frame, const unsigned char *ops )
}
static void
+m0_op_mult_n( M0_CallFrame *frame, const unsigned char *ops )
+{
+ float *r2 = (float*) &(frame->registers[ops[2]]);
+ float *r3 = (float*) &(frame->registers[ops[3]]);
+ float *result = (float*) &(frame->registers[ops[1]]);
+ frame->registers[ops[1]] = (uint64_t)0;
+ *result = *r2 * *r3;
+}
+
+static void
m0_op_div_i( M0_CallFrame *frame, const unsigned char *ops )
{
frame->registers[ops[1]] = frame->registers[ops[2]] /
frame->registers[ops[3]];
}
static void
+m0_op_div_n( M0_CallFrame *frame, const unsigned char *ops )
+{
+ float *r2 = (float*) &(frame->registers[ops[2]]);
+ float *r3 = (float*) &(frame->registers[ops[3]]);
+ float *result = (float*) &(frame->registers[ops[1]]);
+ frame->registers[ops[1]] = (uint64_t)0;
+ *result = *r2 / *r3;
+}
+
+static void
m0_op_mod_i( M0_CallFrame *frame, const unsigned char *ops )
{
frame->registers[ops[1]] = frame->registers[ops[2]] %
frame->registers[ops[3]];
}
static void
+m0_op_mod_n( M0_CallFrame *frame, const unsigned char *ops )
+{
+ float *r2 = (float*) &(frame->registers[ops[2]]);
+ float *r3 = (float*) &(frame->registers[ops[3]]);
+ float *result = (float*) &(frame->registers[ops[1]]);
+ frame->registers[ops[1]] = (uint64_t)0;
+ *result = (int)(*r2) % (int)(*r3);
+}
+
+static void
m0_op_and( M0_CallFrame *frame, const unsigned char *ops )
{
frame->registers[ops[1]] = frame->registers[ops[2]] &
@@ -213,6 +248,12 @@ m0_op_set_byte( M0_CallFrame *frame, const unsigned char *ops )
}
static void
+m0_op_set( M0_CallFrame *frame, const unsigned char *ops )
+{
+ frame->registers[ops[1]] = frame->registers[ops[2]];
+}
+
+static void
m0_op_get_byte( M0_CallFrame *frame, const unsigned char *ops )
{
const char *src = (char*)frame->registers[ops[3]];
@@ -292,14 +333,26 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
m0_op_mult_i( cf, &ops[pc] );
break;
+ case (M0_MULT_N):
+ m0_op_mult_n( cf, &ops[pc] );
+ break;
+
case (M0_DIV_I):
m0_op_div_i( cf, &ops[pc] );
break;
+ case (M0_DIV_N):
+ m0_op_div_n( cf, &ops[pc] );
+ break;
+
case (M0_MOD_I):
m0_op_mod_i( cf, &ops[pc] );
break;
+ case (M0_MOD_N):
+ m0_op_mod_n( cf, &ops[pc] );
+ break;
+
case (M0_AND):
m0_op_and( cf, &ops[pc] );
break;
@@ -332,6 +385,10 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
m0_op_set_byte( cf, &ops[pc] );
break;
+ case (M0_SET):
+ m0_op_set( cf, &ops[pc] );
+ break;
+
case (M0_GET_BYTE):
m0_op_get_byte( cf, &ops[pc] );
break;
@@ -18,16 +18,16 @@
set_imm I3, 0, 8
sub_i I3, I3, I2
- goto_if xor_nok, I3
- goto xor_ok, x
+ goto_if and_nok, I3
+ goto and_ok, x
-xor_ok:
- set_imm S0, 0, 2
+and_nok:
+ set_imm S0, 0, 1
deref S0, CONSTS, S0
print_s I0, S0, x
-xor_nok:
- set_imm S0, 0, 1
+and_ok:
+ set_imm S0, 0, 2
deref S0, CONSTS, S0
print_s I0, S0, x
@@ -18,7 +18,7 @@
set_imm N1, 0, 99
sub_n N0, N0, N1
- goto_if deref_nok, I3
+ goto_if deref_nok, N0
goto deref_ok, x
deref_nok:
@@ -21,13 +21,13 @@
goto_if lshr_nok, I3
goto lshr_ok, x
-lshr_ok:
- set_imm S0, 0, 2
+lshr_nok:
+ set_imm S0, 0, 1
deref S0, CONSTS, S0
print_s I0, S0, x
-lshr_nok:
- set_imm S0, 0, 1
+lshr_ok:
+ set_imm S0, 0, 2
deref S0, CONSTS, S0
print_s I0, S0, x
@@ -18,16 +18,16 @@
set_imm I3, 0, 91
sub_i I3, I3, I2
- goto_if xor_nok, I3
- goto xor_ok, x
+ goto_if or_nok, I3
+ goto or_ok, x
-xor_ok:
- set_imm S0, 0, 2
+or_nok:
+ set_imm S0, 0, 1
deref S0, CONSTS, S0
print_s I0, S0, x
-xor_nok:
- set_imm S0, 0, 1
+or_ok:
+ set_imm S0, 0, 2
deref S0, CONSTS, S0
print_s I0, S0, x
@@ -21,13 +21,13 @@
goto_if shl_nok, I3
goto shl_ok, x
-shl_ok:
- set_imm S0, 0, 2
+shl_nok:
+ set_imm S0, 0, 1
deref S0, CONSTS, S0
print_s I0, S0, x
-shl_nok:
- set_imm S0, 0, 1
+shl_ok:
+ set_imm S0, 0, 2
deref S0, CONSTS, S0
print_s I0, S0, x
@@ -21,13 +21,13 @@
goto_if xor_nok, I3
goto xor_ok, x
-xor_ok:
- set_imm S0, 0, 2
+xor_nok:
+ set_imm S0, 0, 1
deref S0, CONSTS, S0
print_s I0, S0, x
-xor_nok:
- set_imm S0, 0, 1
+xor_ok:
+ set_imm S0, 0, 2
deref S0, CONSTS, S0
print_s I0, S0, x

0 comments on commit 405d94d

Please sign in to comment.