🚀 change `std::cout` to `std::clog` to put some log info

This commit is contained in:
ValKmjolnir 2022-07-21 23:16:16 +08:00
parent f68a512845
commit af761641d6
3 changed files with 14 additions and 17 deletions

View File

@ -12,7 +12,7 @@ const uint32_t VM_OPTIMIZE =0x100;
void help()
{
std::cout
std::clog
<<" ,--#-,\n"
<<"<3 / \\____\\ <3\n"
<<" |_|__A_|\n"
@ -47,7 +47,7 @@ void help()
void logo()
{
std::cout
std::clog
<<" __ _\n"
<<" /\\ \\ \\__ _ ___ __ _| |\n"
<<" / \\/ / _` / __|/ _` | |\n"
@ -64,7 +64,7 @@ void logo()
void err()
{
std::cout
std::cerr
<<"invalid argument(s).\n"
<<"use <nasal -h> to get help.\n";
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();
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);
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)
vm.run(gen,linker,argv,cmd&VM_OPCALLNUM,cmd&VM_DBGINFO);

View File

@ -1,7 +1,7 @@
#ifndef __NASAL_GC_H__
#define __NASAL_GC_H__
enum vm_type:std::uint32_t{
enum vm_type:std::uint8_t{
/* none-gc object */
vm_none=0,
vm_cnt,
@ -76,12 +76,6 @@ struct nasal_ref
// vm_addr
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& 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;}
// number and string can be translated to each other

View File

@ -154,6 +154,10 @@ void nasal_vm::init(
funcr=upvalr=nil;
canary=stack+STACK_DEPTH-1; // stack[STACK_DEPTH-1]
top=stack;
/* clear main stack */
for(uint32_t i=0;i<STACK_DEPTH;++i)
stack[i]=nil;
}
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(),
[](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)
{
uint64_t rate=i.second*100/total;
if(rate)
std::cout<<"\n "<<code_table[i.first].name
std::clog<<"\n "<<code_table[i.first].name
<<" : "<<i.second<<" ("<<rate<<"%)";
else
{
std::cout<<"\n ...";
std::clog<<"\n ...";
break;
}
}
std::cout<<"\n total : "<<total<<'\n';
std::clog<<"\n total : "<<total<<'\n';
}
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()
{
// global values store on stack
for(uint32_t i=0;i<imm[pc];++i)
(top++)[0].type=vm_nil;
top+=imm[pc];
--top;// point to the top
}
inline void nasal_vm::opr_intl()