diff --git a/nasal_gc.h b/nasal_gc.h index b09e535..3193922 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -124,12 +124,13 @@ struct nasal_func struct nasal_upval { bool onstk; + uint32_t size; nasal_ref* stk; std::vector 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 strs; // reserved address for const vm_str std::vector memory; // gc memory std::queue 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 upvalue; uint64_t size[vm_type_size]; uint64_t count[vm_type_size]; diff --git a/nasal_vm.h b/nasal_vm.h index 6e4add5..1b59faf 100644 --- a/nasal_vm.h +++ b/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=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;ilsize;++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;ielems; - for(uint32_t j=0;j upval[%u]:\n",i); + auto& uv=upval[i].upval(); + for(uint32_t j=0;jupvalue=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;