From 8b0b447e6a02d38090b7a03a620da85f09599f05 Mon Sep 17 00:00:00 2001 From: Louis Rubet Date: Sat, 17 Jun 2017 10:21:02 +0200 Subject: [PATCH] #126, #127: now type consumes stack, returns string --- src/rpn-general.hpp | 6 +++--- test/02-general.txt | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/rpn-general.hpp b/src/rpn-general.hpp index 200b349..a41d56d 100644 --- a/src/rpn-general.hpp +++ b/src/rpn-general.hpp @@ -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() diff --git a/test/02-general.txt b/test/02-general.txt index 3d48783..550d2cf 100644 --- a/test/02-general.txt +++ b/test/02-general.txt @@ -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