2014-02-11 11:26:28 +01:00
|
|
|
//
|
|
|
|
void swap(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
2017-04-29 16:48:14 +02:00
|
|
|
stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack);
|
|
|
|
stack::copy_and_push_back(*_stack, _stack->size()-2, _branch_stack);
|
2017-04-21 13:58:44 +02:00
|
|
|
(void)_stack->pop_back();
|
|
|
|
(void)_stack->pop_back();
|
2017-04-29 16:48:14 +02:00
|
|
|
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();
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drop(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
2017-04-21 13:58:44 +02:00
|
|
|
(void)_stack->pop_back();
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drop2(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
2017-04-21 13:58:44 +02:00
|
|
|
(void)_stack->pop_back();
|
|
|
|
(void)_stack->pop_back();
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void erase(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
while(_stack->size()>0)
|
2017-04-21 13:58:44 +02:00
|
|
|
(void)_stack->pop_back();
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void pick(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
2017-04-19 23:31:18 +02:00
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
unsigned int to_pick = (unsigned int)int(((number*)_stack->pop_back())->_value);
|
2014-02-11 11:26:28 +01:00
|
|
|
|
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);
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void rot(void)
|
|
|
|
{
|
2015-05-19 17:51:03 +02:00
|
|
|
MIN_ARGUMENTS(3);
|
2017-04-23 15:49:28 +02:00
|
|
|
|
2017-04-29 16:48:14 +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);
|
2017-04-21 13:58:44 +02:00
|
|
|
(void)_stack->pop_back();
|
|
|
|
(void)_stack->pop_back();
|
|
|
|
(void)_stack->pop_back();
|
2017-04-29 16:48:14 +02:00
|
|
|
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);
|
2017-04-29 16:48:14 +02:00
|
|
|
stack::copy_and_push_back(_branch_stack, 0, *_stack);
|
|
|
|
(void)_branch_stack.pop_back();
|
|
|
|
(void)_branch_stack.pop_back();
|
|
|
|
(void)_branch_stack.pop_back();
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-02-11 11:26:28 +01:00
|
|
|
}
|