mirror of
https://github.com/louisrubet/rpn
synced 2025-01-05 11:01:52 +01:00
#34: update test commands
This commit is contained in:
parent
a3e13d2823
commit
f43bd3f9d9
3 changed files with 153 additions and 106 deletions
|
@ -20,20 +20,30 @@ void bin()
|
||||||
|
|
||||||
void rtob()
|
void rtob()
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(1);
|
||||||
//MIN_ARGUMENTS(1);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
||||||
|
|
||||||
//binary bin;
|
number* left = (number*)_stack->back();
|
||||||
//bin.set(((integer_t)getf()));
|
_stack->pop_back();
|
||||||
//_stack->push_back(&bin, bin.size(), cmd_binary);
|
|
||||||
|
cout<<"TODO"<<endl;
|
||||||
|
|
||||||
|
binary bin;
|
||||||
|
bin._value = mpfr_get_sj(&left->_value.mpfr, s_mpfr_rnd);
|
||||||
|
_stack->push_back(&bin, bin.size(), cmd_binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
void btor()
|
void btor()
|
||||||
{
|
{
|
||||||
// TODO
|
MIN_ARGUMENTS(1);
|
||||||
//MIN_ARGUMENTS(1);
|
ARG_MUST_BE_OF_TYPE(0, cmd_binary);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_binary);
|
|
||||||
|
|
||||||
//putf((floating_t)getb());
|
integer_t bin = getb();
|
||||||
|
|
||||||
|
cout<<"TODO"<<endl;
|
||||||
|
|
||||||
|
_stack->push_back(NULL, sizeof(number), cmd_number, true);
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
left->_value = bin;
|
||||||
|
left->ensure_significand();
|
||||||
}
|
}
|
||||||
|
|
211
src/rpn-test.h
211
src/rpn-test.h
|
@ -1,142 +1,171 @@
|
||||||
|
//TODO must work with binary, ostring (others ?)
|
||||||
|
|
||||||
void sup(void)
|
void sup(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//putf(getf() > first);
|
_stack->pop_back();
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) > 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sup_eq(void)
|
void sup_eq(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//putf(getf() >= first);
|
_stack->pop_back();
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) >= 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inf(void)
|
void inf(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//putf(getf() < first);
|
_stack->pop_back();
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) < 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inf_eq(void)
|
void inf_eq(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//putf(getf() <= first);
|
_stack->pop_back();
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) <= 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void diff(void)
|
void diff(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//putf(getf() != first);
|
_stack->pop_back();
|
||||||
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) != 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eq(void)
|
void eq(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//int type = _stack->get_type(0);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
|
|
||||||
//if (_stack->get_type(1) == type)
|
number* right = (number*)_stack->back();
|
||||||
//{
|
_stack->pop_back();
|
||||||
// switch(type)
|
number* left = (number*)_stack->back();
|
||||||
// {
|
|
||||||
// case cmd_number:
|
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) == 0)
|
||||||
// {
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
// floating_t first = getf();
|
else
|
||||||
// putf(getf() == first);
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
//TODO
|
|
||||||
#if 0
|
|
||||||
case cmd_symbol:
|
|
||||||
{
|
|
||||||
string first = getn();
|
|
||||||
putf(getn() == first);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// _stack->pop_back();
|
|
||||||
// _stack->pop_back();
|
|
||||||
// putf(0);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// _stack->pop_back();
|
|
||||||
// _stack->pop_back();
|
|
||||||
// putf(0);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_and(void)
|
void test_and(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//floating_t second = getf();
|
_stack->pop_back();
|
||||||
//putf((first != 0) && (second != 0));
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if ((mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
|
||||||
|
&& (mpfr_cmp_si(&right->_value.mpfr, 0) == 0))
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_or(void)
|
void test_or(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//floating_t second = getf();
|
_stack->pop_back();
|
||||||
//putf((first != 0) || (second != 0));
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if ((mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
|
||||||
|
|| (mpfr_cmp_si(&right->_value.mpfr, 0) == 0))
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_xor(void)
|
void test_xor(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(2);
|
||||||
//MIN_ARGUMENTS(2);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* right = (number*)_stack->back();
|
||||||
//floating_t second = getf();
|
_stack->pop_back();
|
||||||
//putf(((first == 0) && (second != 0)) || ((first != 0) && (second == 0)));
|
number* left = (number*)_stack->back();
|
||||||
|
|
||||||
|
if (mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
|
||||||
|
{
|
||||||
|
if (mpfr_cmp_si(&right->_value.mpfr, 0) != 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mpfr_cmp_si(&right->_value.mpfr, 0) == 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_not(void)
|
void test_not(void)
|
||||||
{
|
{
|
||||||
//TODO
|
MIN_ARGUMENTS(1);
|
||||||
//MIN_ARGUMENTS(1);
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||||
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
||||||
|
|
||||||
//floating_t first = getf();
|
number* left = (number*)_stack->back();
|
||||||
//putf((first == 0) ? 1 : 0);
|
if (mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
|
||||||
|
else
|
||||||
|
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void same(void)
|
void same(void)
|
||||||
|
|
18
src/rpn.cpp
18
src/rpn.cpp
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h> //for intmax_t
|
||||||
#include <mpfr.h>
|
#include <mpfr.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -99,6 +100,8 @@ const char* cmd_type_string[cmd_max] = {
|
||||||
"undef", "number", "binary", "string", "symbol", "program", "keyword", "keyword"
|
"undef", "number", "binary", "string", "symbol", "program", "keyword", "keyword"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef long long integer_t;
|
||||||
|
|
||||||
// MPFR object
|
// MPFR object
|
||||||
struct floating_t
|
struct floating_t
|
||||||
{
|
{
|
||||||
|
@ -111,13 +114,20 @@ struct floating_t
|
||||||
mpfr_custom_init_set(&mpfr, MPFR_NAN_KIND, 0, s_mpfr_prec, significand);
|
mpfr_custom_init_set(&mpfr, MPFR_NAN_KIND, 0, s_mpfr_prec, significand);
|
||||||
}
|
}
|
||||||
|
|
||||||
floating_t operator=(const long int val)
|
floating_t& operator=(const long int val)
|
||||||
{
|
{
|
||||||
mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH);
|
mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH);
|
||||||
mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand);
|
mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand);
|
||||||
mpfr_set_si(&mpfr, val, s_mpfr_rnd);
|
mpfr_set_si(&mpfr, val, s_mpfr_rnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
floating_t& operator=(const integer_t val)
|
||||||
|
{
|
||||||
|
mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH);
|
||||||
|
mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand);
|
||||||
|
mpfr_set_sj(&mpfr, val, s_mpfr_rnd);
|
||||||
|
}
|
||||||
|
|
||||||
operator int()
|
operator int()
|
||||||
{
|
{
|
||||||
return (int)mpfr_get_si(&mpfr, s_mpfr_rnd);
|
return (int)mpfr_get_si(&mpfr, s_mpfr_rnd);
|
||||||
|
@ -139,8 +149,6 @@ struct floating_t
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef long long integer_t;
|
|
||||||
|
|
||||||
class program;
|
class program;
|
||||||
class object;
|
class object;
|
||||||
class branch;
|
class branch;
|
||||||
|
@ -344,8 +352,8 @@ struct branch : public object
|
||||||
arg1 = -1;
|
arg1 = -1;
|
||||||
arg2 = -1;
|
arg2 = -1;
|
||||||
arg3 = -1;
|
arg3 = -1;
|
||||||
farg1 = 0;
|
farg1 = 0L;
|
||||||
farg2 = 0;
|
farg2 = 0L;
|
||||||
arg_bool = 0;
|
arg_bool = 0;
|
||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue