diff --git a/src/main.cpp b/src/main.cpp index 3921eee..caad6f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) { // entry loop while (go_on) { // make program from interactive entry - program prog(&_global_stack, &_global_heap); + program prog(&_global_stack, _global_heap); switch (program::entry(prog)) { case ret_good_bye: go_on = false; @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) { } // run with cmd line arguments else { - program prog(&_global_stack, &_global_heap); + program prog(&_global_stack, _global_heap); string entry; int i; diff --git a/src/program.hpp b/src/program.hpp index b89c9ec..8351c6e 100644 --- a/src/program.hpp +++ b/src/program.hpp @@ -44,7 +44,7 @@ struct if_layout_t { //< program class: the class containing a string parser, all the programs keywords, a stack for running the program class program : public deque { public: - program(rpnstack* stk, heap* hp, program* parent = nullptr):_stack(stk),_heap(hp),_parent(parent) { + program(rpnstack* stk, heap& hp, program* parent = nullptr):_stack(stk),_heap(hp),_parent(parent) { interrupt_now = false; } virtual ~program() { @@ -85,7 +85,7 @@ class program : public deque { rpnstack* _stack; // global heap (sto, rcl) - heap* _heap; + heap& _heap; // local heap for local loop variables (for..next) heap _local_heap; diff --git a/src/rpn-program.cpp b/src/rpn-program.cpp index abe92ae..3efb4d8 100644 --- a/src/rpn-program.cpp +++ b/src/rpn-program.cpp @@ -22,7 +22,7 @@ bool program::find_variable(string& variable, object*& obj) { parent = parent->_parent; } if (!found) { - if (_heap->get(variable, obj)) found = true; + if (_heap.get(variable, obj)) found = true; } } diff --git a/src/rpn-store.cpp b/src/rpn-store.cpp index 7f6e037..09c9a26 100644 --- a/src/rpn-store.cpp +++ b/src/rpn-store.cpp @@ -7,12 +7,12 @@ void program::rpn_sto(void) { ARG_MUST_BE_OF_TYPE(0, cmd_symbol); // store symbol with first value - const auto it = _heap->find(_stack->value(0)); - if (it != _heap->end()) { + const auto it = _heap.find(_stack->value(0)); + if (it != _heap.end()) { delete it->second; - _heap->erase(it); + _heap.erase(it); } - (*_heap)[_stack->value(0)] = _stack->at(1)->clone(); + _heap[_stack->value(0)] = _stack->at(1)->clone(); _stack->pop_front(2); } @@ -21,7 +21,7 @@ void program::rpn_sto(void) { void program::rpn_stoadd(void) { MIN_ARGUMENTS(2); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -38,7 +38,7 @@ void program::rpn_stoadd(void) { void program::rpn_stosub(void) { MIN_ARGUMENTS(2); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -55,7 +55,7 @@ void program::rpn_stosub(void) { void program::rpn_stomul(void) { MIN_ARGUMENTS(2); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -72,7 +72,7 @@ void program::rpn_stomul(void) { void program::rpn_stodiv(void) { MIN_ARGUMENTS(2); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -89,7 +89,7 @@ void program::rpn_stodiv(void) { void program::rpn_stoneg(void) { MIN_ARGUMENTS(1); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -105,7 +105,7 @@ void program::rpn_stoneg(void) { void program::rpn_stoinv(void) { MIN_ARGUMENTS(1); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - if (_heap->find(_stack->value(0)) == _heap->end()) { + if (_heap.find(_stack->value(0)) == _heap.end()) { ERR_CONTEXT(ret_unknown_variable); return; } @@ -174,10 +174,10 @@ void program::rpn_purge(void) { MIN_ARGUMENTS(1); ARG_MUST_BE_OF_TYPE(0, cmd_symbol); - const auto i = _heap->find(_stack->value(0)); - if (i != _heap->end()) { + const auto i = _heap.find(_stack->value(0)); + if (i != _heap.end()) { delete i->second; - _heap->erase(i); + _heap.erase(i); } else ERR_CONTEXT(ret_unknown_variable); _stack->pop(); @@ -191,8 +191,8 @@ void program::rpn_vars(void) { string name; // heap variables - for (int i = 0; i < (int)_heap->size(); i++) { - (void)_heap->get_by_index(i, name, obj); + for (int i = 0; i < (int)_heap.size(); i++) { + (void)_heap.get_by_index(i, name, obj); cout<<"var "<name()<<", value "; obj->show(cout); cout<clear(); } +void program::rpn_clusr(void) { _heap.clear(); } diff --git a/src/rpn-test-framework.cpp b/src/rpn-test-framework.cpp index bbb2572..57fedd9 100644 --- a/src/rpn-test-framework.cpp +++ b/src/rpn-test-framework.cpp @@ -227,7 +227,7 @@ void program::test(string test_filename, int& total_tests, int& total_tests_fail // parse entry and run line entry = regex_replace(entry, regex("`"), ""); if (!entry.empty()) { - program prog(&stk, &hp); + program prog(&stk, hp); ret = program::parse(entry, prog); if (ret == ret_ok) { // run it