📝 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
|
.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
|
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.exe:$(SRC)
|
||||||
nasal_gc.h nasal_import.h nasal_lexer.h nasal_parse.h nasal_vm.h nasal_dbg.h nasal.h
|
|
||||||
g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static
|
g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static
|
||||||
test:nasal
|
test:nasal
|
||||||
@ ./nasal -op -e test/ascii-art.nas
|
@ ./nasal -op -e test/ascii-art.nas
|
||||||
|
|
|
@ -9,7 +9,7 @@ private:
|
||||||
bool next_step;
|
bool next_step;
|
||||||
uint16_t bk_fidx;
|
uint16_t bk_fidx;
|
||||||
uint32_t bk_line;
|
uint32_t bk_line;
|
||||||
file_line src;
|
fstreamline src;
|
||||||
|
|
||||||
std::vector<std::string> parse(const std::string&);
|
std::vector<std::string> parse(const std::string&);
|
||||||
uint16_t get_fileindex(const std::string&);
|
uint16_t get_fileindex(const std::string&);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
class file_line
|
class fstreamline
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string file;
|
std::string file;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
size_t size(){return res.size();}
|
size_t size(){return res.size();}
|
||||||
};
|
};
|
||||||
|
|
||||||
class nasal_err:public file_line
|
class nasal_err:public fstreamline
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint32_t error;
|
uint32_t error;
|
||||||
|
|
35
nasal_gc.h
35
nasal_gc.h
|
@ -447,15 +447,15 @@ struct nasal_gc
|
||||||
} main_ctx;
|
} main_ctx;
|
||||||
|
|
||||||
/* runtime context */
|
/* runtime context */
|
||||||
uint32_t& pc; // program counter
|
uint32_t& pc; // program counter
|
||||||
nasal_ref*& localr; // local scope register
|
nasal_ref*& localr; // local scope register
|
||||||
nasal_ref*& memr; // used for mem_call
|
nasal_ref*& memr; // used for mem_call
|
||||||
nasal_ref& funcr; // function register
|
nasal_ref& funcr; // function register
|
||||||
nasal_ref& upvalr; // upvalue register
|
nasal_ref& upvalr; // upvalue register
|
||||||
nasal_ref*& canary; // avoid stackoverflow
|
nasal_ref*& canary; // avoid stackoverflow
|
||||||
nasal_ref*& top; // stack top
|
nasal_ref*& top; // stack top
|
||||||
nasal_ref* stack; // stack pointer
|
nasal_ref* stack; // stack pointer
|
||||||
nasal_co* coroutine; // running coroutine
|
nasal_co* coroutine; // running coroutine
|
||||||
|
|
||||||
/* constants and memory pool */
|
/* constants and memory pool */
|
||||||
std::vector<nasal_ref> strs; // reserved address for const vm_str
|
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
|
std::queue<nasal_val*> unused[gc_tsize]; // gc free list
|
||||||
|
|
||||||
/* values for analysis */
|
/* values for analysis */
|
||||||
uint64_t size[gc_tsize];
|
uint64_t size[gc_tsize];
|
||||||
uint64_t count[gc_tsize];
|
uint64_t count[gc_tsize];
|
||||||
uint64_t allocc[gc_tsize];
|
uint64_t allocc[gc_tsize];
|
||||||
nasal_gc(
|
nasal_gc(
|
||||||
uint32_t& _pc,
|
uint32_t& _pc,
|
||||||
nasal_ref*& _localr,
|
nasal_ref*& _localr,
|
||||||
|
@ -499,11 +499,10 @@ struct nasal_gc
|
||||||
void nasal_gc::mark()
|
void nasal_gc::mark()
|
||||||
{
|
{
|
||||||
std::queue<nasal_ref> bfs;
|
std::queue<nasal_ref> bfs;
|
||||||
|
|
||||||
// scan coroutine process stack when coroutine ptr is not null
|
// scan coroutine process stack when coroutine ptr is not null
|
||||||
// scan main process stack when coroutine ptr is null
|
// scan main process stack when coroutine ptr is null
|
||||||
// this scan process must execute because when running coroutine,
|
// 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)
|
for(nasal_ref* i=stack;i<=top;++i)
|
||||||
bfs.push(*i);
|
bfs.push(*i);
|
||||||
bfs.push(funcr);
|
bfs.push(funcr);
|
||||||
|
@ -622,13 +621,13 @@ void nasal_gc::clear()
|
||||||
void nasal_gc::info()
|
void nasal_gc::info()
|
||||||
{
|
{
|
||||||
const char* name[]={"str ","vec ","hash ","func ","upval","obj ","co "};
|
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)
|
for(uint8_t i=0;i<gc_tsize;++i)
|
||||||
std::cout<<" "<<name[i]<<" | gc | "<<count[i]<<"\n"
|
if(count[i] || allocc[i])
|
||||||
<<" | new | "<<allocc[i]<<"\n";
|
std::cout<<" "<<name[i]<<" | "<<count[i]<<","<<allocc[i]<<"\n";
|
||||||
std::cout<<"\nmemory allocator info(max size)\n";
|
std::cout<<"\nmemory allocator info(max size)\n";
|
||||||
for(uint8_t i=0;i<gc_tsize;++i)
|
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)
|
nasal_ref nasal_gc::alloc(uint8_t type)
|
||||||
{
|
{
|
||||||
|
|
21
nasal_vm.h
21
nasal_vm.h
|
@ -21,7 +21,7 @@ protected:
|
||||||
/* main stack */
|
/* main stack */
|
||||||
nasal_ref stack[STACK_DEPTH];
|
nasal_ref stack[STACK_DEPTH];
|
||||||
|
|
||||||
/* values used for debug */
|
/* values used for debugger */
|
||||||
size_t files_size;
|
size_t files_size;
|
||||||
const std::string* files; // ref from nasal_import
|
const std::string* files; // ref from nasal_import
|
||||||
const opcode* bytecode; // ref from nasal_codegen
|
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;
|
typedef std::pair<uint32_t,uint64_t> op;
|
||||||
std::vector<op> opcall;
|
std::vector<op> opcall;
|
||||||
for(uint32_t i=0;i<=op_ret;++i)
|
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(
|
std::sort(
|
||||||
opcall.begin(),
|
opcall.begin(),
|
||||||
opcall.end(),
|
opcall.end(),
|
||||||
|
@ -364,13 +365,19 @@ void nasal_vm::opcallsort(const uint64_t* arr)
|
||||||
std::cout<<"\noperands call info";
|
std::cout<<"\noperands call info";
|
||||||
uint64_t total=0;
|
uint64_t total=0;
|
||||||
for(auto& i:opcall)
|
for(auto& i:opcall)
|
||||||
{
|
|
||||||
if(!i.second)
|
|
||||||
break;
|
|
||||||
total+=i.second;
|
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)
|
void nasal_vm::die(std::string str)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue