#126, #127: now type consumes stack, returns string

This commit is contained in:
Louis Rubet 2017-06-17 10:21:02 +02:00
parent 562ae5fdef
commit 8b0b447e6a
2 changed files with 12 additions and 7 deletions

View file

@ -134,14 +134,14 @@ void type()
{
MIN_ARGUMENTS(1);
int type = _stack->back()->_type;
int type = _stack->pop_back()->_type;
if (type < 0 || type >= (int)cmd_max)
type = (int)cmd_undef;
unsigned int string_size = strlen(object::s_cmd_type_string[type]);
unsigned int size = sizeof(symbol)+string_size+1;
symbol* sym = (symbol*)_stack->allocate_back(size, cmd_symbol);
sym->set(object::s_cmd_type_string[type], string_size, false);
ostring* typ = (ostring*)_stack->allocate_back(size, cmd_string);
typ->set(object::s_cmd_type_string[type], string_size);
}
void rpn_default()

View file

@ -12,22 +12,27 @@ erase
# type (1)
1 type
-> stack should be 1, 'number'
-> stack should be "number"
erase
# type (2)
"hey" type
-> stack should be "hey", 'string'
-> stack should be "string"
erase
# type (3)
<< -> n << n >> >> type
-> stack should be << -> n << n >> >>, 'program'
-> stack should be "program"
erase
# type (4)
(1,2) type
-> stack should be (1,2)), 'complex'
-> stack should be "complex"
erase
# type (5)
type
-> error should be 2
erase
# default