#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))
{
CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack));
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back(2);
CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack));
(void)_calc_stack.pop_back();
}
else
{
(void)_stack->pop_back();
(void)_stack->pop_back();
}
(void)_stack->pop_back(2);
}
void rpn_ifte(void)
@ -116,9 +112,7 @@ void rpn_ifte(void)
else
CHECK_MPFR(stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack));
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back(3);
CHECK_MPFR(stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack));
(void)_calc_stack.pop_back();
@ -242,8 +236,7 @@ int rpn_next(branch& myobj)
{
// end of loop
myobj.arg_bool = false;// init again next time
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
return -1;
}
else
@ -298,8 +291,7 @@ int rpn_step(branch& myobj)
{
// end of loop
myobj.arg_bool = false;// init again next time
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
ret = -1;
}
else

View file

@ -62,8 +62,7 @@ void r2c()
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->im()->mpfr, ((number*)_calc_stack.get_obj(0))->_value.mpfr, floating_t::s_mpfr_rnd));
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
}
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));
_stack->pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(4);
}
void div()
@ -216,17 +213,18 @@ void div()
//1. copy out
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->pop_back();
_stack->pop_back();
_stack->pop_back(2);
//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
//3. set complex level 2 to (number,0)
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_ui(new_cplx->im()->mpfr, 0UL, floating_t::s_mpfr_rnd));
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
//4. divide
do_divide_complexes();
}
@ -501,8 +499,7 @@ void mant()
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);
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
}
}
else

View file

@ -4,12 +4,10 @@ void swap(void)
MIN_ARGUMENTS(2);
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, _calc_stack);
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back(2);
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-2, *_stack);
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(2);
}
void drop(void)
@ -21,8 +19,7 @@ void drop(void)
void drop2(void)
{
MIN_ARGUMENTS(2);
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back(2);
}
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);
MIN_ARGUMENTS(args+1);
for(int i=0;i<args+1;i++)
(void)_stack->pop_back();
(void)_stack->pop_back(args+1);
}
void erase(void)
{
while(_stack->size()>0)
(void)_stack->pop_back();
(void)_stack->pop_back(_stack->size());
}
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()-2, _calc_stack);
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back(3);
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()-3, *_stack);
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back();
_calc_stack.pop_back(3);
}
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, *_stack);
for(int i=0;i<args;i++)
_calc_stack.pop_back();
_calc_stack.pop_back(args);
}
void rolld(void)
@ -154,8 +144,7 @@ void rolld(void)
for(int i=1;i<args;i++)
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-i, *_stack);
for(int i=0;i<args;i++)
_calc_stack.pop_back();
_calc_stack.pop_back(args);
}
void over(void)

View file

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

View file

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