rpn/src/rpn-stack.hpp

88 lines
2.1 KiB
C++
Raw Normal View History

//
void swap(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(2);
stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, _branch_stack);
(void)_stack->pop_back();
(void)_stack->pop_back();
stack::copy_and_push_back(_branch_stack, 0, *_stack);
stack::copy_and_push_back(_branch_stack, 1, *_stack);
(void)_branch_stack.pop_back();
(void)_branch_stack.pop_back();
}
void drop(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
(void)_stack->pop_back();
}
void drop2(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(2);
(void)_stack->pop_back();
(void)_stack->pop_back();
}
void erase(void)
{
2015-05-19 17:51:03 +02:00
while(_stack->size()>0)
(void)_stack->pop_back();
}
void dup(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
2017-04-23 15:49:28 +02:00
stack::copy_and_push_back(*_stack, _stack->size()-1, *_stack);
}
void dup2(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(2);
2017-04-23 15:49:28 +02:00
stack::copy_and_push_back(*_stack, _stack->size()-2, *_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, *_stack);
}
void pick(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
unsigned int to_pick = (unsigned int)int(((number*)_stack->pop_back())->_value);
2015-05-19 17:51:03 +02:00
// treat stack depth errors
if ((to_pick == 0) || (to_pick > _stack->size()))
{
2017-04-23 15:49:28 +02:00
ERR_CONTEXT(ret_out_of_range);
2015-05-19 17:51:03 +02:00
return;
}
2017-04-23 15:49:28 +02:00
stack::copy_and_push_back(*_stack, _stack->size()-to_pick, *_stack);
}
void rot(void)
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(3);
2017-04-23 15:49:28 +02:00
stack::copy_and_push_back(*_stack, _stack->size()-3, _branch_stack);
stack::copy_and_push_back(*_stack, _stack->size()-2, _branch_stack);
stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack);
(void)_stack->pop_back();
(void)_stack->pop_back();
(void)_stack->pop_back();
stack::copy_and_push_back(_branch_stack, 1, *_stack);
2017-05-02 17:05:09 +02:00
stack::copy_and_push_back(_branch_stack, 2, *_stack);
stack::copy_and_push_back(_branch_stack, 0, *_stack);
(void)_branch_stack.pop_back();
(void)_branch_stack.pop_back();
(void)_branch_stack.pop_back();
}
void depth(void)
{
2017-04-22 11:39:24 +02:00
unsigned long depth = (unsigned long)_stack->size();
2017-05-02 10:47:03 +02:00
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
2017-04-22 11:39:24 +02:00
num->set(depth);
}