mirror of
https://github.com/louisrubet/rpn
synced 2025-01-01 18:20:06 +01:00
#34: debug for..netx commands
This commit is contained in:
parent
a16a9e13ce
commit
e4dced2735
2 changed files with 55 additions and 25 deletions
|
@ -77,28 +77,41 @@ int rpn_start(branch& myobj)
|
||||||
|
|
||||||
int rpn_for(branch& myobj)
|
int rpn_for(branch& myobj)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
MIN_ARGUMENTS_RET(2, 1);
|
MIN_ARGUMENTS_RET(2, 1);
|
||||||
ARG_MUST_BE_OF_TYPE_RET(0, cmd_number, -1);
|
ARG_MUST_BE_OF_TYPE_RET(0, cmd_number, -1);
|
||||||
ARG_MUST_BE_OF_TYPE_RET(1, cmd_number, -1);
|
ARG_MUST_BE_OF_TYPE_RET(1, cmd_number, -1);
|
||||||
|
|
||||||
symbol* sym = ((symbol*)seq_obj(myobj.arg1));
|
symbol* sym = ((symbol*)seq_obj(myobj.arg1));
|
||||||
|
|
||||||
// farg1 = first value of for command
|
|
||||||
// farg2 = last value of for command
|
// farg2 = last value of for command
|
||||||
// arg1 = index of symbol to increase
|
// arg1 = index of symbol to increase
|
||||||
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack);
|
||||||
//myobj.farg2 = (number*)_branch_stack.back();
|
myobj.farg2 = (number*)_branch_stack.back();
|
||||||
//myobj.farg2->init(_branch_stack.back_blob());
|
_stack->pop_back();
|
||||||
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
|
||||||
//myobj.farg1 = (number*)_branch_stack.back();
|
|
||||||
//myobj.farg1->init(_branch_stack.back_blob());
|
|
||||||
|
|
||||||
|
// farg1 = first value of for command
|
||||||
|
stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack);
|
||||||
|
myobj.farg1 = (number*)_branch_stack.back();
|
||||||
|
_stack->pop_back();
|
||||||
|
|
||||||
|
// test value
|
||||||
|
if (myobj.farg1->_value > myobj.farg2->_value)
|
||||||
|
// last boundary lower than first boundary
|
||||||
|
// -> next command shall be after 'next'
|
||||||
|
// arg2 holds index of 'next'
|
||||||
|
ret = myobj.arg2 + 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
// store symbol with first value
|
// store symbol with first value
|
||||||
//TODO
|
_local_heap.add(sym->_value, myobj.farg1, myobj.farg1->size());
|
||||||
//number* num = (number*)_local_heap.add(string(sym->_value), NULL, number::calc_size(), cmd_number);
|
(void)_stack->pop_back();
|
||||||
//num->set(myobj.farg1);
|
|
||||||
|
|
||||||
return myobj.arg1 + 1;
|
ret = myobj.arg1 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rpn_next(branch& myobj)
|
int rpn_next(branch& myobj)
|
||||||
|
@ -118,17 +131,12 @@ int rpn_next(branch& myobj)
|
||||||
// for command: increment symbol too
|
// for command: increment symbol too
|
||||||
if (start_or_for->arg1 != -1)
|
if (start_or_for->arg1 != -1)
|
||||||
{
|
{
|
||||||
void* obj;
|
object* obj;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
int type;
|
|
||||||
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
|
symbol* var = (symbol*)seq_obj(start_or_for->arg1);
|
||||||
|
|
||||||
// check symbol variable is a number, then increase
|
// increase symbol variable
|
||||||
// if (_local_heap.get(string(var->_value), obj, size, type) && (type == cmd_number))
|
_local_heap.replace_value(string(var->_value), myobj.farg1, myobj.farg1->size());
|
||||||
// {
|
|
||||||
// ((number*)obj)->set(myobj.farg1);
|
|
||||||
// ((number*)obj)->ensure_significand();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//test value
|
//test value
|
||||||
|
|
26
src/stack.h
26
src/stack.h
|
@ -201,7 +201,7 @@ public:
|
||||||
free(i->second);
|
free(i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
object* add(const string name, void* obj, unsigned int size, int type = 0)
|
object* add(const string name, object* obj, unsigned int size, int type = 0)
|
||||||
{
|
{
|
||||||
struct local_var* local = _map[name];
|
struct local_var* local = _map[name];
|
||||||
if (local == NULL)
|
if (local == NULL)
|
||||||
|
@ -219,9 +219,13 @@ public:
|
||||||
local->length = size;
|
local->length = size;
|
||||||
|
|
||||||
if (obj != NULL)
|
if (obj != NULL)
|
||||||
|
{
|
||||||
memcpy(local->obj, obj, size);
|
memcpy(local->obj, obj, size);
|
||||||
|
if (local->obj->_type == cmd_number)
|
||||||
|
((number*)local->obj)->_value.set_significand(((number*)local->obj)+1);
|
||||||
|
}
|
||||||
|
|
||||||
return (object*)local->obj;
|
return local->obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get(const string name, object*& obj, unsigned int& size)
|
bool get(const string name, object*& obj, unsigned int& size)
|
||||||
|
@ -240,6 +244,24 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool replace_value(const string name, object* obj, unsigned int size)
|
||||||
|
{
|
||||||
|
bool ret=false;
|
||||||
|
map<string, struct local_var*>::iterator i = _map.find(name);
|
||||||
|
|
||||||
|
if (i != _map.end())
|
||||||
|
{
|
||||||
|
if (i->second != NULL && size==i->second->length)
|
||||||
|
{
|
||||||
|
(void)memcpy(i->second->obj, obj, size);
|
||||||
|
if (i->second->obj->_type == cmd_number)
|
||||||
|
((number*)i->second->obj)->_value.set_significand(((number*)i->second->obj)+1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool exist(const string name)
|
bool exist(const string name)
|
||||||
{
|
{
|
||||||
return (_map.find(name) != _map.end());
|
return (_map.find(name) != _map.end());
|
||||||
|
|
Loading…
Reference in a new issue