diff --git a/makefile b/makefile index 5816e85..48f44f1 100644 --- a/makefile +++ b/makefile @@ -58,8 +58,8 @@ test:nasal @ ./nasal -d test/life.nas @ ./nasal -t test/loop.nas @ ./nasal -t -d test/mandel.nas - @ ./nasal -t -d test/mandelbrot.nas - @ ./nasal -t -d test/md5.nas + @ ./nasal -t test/mandelbrot.nas + @ ./nasal -t test/md5.nas @ ./nasal -t -d test/md5compare.nas -@ ./nasal -d test/module_test.nas @ ./nasal -e test/nasal_test.nas diff --git a/nasal_gc.h b/nasal_gc.h index cdd2f15..5a1aa6f 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -219,24 +218,15 @@ struct nas_co { u32 pc; var* top; - var* canary; + var* canary=stack+STACK_DEPTH-1; var* localr; var* memr; var funcr; var upvalr; u32 status; - nas_co(): - pc(0),top(stack), - canary(stack+STACK_DEPTH-1), - localr(nullptr), - memr(nullptr), - funcr({vm_nil,(f64)0}), - upvalr({vm_nil,(f64)0}), - status(nas_co::suspended) { - for(u32 i=0;i strs; // reserved address for const vm_str std::vector env_argv; // command line arguments std::vector memory; // gc memory - std::queue unused[gc_tsize]; // gc free list + std::vector unused[gc_tsize]; // gc free list /* values for analysis */ u64 size[gc_tsize]; @@ -517,28 +508,28 @@ struct gc { /* gc functions */ void gc::mark() { - std::queue bfs; + std::vector bfs; // scan coroutine process stack when coroutine ptr is not null // scan main process stack when coroutine ptr is null // this scan process must execute because when running coroutine, // the nas_co related to it will not update it's context(like `top`) until the coroutine suspends or exits. for(var* i=stack;i<=top;++i) { - bfs.push(*i); + bfs.push_back(*i); } - bfs.push(funcr); - bfs.push(upvalr); - bfs.push(temp); + bfs.push_back(funcr); + bfs.push_back(upvalr); + bfs.push_back(temp); if (cort) { // scan main process stack for(var* i=mctx.stack;i<=mctx.top;++i) { - bfs.push(*i); + bfs.push_back(*i); } - bfs.push(mctx.funcr); - bfs.push(mctx.upvalr); + bfs.push_back(mctx.funcr); + bfs.push_back(mctx.upvalr); } while(!bfs.empty()) { - var tmp=bfs.front(); - bfs.pop(); + var tmp=bfs.back(); + bfs.pop_back(); if (tmp.type<=vm_num || tmp.val.gcobj->mark) { continue; } @@ -546,32 +537,32 @@ void gc::mark() { switch(tmp.type) { case vm_vec: for(auto& i:tmp.vec().elems) { - bfs.push(i); + bfs.push_back(i); } break; case vm_hash: for(auto& i:tmp.hash().elems) { - bfs.push(i.second); + bfs.push_back(i.second); } break; case vm_func: for(auto& i:tmp.func().local) { - bfs.push(i); + bfs.push_back(i); } for(auto& i:tmp.func().upval) { - bfs.push(i); + bfs.push_back(i); } break; case vm_upval: for(auto& i:tmp.upval().elems) { - bfs.push(i); + bfs.push_back(i); } break; case vm_co: - bfs.push(tmp.co().funcr); - bfs.push(tmp.co().upvalr); + bfs.push_back(tmp.co().funcr); + bfs.push_back(tmp.co().upvalr); for(var* i=tmp.co().stack;i<=tmp.co().top;++i) { - bfs.push(*i); + bfs.push_back(*i); } break; } @@ -582,7 +573,7 @@ void gc::sweep() { for(auto i:memory) { if (i->mark==GC_UNCOLLECTED) { i->clear(); - unused[i->type-vm_str].push(i); + unused[i->type-vm_str].push_back(i); i->mark=GC_COLLECTED; } else if (i->mark==GC_FOUND) { i->mark=GC_UNCOLLECTED; @@ -596,7 +587,7 @@ void gc::extend(u8 type) { for(u32 i=0;i& s,const std::vector& argv) { for(u32 j=0;jmark=GC_UNCOLLECTED; - unused[index].pop(); + unused[index].pop_back(); return ret; } diff --git a/test/coroutine.nas b/test/coroutine.nas index c7b91d1..8861054 100644 --- a/test/coroutine.nas +++ b/test/coroutine.nas @@ -73,10 +73,11 @@ println("coroutine state:\e[91m ",coroutine.status(co),"\e[0m"); println("ok"); # pressure test -for(var t=0;t<5;t+=1){ +for(var t=0;t<10;t+=1){ var productor=func(){ - for(var i=0;;i+=1) + while(1){ coroutine.yield(i); + } } var total=1000; # ms var co=coroutine.create(productor); @@ -86,14 +87,16 @@ for(var t=0;t<5;t+=1){ var bar=process_bar.high_resolution_bar(40); var consumer=func(){ counter+=1; - for(var i=0;i<5;i+=1) + for(var i=0;i1/100){ last_step=i; - print(bar.bar((i+1)/n)~" "~str(int((i+1)/n*100))~"% \r"); + print(" ",bar.bar((i+1)/n)~" "~str(int((i+1)/n*100))~"% \r"); } } - print(bar.bar((i+1)/n)~" 100% | ",ts.elapsedMSec()/1000," s | "); + print(" ",bar.bar((i+1)/n)~" 100% | ",ts.elapsedMSec()/1000," s | "); var mess=func(vec){ var s=size(vec);