📝 change makefile and update output format of --opcnt and --detail
This commit is contained in:
parent
82b33ffe4a
commit
a04ed2a4aa
22
makefile
22
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
|
||||
|
|
|
@ -9,7 +9,7 @@ private:
|
|||
bool next_step;
|
||||
uint16_t bk_fidx;
|
||||
uint32_t bk_line;
|
||||
file_line src;
|
||||
fstreamline src;
|
||||
|
||||
std::vector<std::string> parse(const std::string&);
|
||||
uint16_t get_fileindex(const std::string&);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <fstream>
|
||||
#include <cstring>
|
||||
|
||||
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;
|
||||
|
|
35
nasal_gc.h
35
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<nasal_ref> strs; // reserved address for const vm_str
|
||||
|
@ -464,9 +464,9 @@ struct nasal_gc
|
|||
std::queue<nasal_val*> 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<nasal_ref> 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<gc_tsize;++i)
|
||||
std::cout<<" "<<name[i]<<" | gc | "<<count[i]<<"\n"
|
||||
<<" | new | "<<allocc[i]<<"\n";
|
||||
if(count[i] || allocc[i])
|
||||
std::cout<<" "<<name[i]<<" | "<<count[i]<<","<<allocc[i]<<"\n";
|
||||
std::cout<<"\nmemory allocator info(max size)\n";
|
||||
for(uint8_t i=0;i<gc_tsize;++i)
|
||||
std::cout<<" "<<name[i]<<" | "<<ini[i]+size[i]*incr[i]<<" (+"<<size[i]<<")\n";
|
||||
std::cout<<" "<<name[i]<<" | "<<ini[i]+size[i]*incr[i]<<" (+"<<size[i]<<")\n";
|
||||
}
|
||||
nasal_ref nasal_gc::alloc(uint8_t type)
|
||||
{
|
||||
|
|
21
nasal_vm.h
21
nasal_vm.h
|
@ -21,7 +21,7 @@ protected:
|
|||
/* main stack */
|
||||
nasal_ref stack[STACK_DEPTH];
|
||||
|
||||
/* values used for debug */
|
||||
/* values used for debugger */
|
||||
size_t files_size;
|
||||
const std::string* files; // ref from nasal_import
|
||||
const opcode* bytecode; // ref from nasal_codegen
|
||||
|
@ -355,7 +355,8 @@ void nasal_vm::opcallsort(const uint64_t* arr)
|
|||
typedef std::pair<uint32_t,uint64_t> op;
|
||||
std::vector<op> 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 "<<code_table[i.first].name<<" : "<<i.second;
|
||||
for(auto& i:opcall)
|
||||
{
|
||||
uint64_t rate=i.second*100/total;
|
||||
if(rate>0)
|
||||
std::cout<<"\n "<<code_table[i.first].name<<" : "<<i.second<<" ("<<rate<<"%)";
|
||||
else
|
||||
{
|
||||
std::cout<<"\n ...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::cout<<"\n total : "<<total<<'\n';
|
||||
std::cout<<"\n total : "<<total<<'\n';
|
||||
}
|
||||
void nasal_vm::die(std::string str)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue