#139: stack::pop_back() has a new parameter to pop several levels

This commit is contained in:
Louis Rubet 2017-06-18 22:11:15 +02:00
parent c62a48ed92
commit 0b54fbca38
6 changed files with 32 additions and 53 deletions

View file

@ -89,17 +89,13 @@ void rpn_ift(void)
if (!mpfr_zero_p(testee->_value.mpfr)) if (!mpfr_zero_p(testee->_value.mpfr))
{ {
CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack)); CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack));
(void)_stack->pop_back(); (void)_stack->pop_back(2);
(void)_stack->pop_back();
CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack)); CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack));
(void)_calc_stack.pop_back(); (void)_calc_stack.pop_back();
} }
else else
{ (void)_stack->pop_back(2);
(void)_stack->pop_back();
(void)_stack->pop_back();
}
} }
void rpn_ifte(void) void rpn_ifte(void)
@ -116,9 +112,7 @@ void rpn_ifte(void)
else else
CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack)); CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack));
(void)_stack->pop_back(); (void)_stack->pop_back(3);
(void)_stack->pop_back();
(void)_stack->pop_back();
CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack)); CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack));
(void)_calc_stack.pop_back(); (void)_calc_stack.pop_back();
@ -242,8 +236,7 @@ int rpn_next(branch& myobj)
{ {
// end of loop // end of loop
myobj.arg_bool = false;// init again next time myobj.arg_bool = false;// init again next time
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
return -1; return -1;
} }
else else
@ -298,8 +291,7 @@ int rpn_step(branch& myobj)
{ {
// end of loop // end of loop
myobj.arg_bool = false;// init again next time myobj.arg_bool = false;// init again next time
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
ret = -1; ret = -1;
} }
else else

View file

@ -62,8 +62,7 @@ void r2c()
complex* cplx = (complex*)_stack->allocate_back(complex::calc_size(), cmd_complex); complex* cplx = (complex*)_stack->allocate_back(complex::calc_size(), cmd_complex);
CHECK_MPFR(mpfr_set(cplx->re()->mpfr, ((number*)_calc_stack.get_obj(1))->_value.mpfr, floating_t::s_mpfr_rnd)); CHECK_MPFR(mpfr_set(cplx->re()->mpfr, ((number*)_calc_stack.get_obj(1))->_value.mpfr, floating_t::s_mpfr_rnd));
CHECK_MPFR(mpfr_set(cplx->im()->mpfr, ((number*)_calc_stack.get_obj(0))->_value.mpfr, floating_t::s_mpfr_rnd)); CHECK_MPFR(mpfr_set(cplx->im()->mpfr, ((number*)_calc_stack.get_obj(0))->_value.mpfr, floating_t::s_mpfr_rnd));
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
} }
void c2r() void c2r()

View file

@ -182,10 +182,7 @@ void do_divide_complexes()
CHECK_MPFR(mpfr_div(left->im()->mpfr, left->im()->mpfr, ex->_value.mpfr, floating_t::s_mpfr_rnd)); CHECK_MPFR(mpfr_div(left->im()->mpfr, left->im()->mpfr, ex->_value.mpfr, floating_t::s_mpfr_rnd));
_stack->pop_back(); _stack->pop_back();
_calc_stack.pop_back(); _calc_stack.pop_back(4);
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back();
} }
void div() void div()
@ -216,17 +213,18 @@ void div()
//1. copy out //1. copy out
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);//complex stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);//complex
stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack);//number stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack);//number
_stack->pop_back(); _stack->pop_back(2);
_stack->pop_back();
//2. copy back (2 complexes on stack) //2. copy back (2 complexes on stack)
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);//complex back to stack stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);//complex back to stack
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);//complex back to stack stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);//complex back to stack
//3. set complex level 2 to (number,0) //3. set complex level 2 to (number,0)
complex* new_cplx = (complex*)_stack->get_obj(1); complex* new_cplx = (complex*)_stack->get_obj(1);
CHECK_MPFR(mpfr_set(new_cplx->re()->mpfr, ((number*)_calc_stack.get_obj(0))->_value.mpfr, floating_t::s_mpfr_rnd)); CHECK_MPFR(mpfr_set(new_cplx->re()->mpfr, ((number*)_calc_stack.get_obj(0))->_value.mpfr, floating_t::s_mpfr_rnd));
CHECK_MPFR(mpfr_set_ui(new_cplx->im()->mpfr, 0UL, floating_t::s_mpfr_rnd)); CHECK_MPFR(mpfr_set_ui(new_cplx->im()->mpfr, 0UL, floating_t::s_mpfr_rnd));
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
//4. divide //4. divide
do_divide_complexes(); do_divide_complexes();
} }
@ -501,8 +499,7 @@ void mant()
while (mpfr_less_p(left->_value.mpfr, one->_value.mpfr)) while (mpfr_less_p(left->_value.mpfr, one->_value.mpfr))
mpfr_mul(left->_value.mpfr, left->_value.mpfr, ten->_value.mpfr, floating_t::s_mpfr_rnd); mpfr_mul(left->_value.mpfr, left->_value.mpfr, ten->_value.mpfr, floating_t::s_mpfr_rnd);
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
} }
} }
else else

View file

@ -4,12 +4,10 @@ void swap(void)
MIN_ARGUMENTS(2); MIN_ARGUMENTS(2);
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack); stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack); stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack);
(void)_stack->pop_back(); (void)_stack->pop_back(2);
(void)_stack->pop_back();
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
_calc_stack.pop_back(); _calc_stack.pop_back(2);
_calc_stack.pop_back();
} }
void drop(void) void drop(void)
@ -21,8 +19,7 @@ void drop(void)
void drop2(void) void drop2(void)
{ {
MIN_ARGUMENTS(2); MIN_ARGUMENTS(2);
(void)_stack->pop_back(); (void)_stack->pop_back(2);
(void)_stack->pop_back();
} }
void dropn(void) void dropn(void)
@ -33,14 +30,12 @@ void dropn(void)
int args = (int)mpfr_get_si(((number*)_stack->back())->_value.mpfr, floating_t::s_mpfr_rnd); int args = (int)mpfr_get_si(((number*)_stack->back())->_value.mpfr, floating_t::s_mpfr_rnd);
MIN_ARGUMENTS(args+1); MIN_ARGUMENTS(args+1);
for(int i=0;i<args+1;i++) (void)_stack->pop_back(args+1);
(void)_stack->pop_back();
} }
void erase(void) void erase(void)
{ {
while(_stack->size()>0) (void)_stack->pop_back(_stack->size());
(void)_stack->pop_back();
} }
void dup(void) void dup(void)
@ -93,15 +88,11 @@ void rot(void)
stack::copy_and_push_back(*_stack, _stack->size()-3, _calc_stack); stack::copy_and_push_back(*_stack, _stack->size()-3, _calc_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack); stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack);
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack); stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);
(void)_stack->pop_back(); (void)_stack->pop_back(3);
(void)_stack->pop_back();
(void)_stack->pop_back();
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-3, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-3, *_stack);
_calc_stack.pop_back(); _calc_stack.pop_back(3);
_calc_stack.pop_back();
_calc_stack.pop_back();
} }
void depth(void) void depth(void)
@ -130,8 +121,7 @@ void roll(void)
stack::copy_and_push_back(_calc_stack, args-1-i, *_stack); stack::copy_and_push_back(_calc_stack, args-1-i, *_stack);
stack::copy_and_push_back(_calc_stack, args-1, *_stack); stack::copy_and_push_back(_calc_stack, args-1, *_stack);
for(int i=0;i<args;i++) _calc_stack.pop_back(args);
_calc_stack.pop_back();
} }
void rolld(void) void rolld(void)
@ -154,8 +144,7 @@ void rolld(void)
for(int i=1;i<args;i++) for(int i=1;i<args;i++)
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-i, *_stack); stack::copy_and_push_back(_calc_stack, _calc_stack.size()-i, *_stack);
for(int i=0;i<args;i++) _calc_stack.pop_back(args);
_calc_stack.pop_back();
} }
void over(void) void over(void)

View file

@ -93,8 +93,7 @@ void strpos()
if (found != NULL) if (found != NULL)
pos = (long)(found - src)+1L; pos = (long)(found - src)+1L;
_stack->pop_back(); _stack->pop_back(2);
_stack->pop_back();
number* numb = (number*)_stack->allocate_back(number::calc_size(), cmd_number); number* numb = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
numb->_value = pos; numb->_value = pos;
@ -112,8 +111,7 @@ void strsub()
long len = ((ostring*)_stack->get_obj(2))->_len; long len = ((ostring*)_stack->get_obj(2))->_len;
bool result_is_void = false; bool result_is_void = false;
_stack->pop_back(); _stack->pop_back(2);
_stack->pop_back();
if (first < 0) if (first < 0)
first = 0; first = 0;

View file

@ -109,14 +109,18 @@ public:
return allocated; return allocated;
} }
object* pop_back() object* pop_back(int pop_count = 1)
{ {
object* back = NULL; object* back = NULL;
if (_count > 0) // pop several entries, return the last
while (pop_count-- > 0)
{ {
_current = (char*)_base_pointer[--_count]; if (_count > 0)
back = (object*)_current; {
_current = (char*)_base_pointer[--_count];
back = (object*)_current;
}
} }
return back; return back;