Skip to content

Commit

Permalink
add untested implementations of the comparison ops to c-m0 and p5-m0
Browse files Browse the repository at this point in the history
  • Loading branch information
cotto committed May 28, 2012
1 parent 44c0b79 commit a2cb0ea
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/m0/c/include/m0_ops.h
Expand Up @@ -17,6 +17,10 @@ enum M0_OPS {
M0_DIV_N, M0_DIV_N,
M0_MOD_I, M0_MOD_I,
M0_MOD_N, M0_MOD_N,
M0_ISGT_I,
M0_ISGT_N,
M0_ISGE_I,
M0_ISGE_N,
M0_ITON, M0_ITON,
M0_NTOI, M0_NTOI,
M0_ASHR, M0_ASHR,
Expand Down
52 changes: 52 additions & 0 deletions src/m0/c/m0_ops.c
Expand Up @@ -103,6 +103,42 @@ m0_op_sub_n( M0_CallFrame *frame, const unsigned char *ops )
*result = r2 - r3; *result = r2 - r3;
} }


static void
m0_op_isgt_i( M0_CallFrame *frame, const unsigned char *ops )
{
int64_t *r2 = (int64_t*) &(frame->registers[ops[2]]);
int64_t *r3 = (int64_t*) &(frame->registers[ops[3]]);
int64_t *r1 = (int64_t*) &(frame->registers[ops[1]]);
*r1 = *r2 > *r3;
}

static void
m0_op_isgt_n( M0_CallFrame *frame, const unsigned char *ops )
{
double *r2 = (double*) &(frame->registers[ops[2]]);
double *r3 = (double*) &(frame->registers[ops[3]]);
double *r1 = (double*) &(frame->registers[ops[1]]);
*r1 = *r2 > *r3;
}

static void
m0_op_isge_i( M0_CallFrame *frame, const unsigned char *ops )
{
int64_t *r2 = (int64_t*) &(frame->registers[ops[2]]);
int64_t *r3 = (int64_t*) &(frame->registers[ops[3]]);
int64_t *r1 = (int64_t*) &(frame->registers[ops[1]]);
*r1 = *r2 >= *r3;
}

static void
m0_op_isge_n( M0_CallFrame *frame, const unsigned char *ops )
{
double *r2 = (double*) &(frame->registers[ops[2]]);
double *r3 = (double*) &(frame->registers[ops[3]]);
double *r1 = (double*) &(frame->registers[ops[1]]);
*r1 = *r2 >= *r3;
}

static void static void
m0_op_convert_n_i( M0_CallFrame *frame, const unsigned char *ops ) m0_op_convert_n_i( M0_CallFrame *frame, const unsigned char *ops )
{ {
Expand Down Expand Up @@ -369,6 +405,22 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
M0_EXEC_OP(sub_n, cf, ops, pc); M0_EXEC_OP(sub_n, cf, ops, pc);
break; break;


case (M0_ISGT_I):
M0_EXEC_OP(isgt_i, cf, ops, pc);
break;

case (M0_ISGT_N):
M0_EXEC_OP(isgt_n, cf, ops, pc);
break;

case (M0_ISGE_I):
M0_EXEC_OP(isge_i, cf, ops, pc);
break;

case (M0_ISGE_N):
M0_EXEC_OP(isge_n, cf, ops, pc);
break;

case (M0_GOTO): case (M0_GOTO):
M0_EXEC_OP(goto, cf, ops, pc); M0_EXEC_OP(goto, cf, ops, pc);
break; break;
Expand Down
4 changes: 4 additions & 0 deletions src/m0/perl5/m0_assembler.pl
Expand Up @@ -664,6 +664,10 @@ sub parse_chunks {
div_n div_n
mod_i mod_i
mod_n mod_n
isgt_i
isgt_n
isge_i
isge_n
convert_i_n convert_i_n
convert_n_i convert_n_i
ashr ashr
Expand Down
33 changes: 33 additions & 0 deletions src/m0/perl5/m0_interp.pl
Expand Up @@ -18,6 +18,7 @@ =head1 DESCRIPTION
use strict; use strict;
use warnings FATAL => qw(all); use warnings FATAL => qw(all);
use feature 'say'; use feature 'say';
use IPC::System::Simple;
use autodie qw/:all/; use autodie qw/:all/;
use File::Slurp qw/slurp/; use File::Slurp qw/slurp/;
use Data::Dumper; use Data::Dumper;
Expand Down Expand Up @@ -117,6 +118,10 @@ sub new_interp {
\&m0_opfunc_div_n, \&m0_opfunc_div_n,
\&m0_opfunc_mod_i, \&m0_opfunc_mod_i,
\&m0_opfunc_mod_n, \&m0_opfunc_mod_n,
\&m0_opfunc_isgt_i,
\&m0_opfunc_isgt_n,
\&m0_opfunc_isge_i,
\&m0_opfunc_isge_n,
\&m0_opfunc_convert_i_n, \&m0_opfunc_convert_i_n,
\&m0_opfunc_convert_n_i, \&m0_opfunc_convert_n_i,
\&m0_opfunc_ashr, \&m0_opfunc_ashr,
Expand Down Expand Up @@ -378,6 +383,34 @@ sub m0_opfunc_mod_n {
$$cf->[$a1] = n( n($$cf,$a2) % n($$cf,$a3) ); $$cf->[$a1] = n( n($$cf,$a2) % n($$cf,$a3) );
} }


sub m0_opfunc_isgt_i {
my ($cf, $a1, $a2, $a3) = @_;
m0_say "isgt_i $a1, $a2, $a3";

$$cf->[$a1] = i( i($$cf,$a2) > i($$cf,$a3) );
}

sub m0_opfunc_isgt_n {
my ($cf, $a1, $a2, $a3) = @_;
m0_say "isgt_n $a1, $a2, $a3";

$$cf->[$a1] = n( n($$cf,$a2) > n($$cf,$a3) );
}

sub m0_opfunc_isge_i {
my ($cf, $a1, $a2, $a3) = @_;
m0_say "isge_i $a1, $a2, $a3";

$$cf->[$a1] = i( i($$cf,$a2) >= i($$cf,$a3) );
}

sub m0_opfunc_isge_n {
my ($cf, $a1, $a2, $a3) = @_;
m0_say "isge_n $a1, $a2, $a3";

$$cf->[$a1] = n( n($$cf,$a2) >= n($$cf,$a3) );
}

sub m0_opfunc_convert_i_n { sub m0_opfunc_convert_i_n {
my ($cf, $a1, $a2, $a3) = @_; my ($cf, $a1, $a2, $a3) = @_;
m0_say "convert_i_n $a1, $a2, $a3"; m0_say "convert_i_n $a1, $a2, $a3";
Expand Down
Binary file modified t/m0/basic/hello_canon.m0b
Binary file not shown.
2 changes: 1 addition & 1 deletion t/m0/m0_assembler.t
Expand Up @@ -74,7 +74,7 @@ output_like(


output_like( output_like(
$hello_m0, $hello_m0,
qr/Parsed data for 42 ops/, qr/Parsed data for 46 ops/,
'Parse data for the correct number of ops' 'Parse data for the correct number of ops'
); );


Expand Down

0 comments on commit a2cb0ea

Please sign in to comment.