🚀 shrink stack size & optimize nasal_vm::traceback
This commit is contained in:
parent
61dcfb9395
commit
4c95d622f6
2
nasal.h
2
nasal.h
|
@ -50,7 +50,7 @@ using usize=std::size_t;
|
||||||
using f64=double;
|
using f64=double;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
const u32 STACK_DEPTH=2048;
|
const u32 STACK_DEPTH=1024;
|
||||||
|
|
||||||
inline f64 hex_to_double(const char* str)
|
inline f64 hex_to_double(const char* str)
|
||||||
{
|
{
|
||||||
|
|
18
nasal_vm.h
18
nasal_vm.h
|
@ -203,14 +203,12 @@ void nasal_vm::bytecodeinfo(const char* header,const u32 p)
|
||||||
}
|
}
|
||||||
void nasal_vm::traceback()
|
void nasal_vm::traceback()
|
||||||
{
|
{
|
||||||
const u32 global_size=bytecode[0].num; // bytecode[0] is op_intg
|
nas_ref* bottom=stack+bytecode[0].num; // bytecode[0] is op_intg
|
||||||
nas_ref* t=top;
|
|
||||||
nas_ref* bottom=stack+global_size;
|
|
||||||
std::stack<u32> ret;
|
std::stack<u32> ret;
|
||||||
for(nas_ref* i=bottom;i<=t;++i)
|
for(nas_ref* i=bottom;i<=top;++i)
|
||||||
if(i->type==vm_ret)
|
if(i->type==vm_ret)
|
||||||
ret.push(i->ret());
|
ret.push(i->ret());
|
||||||
// push pc to ret stack to store the position program crashed
|
// push pc to stack to store the position program crashed
|
||||||
ret.push(pc);
|
ret.push(pc);
|
||||||
std::cout<<"trace back:\n";
|
std::cout<<"trace back:\n";
|
||||||
u32 same=0,last=0xffffffff;
|
u32 same=0,last=0xffffffff;
|
||||||
|
@ -222,14 +220,13 @@ void nasal_vm::traceback()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(same)
|
if(same)
|
||||||
std::cout<<" 0x"<<std::hex<<std::setw(8)<<std::setfill('0')
|
std::cout
|
||||||
<<last<<std::dec<<": "<<same<<" same call(s)\n";
|
<<" 0x"<<std::hex<<std::setw(8)<<std::setfill('0')
|
||||||
|
<<last<<std::dec<<": "<<same<<" same call(s)\n";
|
||||||
same=0;
|
same=0;
|
||||||
bytecodeinfo(" ",point);
|
bytecodeinfo(" ",point);
|
||||||
}
|
}
|
||||||
if(same)
|
// same must be zero here
|
||||||
std::cout<<" 0x"<<std::hex<<std::setw(8)<<std::setfill('0')
|
|
||||||
<<last<<std::dec<<": "<<same<<" same call(s)\n";
|
|
||||||
}
|
}
|
||||||
void nasal_vm::stackinfo(const u32 limit=10)
|
void nasal_vm::stackinfo(const u32 limit=10)
|
||||||
{
|
{
|
||||||
|
@ -919,7 +916,6 @@ inline void nasal_vm::o_ret()
|
||||||
|
|
||||||
top=local-1;
|
top=local-1;
|
||||||
funcr=top[0];
|
funcr=top[0];
|
||||||
|
|
||||||
top[0]=ret; // rewrite func with returned value
|
top[0]=ret; // rewrite func with returned value
|
||||||
|
|
||||||
if(up.type==vm_upval) // synchronize upvalue
|
if(up.type==vm_upval) // synchronize upvalue
|
||||||
|
|
Loading…
Reference in New Issue