#34: implemented binary, branch, general, stack and store commands

This commit is contained in:
Louis Rubet 2017-04-19 23:31:18 +02:00
parent 67403c56ff
commit 0f8f76f283
7 changed files with 47 additions and 23 deletions

View file

@ -26,10 +26,8 @@ void rtob()
number* left = (number*)_stack->back();
_stack->pop_back();
cout<<"TODO"<<endl;
binary bin;
bin._value = mpfr_get_sj(&left->_value.mpfr, s_mpfr_rnd);
bin.set(mpfr_get_sj(&left->_value.mpfr, s_mpfr_rnd));
_stack->push_back(&bin, bin.size(), cmd_binary);
}
@ -40,10 +38,7 @@ void btor()
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();
left->set(bin);
}

View file

@ -79,9 +79,9 @@ int rpn_for(branch& myobj)
myobj.farg1.ensure_significand();
// store symbol with first value
number num;
num.set(myobj.farg1);
_local_heap.add(string(sym->_value), &num, num.size(), cmd_number);
number* num = (number*)_local_heap.add(string(sym->_value), NULL, sizeof(number), cmd_number);
num->set(myobj.farg1);
num->ensure_significand();
return myobj.arg1 + 1;
}
@ -108,10 +108,11 @@ int rpn_next(branch& myobj)
unsigned int size;
int type;
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
// check symbol variable is a number, then increase
if (_local_heap.get(string(var->_value), obj, size, type) && (type == cmd_number))
{
((number*)obj)->_value = myobj.farg1;
((number*)obj)->set(myobj.farg1);
((number*)obj)->ensure_significand();
}
}
@ -139,6 +140,8 @@ int rpn_step(branch& myobj)
// arg1 = index of start or for command in program
// farg1 = current count
floating_t step = getf();
step.ensure_significand();
branch* start_or_for = (branch*)seq_obj(myobj.arg1);
if (! myobj.arg_bool)
{
@ -157,6 +160,7 @@ int rpn_step(branch& myobj)
unsigned int size;
int type;
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
// check symbol variable is a number, then increase
if (_local_heap.get(string(var->_value), obj, size, type) && (type == cmd_number))
{

View file

@ -15,7 +15,11 @@ void verbose()
{
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
g_verbose = int(getf());
int verbose = int(((number*)_stack->back())->_value);
_stack->pop_back();
g_verbose = verbose;
}
void help()
@ -75,7 +79,10 @@ void std()
if (stack_size()>=1)
{
ARG_MUST_BE_OF_TYPE(0, cmd_number);
number::s_default_precision = int(getf());
int precision = int(((number*)_stack->back())->_value);
_stack->pop_back();
number::s_default_precision = int(precision);
}
number::s_current_precision = number::s_default_precision;
@ -92,7 +99,10 @@ void fix()
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
number::s_current_precision = int(getf());
int precision = int(((number*)_stack->back())->_value);
_stack->pop_back();
number::s_current_precision = int(precision);
number::s_mode = number::fix;
// format for mpfr_printf
@ -106,7 +116,10 @@ void sci()
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
number::s_current_precision = (int)getf();
int precision = int(((number*)_stack->back())->_value);
_stack->pop_back();
number::s_current_precision = int(precision);
number::s_mode = number::sci;
// format for mpfr_printf

View file

@ -48,7 +48,10 @@ void dup2(void)
void pick(void)
{
MIN_ARGUMENTS(1);
unsigned int to_pick = (unsigned int)getf();
ARG_MUST_BE_OF_TYPE(0, cmd_number);
unsigned int to_pick = (unsigned int)int(((number*)_stack->back())->_value);
_stack->pop_back();
// treat stack depth errors
if ((to_pick == 0) || (to_pick > _stack->size()))

View file

@ -84,9 +84,9 @@ void auto_rcl(symbol* symb)
{
_stack->push_back(obj, size, type);
if (type == cmd_program)
{
eval();
}
else if (type == cmd_number)
((number*)_stack->back())->ensure_significand();
}
else
_stack->push_back(symb, symb->size(), cmd_symbol);

View file

@ -185,7 +185,12 @@ struct number : public object
void set(long value)
{
_type = cmd_number;
_value = (long)value;
_value = value;
}
void set(integer_t value)
{
_type = cmd_number;
_value = value;
}
unsigned int size() { return (unsigned int)sizeof(floating_t); }
@ -481,7 +486,7 @@ public:
}
// could be an auto-evaluated symbol
if (type == cmd_symbol)
else if (type == cmd_symbol)
{
auto_rcl((symbol*)seq_obj(i));
i++;

View file

@ -186,7 +186,7 @@ public:
free(i->second);
}
void add(const string name, void* obj, unsigned int size, int type = 0)
void* add(const string name, void* obj, unsigned int size, int type = 0)
{
struct local_var* blob = _map[name];
if (blob == NULL)
@ -203,9 +203,13 @@ public:
}
blob->length = size;
blob->type= type;
memcpy(&blob->blob, obj, size);
}
if (obj != NULL)
memcpy(&blob->blob, obj, size);
return (void*)&blob->blob;
}
bool get(const string name, void*& obj, unsigned int& size, int& type)
{
map<string, struct local_var*>::iterator i = _map.find(name);