fix bug of upval_state
This commit is contained in:
parent
f312250d27
commit
40f61a9dd4
10
nasal_gc.h
10
nasal_gc.h
|
@ -124,12 +124,13 @@ struct nasal_func
|
|||
struct nasal_upval
|
||||
{
|
||||
bool onstk;
|
||||
uint32_t size;
|
||||
nasal_ref* stk;
|
||||
std::vector<nasal_ref> elems;
|
||||
|
||||
nasal_upval(){onstk=true;stk=nullptr;}
|
||||
nasal_upval(){onstk=true;stk=nullptr;size=0;}
|
||||
nasal_ref& operator[](const int);
|
||||
void clear(){onstk=true;elems.clear();}
|
||||
void clear(){onstk=true;elems.clear();size=0;}
|
||||
};
|
||||
|
||||
struct nasal_obj
|
||||
|
@ -341,6 +342,11 @@ struct nasal_gc
|
|||
std::vector<nasal_ref> strs; // reserved address for const vm_str
|
||||
std::vector<nasal_val*> memory; // gc memory
|
||||
std::queue<nasal_val*> free_list[vm_type_size]; // gc free list
|
||||
/* upvalue is a temporary space to store upvalues */
|
||||
/* if no new functions generated in local scope */
|
||||
/* upvalue will pushback(nil) */
|
||||
/* if new functions generated in local scope */
|
||||
/* they will share the same upvalue stored here */
|
||||
std::vector<nasal_ref> upvalue;
|
||||
uint64_t size[vm_type_size];
|
||||
uint64_t count[vm_type_size];
|
||||
|
|
23
nasal_vm.h
23
nasal_vm.h
|
@ -222,7 +222,10 @@ void nasal_vm::stackinfo(const uint32_t limit=10)
|
|||
}
|
||||
printf("vm stack(limit %d, total %ld):\n",limit,top-bottom+1);
|
||||
for(uint32_t i=0;i<limit && top>=bottom;++i,--top)
|
||||
{
|
||||
printf("0x%.8lx",top-gc.stack);
|
||||
valinfo(top[0]);
|
||||
}
|
||||
}
|
||||
void nasal_vm::global_state()
|
||||
{
|
||||
|
@ -231,10 +234,10 @@ void nasal_vm::global_state()
|
|||
printf("no global value exists\n");
|
||||
return;
|
||||
}
|
||||
printf("global:\n");
|
||||
printf("global(base %p):\n",gc.stack);
|
||||
for(uint32_t i=0;i<bytecode[0].num;++i)
|
||||
{
|
||||
printf("[0x%.8x]",i);
|
||||
printf("0x%.8x",i);
|
||||
valinfo(gc.stack[i]);
|
||||
}
|
||||
}
|
||||
|
@ -245,10 +248,10 @@ void nasal_vm::local_state()
|
|||
printf("no local value exists\n");
|
||||
return;
|
||||
}
|
||||
printf("local:\n");
|
||||
printf("local(base %p):\n",lstk.top());
|
||||
for(uint32_t i=0;i<fstk.top()->lsize;++i)
|
||||
{
|
||||
printf("[0x%.8x]",i);
|
||||
printf("0x%.8x",i);
|
||||
valinfo(lstk.top()[i]);
|
||||
}
|
||||
}
|
||||
|
@ -263,17 +266,18 @@ void nasal_vm::upval_state()
|
|||
auto& upval=fstk.top()->upvalue;
|
||||
for(uint32_t i=0;i<upval.size();++i)
|
||||
{
|
||||
auto& vec=upval[i].vec()->elems;
|
||||
for(uint32_t j=0;j<vec.size();++j)
|
||||
printf("-> upval[%u]:\n",i);
|
||||
auto& uv=upval[i].upval();
|
||||
for(uint32_t j=0;j<uv.size;++j)
|
||||
{
|
||||
printf("[%.4x][%.4x]",i,j);
|
||||
valinfo(vec[j]);
|
||||
printf(" 0x%.8x",j);
|
||||
valinfo(uv[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void nasal_vm::detail()
|
||||
{
|
||||
printf("mcall address: 0x%lx\n",(uint64_t)mem_addr);
|
||||
printf("maddr: 0x%lx\n",(uint64_t)mem_addr);
|
||||
global_state();
|
||||
local_state();
|
||||
upval_state();
|
||||
|
@ -384,6 +388,7 @@ inline void nasal_vm::opr_newf()
|
|||
{
|
||||
func->upvalue=fstk.top()->upvalue;
|
||||
nasal_ref upval=(gc.upvalue.back().type==vm_nil)?gc.alloc(vm_upval):gc.upvalue.back();
|
||||
upval.upval().size=fstk.top()->lsize;
|
||||
upval.upval().stk=lstk.top();
|
||||
func->upvalue.push_back(upval);
|
||||
gc.upvalue.back()=upval;
|
||||
|
|
Loading…
Reference in New Issue