🚀 change `std::cout` to `std::clog` to put some log info
This commit is contained in:
parent
f68a512845
commit
af761641d6
8
main.cpp
8
main.cpp
|
@ -12,7 +12,7 @@ const uint32_t VM_OPTIMIZE =0x100;
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
std::cout
|
std::clog
|
||||||
<<" ,--#-,\n"
|
<<" ,--#-,\n"
|
||||||
<<"<3 / \\____\\ <3\n"
|
<<"<3 / \\____\\ <3\n"
|
||||||
<<" |_|__A_|\n"
|
<<" |_|__A_|\n"
|
||||||
|
@ -47,7 +47,7 @@ void help()
|
||||||
|
|
||||||
void logo()
|
void logo()
|
||||||
{
|
{
|
||||||
std::cout
|
std::clog
|
||||||
<<" __ _\n"
|
<<" __ _\n"
|
||||||
<<" /\\ \\ \\__ _ ___ __ _| |\n"
|
<<" /\\ \\ \\__ _ ___ __ _| |\n"
|
||||||
<<" / \\/ / _` / __|/ _` | |\n"
|
<<" / \\/ / _` / __|/ _` | |\n"
|
||||||
|
@ -64,7 +64,7 @@ void logo()
|
||||||
|
|
||||||
void err()
|
void err()
|
||||||
{
|
{
|
||||||
std::cout
|
std::cerr
|
||||||
<<"invalid argument(s).\n"
|
<<"invalid argument(s).\n"
|
||||||
<<"use <nasal -h> to get help.\n";
|
<<"use <nasal -h> to get help.\n";
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
|
@ -112,7 +112,7 @@ void execute(const std::string& file,const std::vector<std::string>& argv,const
|
||||||
auto start=std::chrono::high_resolution_clock::now();
|
auto start=std::chrono::high_resolution_clock::now();
|
||||||
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);
|
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);
|
||||||
auto end=std::chrono::high_resolution_clock::now();
|
auto end=std::chrono::high_resolution_clock::now();
|
||||||
std::cout<<"process exited after "<<(end-start).count()*1.0/std::chrono::high_resolution_clock::duration::period::den<<"s.\n";
|
std::clog<<"process exited after "<<(end-start).count()*1.0/std::chrono::high_resolution_clock::duration::period::den<<"s.\n";
|
||||||
}
|
}
|
||||||
else if(cmd&VM_EXEC)
|
else if(cmd&VM_EXEC)
|
||||||
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);
|
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __NASAL_GC_H__
|
#ifndef __NASAL_GC_H__
|
||||||
#define __NASAL_GC_H__
|
#define __NASAL_GC_H__
|
||||||
|
|
||||||
enum vm_type:std::uint32_t{
|
enum vm_type:std::uint8_t{
|
||||||
/* none-gc object */
|
/* none-gc object */
|
||||||
vm_none=0,
|
vm_none=0,
|
||||||
vm_cnt,
|
vm_cnt,
|
||||||
|
@ -76,12 +76,6 @@ struct nasal_ref
|
||||||
// vm_addr
|
// vm_addr
|
||||||
nasal_ref(const uint8_t t,nasal_ref* n):type(t){val.addr=n;}
|
nasal_ref(const uint8_t t,nasal_ref* n):type(t){val.addr=n;}
|
||||||
nasal_ref(const nasal_ref& nr):type(nr.type),val(nr.val){}
|
nasal_ref(const nasal_ref& nr):type(nr.type),val(nr.val){}
|
||||||
nasal_ref& operator=(const nasal_ref& nr)
|
|
||||||
{
|
|
||||||
type=nr.type;
|
|
||||||
val=nr.val;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool operator==(const nasal_ref& nr){return type==nr.type && val.gcobj==nr.val.gcobj;}
|
bool operator==(const nasal_ref& nr){return type==nr.type && val.gcobj==nr.val.gcobj;}
|
||||||
bool operator!=(const nasal_ref& nr){return type!=nr.type || val.gcobj!=nr.val.gcobj;}
|
bool operator!=(const nasal_ref& nr){return type!=nr.type || val.gcobj!=nr.val.gcobj;}
|
||||||
// number and string can be translated to each other
|
// number and string can be translated to each other
|
||||||
|
|
15
nasal_vm.h
15
nasal_vm.h
|
@ -154,6 +154,10 @@ void nasal_vm::init(
|
||||||
funcr=upvalr=nil;
|
funcr=upvalr=nil;
|
||||||
canary=stack+STACK_DEPTH-1; // stack[STACK_DEPTH-1]
|
canary=stack+STACK_DEPTH-1; // stack[STACK_DEPTH-1]
|
||||||
top=stack;
|
top=stack;
|
||||||
|
|
||||||
|
/* clear main stack */
|
||||||
|
for(uint32_t i=0;i<STACK_DEPTH;++i)
|
||||||
|
stack[i]=nil;
|
||||||
}
|
}
|
||||||
void nasal_vm::valinfo(nasal_ref& val)
|
void nasal_vm::valinfo(nasal_ref& val)
|
||||||
{
|
{
|
||||||
|
@ -325,20 +329,20 @@ void nasal_vm::opcallsort(const uint64_t* arr)
|
||||||
std::sort(opcall.begin(),opcall.end(),
|
std::sort(opcall.begin(),opcall.end(),
|
||||||
[](const op& a,const op& b){return a.second>b.second;}
|
[](const op& a,const op& b){return a.second>b.second;}
|
||||||
);
|
);
|
||||||
std::cout<<"\noperands call info";
|
std::clog<<"\noperands call info";
|
||||||
for(auto& i:opcall)
|
for(auto& i:opcall)
|
||||||
{
|
{
|
||||||
uint64_t rate=i.second*100/total;
|
uint64_t rate=i.second*100/total;
|
||||||
if(rate)
|
if(rate)
|
||||||
std::cout<<"\n "<<code_table[i.first].name
|
std::clog<<"\n "<<code_table[i.first].name
|
||||||
<<" : "<<i.second<<" ("<<rate<<"%)";
|
<<" : "<<i.second<<" ("<<rate<<"%)";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout<<"\n ...";
|
std::clog<<"\n ...";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout<<"\n total : "<<total<<'\n';
|
std::clog<<"\n total : "<<total<<'\n';
|
||||||
}
|
}
|
||||||
void nasal_vm::die(const std::string& str)
|
void nasal_vm::die(const std::string& str)
|
||||||
{
|
{
|
||||||
|
@ -365,8 +369,7 @@ inline bool nasal_vm::condition(nasal_ref val)
|
||||||
inline void nasal_vm::opr_intg()
|
inline void nasal_vm::opr_intg()
|
||||||
{
|
{
|
||||||
// global values store on stack
|
// global values store on stack
|
||||||
for(uint32_t i=0;i<imm[pc];++i)
|
top+=imm[pc];
|
||||||
(top++)[0].type=vm_nil;
|
|
||||||
--top;// point to the top
|
--top;// point to the top
|
||||||
}
|
}
|
||||||
inline void nasal_vm::opr_intl()
|
inline void nasal_vm::opr_intl()
|
||||||
|
|
Loading…
Reference in New Issue