From a04ed2a4aa22bac4ff3cfb489b50ccec23b815ff Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 6 Jul 2022 11:57:40 +0800 Subject: [PATCH] :memo: change makefile and update output format of --opcnt and --detail --- makefile | 22 ++++++++++++++++++---- nasal_dbg.h | 2 +- nasal_err.h | 4 ++-- nasal_gc.h | 35 +++++++++++++++++------------------ nasal_vm.h | 21 ++++++++++++++------- 5 files changed, 52 insertions(+), 32 deletions(-) diff --git a/makefile b/makefile index 186b3fc..56a4aa3 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,23 @@ .PHONY:test -nasal:main.cpp nasal_ast.h nasal_err.h nasal_builtin.h nasal_opt.h nasal_codegen.h\ - nasal_gc.h nasal_import.h nasal_lexer.h nasal_parse.h nasal_vm.h nasal_dbg.h nasal.h + +SRC=\ + main.cpp\ + nasal_ast.h\ + nasal_err.h\ + nasal_builtin.h\ + nasal_opt.h\ + nasal_codegen.h\ + nasal_gc.h\ + nasal_import.h\ + nasal_lexer.h\ + nasal_parse.h\ + nasal_vm.h\ + nasal_dbg.h\ + nasal.h + +nasal:$(SRC) clang++ -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall -nasal.exe:main.cpp nasal_ast.h nasal_err.h nasal_builtin.h nasal_opt.h nasal_codegen.h\ - nasal_gc.h nasal_import.h nasal_lexer.h nasal_parse.h nasal_vm.h nasal_dbg.h nasal.h +nasal.exe:$(SRC) g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static test:nasal @ ./nasal -op -e test/ascii-art.nas diff --git a/nasal_dbg.h b/nasal_dbg.h index daa2b29..ce48631 100644 --- a/nasal_dbg.h +++ b/nasal_dbg.h @@ -9,7 +9,7 @@ private: bool next_step; uint16_t bk_fidx; uint32_t bk_line; - file_line src; + fstreamline src; std::vector parse(const std::string&); uint16_t get_fileindex(const std::string&); diff --git a/nasal_err.h b/nasal_err.h index 1edacf9..7b52877 100644 --- a/nasal_err.h +++ b/nasal_err.h @@ -5,7 +5,7 @@ #include #include -class file_line +class fstreamline { protected: std::string file; @@ -40,7 +40,7 @@ public: size_t size(){return res.size();} }; -class nasal_err:public file_line +class nasal_err:public fstreamline { private: uint32_t error; diff --git a/nasal_gc.h b/nasal_gc.h index ceeeb67..0eed8a1 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -447,15 +447,15 @@ 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 @@ -464,9 +464,9 @@ struct nasal_gc std::queue unused[gc_tsize]; // gc free list /* values for analysis */ - uint64_t size[gc_tsize]; - uint64_t count[gc_tsize]; - uint64_t allocc[gc_tsize]; + uint64_t size[gc_tsize]; + uint64_t count[gc_tsize]; + uint64_t allocc[gc_tsize]; nasal_gc( uint32_t& _pc, nasal_ref*& _localr, @@ -499,11 +499,10 @@ struct nasal_gc void nasal_gc::mark() { std::queue 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 nasal_co related to it will not update it's context until the coroutine suspends or exits. + // the nasal_co related to it will not update it's context(like `top`) until the coroutine suspends or exits. for(nasal_ref* i=stack;i<=top;++i) bfs.push(*i); bfs.push(funcr); @@ -622,13 +621,13 @@ void nasal_gc::clear() void nasal_gc::info() { const char* name[]={"str ","vec ","hash ","func ","upval","obj ","co "}; - std::cout<<"\ngarbage collector info\n"; + std::cout<<"\ngarbage collector info(gc/alloc)\n"; for(uint8_t i=0;i op; std::vector opcall; for(uint32_t i=0;i<=op_ret;++i) - opcall.push_back({i,arr[i]}); + if(arr[i]) + opcall.push_back({i,arr[i]}); std::sort( opcall.begin(), opcall.end(), @@ -364,13 +365,19 @@ void nasal_vm::opcallsort(const uint64_t* arr) std::cout<<"\noperands call info"; uint64_t total=0; for(auto& i:opcall) - { - if(!i.second) - break; total+=i.second; - std::cout<<"\n "<0) + std::cout<<"\n "<