rpn/src/rpn-stack.h

83 lines
1.4 KiB
C
Raw Normal View History

//
void swap(void)
{
MIN_ARGUMENTS(2);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->pop_back();
_stack->pop_back();
_stack->push_obj_from_local(0);
_stack->push_obj_from_local(1);
}
void drop(void)
{
MIN_ARGUMENTS(1);
_stack->pop_back();
}
void drop2(void)
{
MIN_ARGUMENTS(2);
_stack->pop_back();
_stack->pop_back();
}
void erase(void)
{
while(_stack->size()>0)
_stack->pop_back();
}
void dup(void)
{
MIN_ARGUMENTS(1);
_stack->copy_obj_to_local(0, 0);
_stack->push_obj_from_local(0);
}
void dup2(void)
{
MIN_ARGUMENTS(2);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->push_obj_from_local(1);
_stack->push_obj_from_local(0);
}
void pick(void)
{
MIN_ARGUMENTS(1);
unsigned int to_pick = (unsigned int)getf();
// treat stack depth errors
if ((to_pick == 0) || (to_pick > _stack->size()))
{
ERR_CONTEXT(ret_missing_operand);
return;
}
_stack->copy_obj_to_local(to_pick - 1, 0);
_stack->push_obj_from_local(0);
}
void rot(void)
{
2014-02-11 14:33:40 +01:00
MIN_ARGUMENTS(3);
_stack->copy_obj_to_local(0, 0);
_stack->copy_obj_to_local(1, 1);
_stack->copy_obj_to_local(2, 2);
_stack->pop_back();
_stack->pop_back();
_stack->pop_back();
_stack->push_obj_from_local(1);
_stack->push_obj_from_local(0);
_stack->push_obj_from_local(2);
}
void depth(void)
{
2015-02-26 22:33:28 +01:00
number num;
num.set((floating_t)_stack->size());
2015-03-01 16:02:23 +01:00
_stack->push_back(&num, num.size(), cmd_number);
}