mirror of
https://github.com/louisrubet/rpn
synced 2025-01-29 20:34:21 +01:00
#5: changes due to stack refactoring
This commit is contained in:
parent
da340837e3
commit
7de1177570
1 changed files with 46 additions and 22 deletions
|
@ -55,10 +55,27 @@ int rpn_start(branch& myobj)
|
||||||
|
|
||||||
// farg1 = first value of start command
|
// farg1 = first value of start command
|
||||||
// farg2 = last value of start command
|
// farg2 = last value of start command
|
||||||
myobj.farg2 = getf();
|
cout<<__FUNCTION__<<": copy_and_push_back(farg2)"<<endl;
|
||||||
myobj.farg2.ensure_significand();
|
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
||||||
myobj.farg1 = getf();
|
cout<<"[(number*)_stack->get_obj(0)="; ((number*)_stack->get_obj(0))->show(cout);cout<<"]\n";
|
||||||
myobj.farg1.ensure_significand();
|
cout<<"(number*)_stack->get_obj(0)="<<(void*)_stack->get_obj(0)<<"=";
|
||||||
|
dump8((unsigned char*)_stack->get_obj(0), 0, 40);
|
||||||
|
myobj.farg2 = (number*)_branch_stack.get_obj(0);
|
||||||
|
myobj.farg2->init(_branch_stack.get_blob(0));
|
||||||
|
_stack->pop_back();
|
||||||
|
cout<<"myobj.farg2="<<(void*)myobj.farg2<<"=";
|
||||||
|
dump8((unsigned char*)myobj.farg2, 0, 40);
|
||||||
|
cout<<"[-> arg2="; myobj.farg2->show(cout);cout<<"]\n";
|
||||||
|
|
||||||
|
cout<<__FUNCTION__<<": copy_and_push_back(farg1)"<<endl;
|
||||||
|
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
||||||
|
cout<<"[(number*)_stack->get_obj(0)="; ((number*)_stack->get_obj(0))->show(cout);cout<<"]\n";
|
||||||
|
cout<<"[_branch_stack.size()="<<_branch_stack.size()<<"]\n";
|
||||||
|
myobj.farg1 = (number*)_branch_stack.get_obj(0);
|
||||||
|
myobj.farg1->init(_branch_stack.get_blob(0));
|
||||||
|
_stack->pop_back();
|
||||||
|
cout<<"[myobj.farg2->_value.mpfr._mpfr_d="; myobj.farg2->_value.mpfr._mpfr_d;cout<<"]\n";
|
||||||
|
cout<<"[-> arg2="; myobj.farg2->show(cout);cout<<"]\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,15 +90,18 @@ int rpn_for(branch& myobj)
|
||||||
// farg1 = first value of for command
|
// 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
|
||||||
myobj.farg2 = getf();
|
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
||||||
myobj.farg2.ensure_significand();
|
myobj.farg2 = (number*)_branch_stack.back();
|
||||||
myobj.farg1 = getf();
|
myobj.farg2->init(_branch_stack.back_blob());
|
||||||
myobj.farg1.ensure_significand();
|
stack::copy_and_push_back(*_stack, 0, _branch_stack);
|
||||||
|
myobj.farg1 = (number*)_branch_stack.back();
|
||||||
|
myobj.farg1->init(_branch_stack.back_blob());
|
||||||
|
|
||||||
// store symbol with first value
|
// store symbol with first value
|
||||||
number* num = (number*)_local_heap.add(string(sym->_value), NULL, sizeof(number), cmd_number);
|
//TODO
|
||||||
num->set(myobj.farg1);
|
//number* num = (number*)_local_heap.add(string(sym->_value), NULL, sizeof(number), cmd_number);
|
||||||
num->ensure_significand();
|
//num->set(myobj.farg1);
|
||||||
|
//num->ensure_significand();
|
||||||
|
|
||||||
return myobj.arg1 + 1;
|
return myobj.arg1 + 1;
|
||||||
}
|
}
|
||||||
|
@ -95,11 +115,10 @@ int rpn_next(branch& myobj)
|
||||||
{
|
{
|
||||||
myobj.arg_bool = true;
|
myobj.arg_bool = true;
|
||||||
myobj.farg1 = start_or_for->farg1;
|
myobj.farg1 = start_or_for->farg1;
|
||||||
myobj.farg1.ensure_significand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment then test
|
// increment then test
|
||||||
mpfr_add_si(&myobj.farg1.mpfr, &myobj.farg1.mpfr, 1UL, MPFR_DEF_RND);
|
mpfr_add_si(&myobj.farg1->_value.mpfr, &myobj.farg1->_value.mpfr, 1UL, MPFR_DEF_RND);
|
||||||
|
|
||||||
// for command: increment symbol too
|
// for command: increment symbol too
|
||||||
if (start_or_for->arg1 != -1)
|
if (start_or_for->arg1 != -1)
|
||||||
|
@ -110,18 +129,20 @@ int rpn_next(branch& myobj)
|
||||||
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
|
// check symbol variable is a number, then increase
|
||||||
if (_local_heap.get(string(var->_value), obj, size, type) && (type == cmd_number))
|
//TODO
|
||||||
{
|
// if (_local_heap.get(string(var->_value), obj, size, type) && (type == cmd_number))
|
||||||
((number*)obj)->set(myobj.farg1);
|
// {
|
||||||
((number*)obj)->ensure_significand();
|
// ((number*)obj)->set(myobj.farg1);
|
||||||
}
|
// ((number*)obj)->ensure_significand();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//test value
|
//test value
|
||||||
if (myobj.farg1 > start_or_for->farg2)
|
if (myobj.farg1->_value > start_or_for->farg2->_value)
|
||||||
{
|
{
|
||||||
// end of loop
|
// end of loop
|
||||||
myobj.arg_bool = false;// init again next time
|
myobj.arg_bool = false;// init again next time
|
||||||
|
_branch_stack.erase();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -137,17 +158,17 @@ int rpn_next(branch& myobj)
|
||||||
|
|
||||||
int rpn_step(branch& myobj)
|
int rpn_step(branch& myobj)
|
||||||
{
|
{
|
||||||
|
//TODO
|
||||||
|
#if 0
|
||||||
// arg1 = index of start or for command in program
|
// arg1 = index of start or for command in program
|
||||||
// farg1 = current count
|
// farg1 = current count
|
||||||
floating_t step = getf();
|
number* step = _stack.pop_back();
|
||||||
step.ensure_significand();
|
|
||||||
|
|
||||||
branch* start_or_for = (branch*)seq_obj(myobj.arg1);
|
branch* start_or_for = (branch*)seq_obj(myobj.arg1);
|
||||||
if (! myobj.arg_bool)
|
if (! myobj.arg_bool)
|
||||||
{
|
{
|
||||||
myobj.arg_bool = true;
|
myobj.arg_bool = true;
|
||||||
myobj.farg1 = start_or_for->farg1;
|
myobj.farg1 = start_or_for->farg1;
|
||||||
myobj.farg1.ensure_significand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment then test
|
// increment then test
|
||||||
|
@ -186,4 +207,7 @@ int rpn_step(branch& myobj)
|
||||||
else
|
else
|
||||||
return myobj.arg1 + 1;
|
return myobj.arg1 + 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue