diff --git a/src/rpn-branch.h b/src/rpn-branch.h index 4610000..217cacb 100644 --- a/src/rpn-branch.h +++ b/src/rpn-branch.h @@ -72,7 +72,7 @@ int rpn_for(branch& myobj) // store symbol with first value number num; num.set(myobj.farg1); - _heap->add(string(sym->_value), &num, num.size(), cmd_number); + _local_heap->add(string(sym->_value), &num, num.size(), cmd_number); return myobj.arg1 + 1; } @@ -99,7 +99,7 @@ int rpn_next(branch& myobj) int type; symbol* var = (symbol*)seq_obj(start_or_for->arg1); // check symbol variable is a number, then increase - if (_heap->get(string(var->_value), obj, size, type) && (type == cmd_number)) + if (_local_heap->get(string(var->_value), obj, size, type) && (type == cmd_number)) ((number*)obj)->_value = myobj.farg1; } @@ -144,7 +144,7 @@ int rpn_step(branch& myobj) int type; symbol* var = (symbol*)seq_obj(start_or_for->arg1); // check symbol variable is a number, then increase - if (_heap->get(string(var->_value), obj, size, type) && (type == cmd_number)) + if (_local_heap->get(string(var->_value), obj, size, type) && (type == cmd_number)) ((number*)obj)->_value = myobj.farg1; } diff --git a/src/rpn-program.h b/src/rpn-program.h index 0fb7a15..54c21d7 100644 --- a/src/rpn-program.h +++ b/src/rpn-program.h @@ -12,7 +12,7 @@ void eval(void) unsigned int size; int type; string variable(((symbol*)_stack->back())->_value); - if (_heap->get(variable, obj, size, type)) + if (_local_heap->get(variable, obj, size, type) || _global_heap->get(variable, obj, size, type)) { // if variable holds a program, run this program if (type == cmd_program) @@ -50,7 +50,7 @@ void eval(void) if (program::parse(prog_text.c_str(), prog) == ret_ok) { // run it - prog.run(*_stack, *_heap); + prog.run(*_stack, *_global_heap); } } } @@ -117,9 +117,10 @@ int inprog(branch& myobj) } // load variables + heap local_heap; for (unsigned int i = myobj.arg1 + count_symbols; i > myobj.arg1; i--) { - _heap->add(string(((symbol*)seq_obj(i))->_value), _stack->get_obj(0), _stack->get_len(0), _stack->get_type(0)); + local_heap.add(string(((symbol*)seq_obj(i))->_value), _stack->get_obj(0), _stack->get_len(0), _stack->get_type(0)); _stack->pop_back(); } @@ -131,7 +132,8 @@ int inprog(branch& myobj) if (program::parse(entry.c_str(), prog) == ret_ok) { // run it - prog.run(*_stack, *_heap); + prog.run(*_stack, *_global_heap, &local_heap); + //TODO here: _local_heap free } // point on next command diff --git a/src/rpn-store.h b/src/rpn-store.h index 7cdf7e6..5abca93 100644 --- a/src/rpn-store.h +++ b/src/rpn-store.h @@ -6,7 +6,7 @@ void sto(void) 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)); + _global_heap->add(name, _stack->get_obj(0), _stack->get_len(0), _stack->get_type(0)); _stack->pop_back(); } @@ -20,7 +20,7 @@ void rcl(void) unsigned int size; int type; string variable(((symbol*)_stack->back())->_value); - if (_heap->get(variable, obj, size, type)) + if (_local_heap->get(variable, obj, size, type) || _global_heap->get(variable, obj, size, type)) { _stack->pop_back(); _stack->push_back(obj, size, type); @@ -37,7 +37,7 @@ void auto_rcl(symbol* symb) void* obj; unsigned int size; int type; - if (_heap->get(string(symb->_value), obj, size, type)) + if (_local_heap->get(string(symb->_value), obj, size, type) || _global_heap->get(string(symb->_value), obj, size, type)) _stack->push_back(obj, size, type); else _stack->push_back(symb, symb->size(), cmd_symbol); @@ -52,10 +52,18 @@ void purge(void) ARG_MUST_BE_OF_TYPE(0, cmd_symbol); string name(((symbol*)_stack->back())->_value); - if (!_heap->erase(name)) - ERR_CONTEXT(ret_unknown_variable); + if (_local_heap->erase(name)) + { + //TODO another error + ERR_CONTEXT(ret_bad_operand_type); + } else - _stack->pop_back(); + { + if (!_global_heap->erase(name)) + _stack->pop_back(); + else + ERR_CONTEXT(ret_unknown_variable); + } } void vars(void) @@ -65,9 +73,17 @@ void vars(void) int type; string name; - for (int i=0; i<(int)_heap->size(); i++) + for (int i=0; i<(int)_local_heap->size(); i++) + { + (void)_local_heap->get_by_index(i, name, (void*&)obj, size, type); + cout<<"local var "<show(); + cout<size(); i++) { - (void)_heap->get_by_index(i, name, (void*&)obj, size, type); + (void)_global_heap->get_by_index(i, name, (void*&)obj, size, type); cout<<"var "<show(); cout<