rpn/src/rpn-store.h

76 lines
1.5 KiB
C
Raw Normal View History

//
void sto(void)
{
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
2015-03-01 16:02:23 +01:00
string name(((symbol*)_stack->get_obj(0))->_value);
_stack->pop_back();
_heap->add(name, _stack->get_obj(0), _stack->get_len(0), _stack->get_type(0));
_stack->pop_back();
}
void rcl(void)
{
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
// recall a variable
void* obj;
unsigned int size;
int type;
2015-02-26 22:33:28 +01:00
string variable(((symbol*)_stack->back())->_value);
if (_heap->get(variable, obj, size, type))
{
_stack->pop_back();
_stack->push_back(obj, size, type);
}
else
2014-03-10 17:13:18 +01:00
ERR_CONTEXT(ret_unknown_variable);
}
// carefull : this is not a langage command
void auto_rcl(symbol* symb)
{
if (symb->_auto_eval)
{
void* obj;
unsigned int size;
int type;
2015-02-26 22:33:28 +01:00
if (_heap->get(string(symb->_value), obj, size, type))
_stack->push_back(obj, size, type);
else
2015-03-01 16:02:23 +01:00
_stack->push_back(symb, symb->size(), cmd_symbol);
}
else
2015-03-01 16:02:23 +01:00
_stack->push_back(symb, symb->size(), cmd_symbol);
}
void purge(void)
{
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
2015-03-01 16:30:13 +01:00
string name(((symbol*)_stack->back())->_value);
if (!_heap->erase(name))
2014-03-10 17:13:18 +01:00
ERR_CONTEXT(ret_unknown_variable);
2015-03-01 16:30:13 +01:00
else
_stack->pop_back();
}
void vars(void)
{
object* obj;
unsigned int size;
int type;
string name;
for (int i=0; i<(int)_heap->size(); i++)
{
(void)_heap->get_by_index(i, name, (void*&)obj, size, type);
cout<<"var "<<i+1<<": name '"<<name<<"', type "<<cmd_type_string[type]<<", value ";
obj->show();
cout<<endl;
}
}