diff --git a/makefile b/makefile index a48a39b..186b3fc 100644 --- a/makefile +++ b/makefile @@ -46,5 +46,5 @@ test:nasal -@ ./nasal -op -c -t test/tetris.nas @ ./nasal -op -c -t -d test/turingmachine.nas @ ./nasal -op -c -t -d -o test/ycombinator.nas - @ ./nasal -op -e test/wavecollapse.nas + @ ./nasal -op -d -o test/wavecollapse.nas \ No newline at end of file diff --git a/nasal_gc.h b/nasal_gc.h index a76d21c..a823b43 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -17,12 +17,12 @@ enum vm_type:std::uint32_t{ vm_upval, vm_obj, vm_co, - vm_type_size + vm_tsize }; -const uint32_t gc_obj_size=vm_type_size-vm_str; +const uint32_t gc_tsize=vm_tsize-vm_str; // change parameters here to make your own efficient gc // better set bigger number on vm_vec -const uint32_t ini[gc_obj_size]= +const uint32_t ini[gc_tsize]= { 128, // vm_str 512, // vm_func @@ -32,7 +32,7 @@ const uint32_t ini[gc_obj_size]= 0, // vm_obj 0 // vm_co }; -const uint32_t incr[gc_obj_size]= +const uint32_t incr[gc_tsize]= { 256, // vm_str 512, // vm_func @@ -447,26 +447,26 @@ struct nasal_gc } main_ctx; /* runtime context */ - uint32_t& pc; // program counter - nasal_ref*& localr; // local scope register - nasal_ref*& memr; // used for mem_call - nasal_ref& funcr; // function register - nasal_ref& upvalr; // upvalue register - nasal_ref*& canary; // avoid stackoverflow - nasal_ref*& top; // stack top - nasal_ref* stack; // stack pointer - nasal_co* coroutine; // running coroutine + uint32_t& pc; // program counter + nasal_ref*& localr; // local scope register + nasal_ref*& memr; // used for mem_call + nasal_ref& funcr; // function register + nasal_ref& upvalr; // upvalue register + nasal_ref*& canary; // avoid stackoverflow + nasal_ref*& top; // stack top + nasal_ref* stack; // stack pointer + nasal_co* coroutine; // running coroutine /* constants and memory pool */ - std::vector strs; // reserved address for const vm_str - std::vector memory; // gc memory - std::queue free_list[vm_type_size]; // gc free list - std::vector env_argv; // command line arguments + std::vector strs; // reserved address for const vm_str + std::vector memory; // gc memory + std::queue free_list[gc_tsize]; // gc free list + std::vector env_argv; // command line arguments /* values for analysis */ - uint64_t size[gc_obj_size]; - uint64_t count[gc_obj_size]; - uint64_t allocc[gc_obj_size]; + uint64_t size[gc_tsize]; + uint64_t count[gc_tsize]; + uint64_t allocc[gc_tsize]; nasal_gc( uint32_t& _pc, nasal_ref*& _localr, @@ -567,7 +567,7 @@ void nasal_gc::sweep() case vm_obj: i->ptr.obj->clear(); break; case vm_co: i->ptr.co->clear(); break; } - free_list[i->type].push(i); + free_list[i->type-vm_str].push(i); i->mark=GC_COLLECTED; } else if(i->mark==GC_FOUND) @@ -579,12 +579,12 @@ void nasal_gc::init(const std::vector& s,const std::vectormark=GC_UNCOLLECTED; - free_list[type].pop(); + free_list[type-vm_str].pop(); return ret; } nasal_ref nasal_gc::builtin_alloc(uint8_t type) @@ -661,19 +661,19 @@ nasal_ref nasal_gc::builtin_alloc(uint8_t type) // and the value got before will be collected,this is a fatal error // so use builtin_alloc in builtin functions if this function uses alloc more then one time ++allocc[type-vm_str]; - if(free_list[type].empty()) + if(free_list[type-vm_str].empty()) { ++size[type-vm_str]; for(uint32_t i=0;imark=GC_UNCOLLECTED; - free_list[type].pop(); + free_list[type-vm_str].pop(); return ret; } void nasal_gc::ctxchg(nasal_co& context)