From cfbec9a3f1999337c0c29a4dab8f1a5e51d7ab91 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Mon, 18 Jul 2022 23:54:44 +0800 Subject: [PATCH] :memo: change identifiers' name --- nasal.h | 5 +---- nasal_codegen.h | 8 ++++---- nasal_dbg.h | 8 ++++---- nasal_import.h | 2 +- nasal_vm.h | 30 +++++++++++++++--------------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/nasal.h b/nasal.h index b05b6b5..e93cef6 100644 --- a/nasal.h +++ b/nasal.h @@ -5,9 +5,7 @@ #ifndef _MSC_VER #include #include -#endif - -#ifdef _MSC_VER +#else #include #include #endif @@ -34,7 +32,6 @@ #include #include -#include #ifdef _WIN32 #include diff --git a/nasal_codegen.h b/nasal_codegen.h index f336d5f..e1bdafc 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -310,9 +310,9 @@ public: nasal_codegen(nasal_err& e):fileindex(0),nerr(e),file(nullptr){} void compile(const nasal_parse&,const nasal_import&); void print(); - const std::vector& get_strs() const {return str_res;} - const std::vector& get_nums() const {return num_res;} - const std::vector& get_code() const {return code;} + const std::vector& strs() const {return str_res;} + const std::vector& nums() const {return num_res;} + const std::vector& codes() const {return code;} }; void nasal_codegen::die(const std::string& info,const uint32_t line) @@ -1282,7 +1282,7 @@ void nasal_codegen::ret_gen(const nasal_ast& ast) void nasal_codegen::compile(const nasal_parse& parse,const nasal_import& import) { fileindex=0; - file=import.get_file().data(); + file=import.filelist().data(); in_iterloop.push(0); regist_num(0); diff --git a/nasal_dbg.h b/nasal_dbg.h index f0aede6..3fee05e 100644 --- a/nasal_dbg.h +++ b/nasal_dbg.h @@ -179,8 +179,8 @@ void nasal_dbg::run( const std::vector& argv) { detail_info=true; - fsize=linker.get_file().size(); - init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file(),argv); + fsize=linker.filelist().size(); + init(gen.strs(),gen.nums(),gen.codes(),linker.filelist(),argv); #ifndef _MSC_VER const void* oprs[]= { @@ -205,7 +205,7 @@ void nasal_dbg::run( &&mcallv, &&mcallh, &&ret }; std::vector code; - for(auto& i:gen.get_code()) + for(auto& i:gen.codes()) { code.push_back(oprs[i.op]); imm.push_back(i.num); @@ -256,7 +256,7 @@ void nasal_dbg::run( &nasal_dbg::opr_ret }; std::vector code; - for(auto& i:gen.get_code()) + for(auto& i:gen.codes()) { code.push_back(oprs[i.op]); imm.push_back(i.num); diff --git a/nasal_import.h b/nasal_import.h index 9400049..0c343a3 100644 --- a/nasal_import.h +++ b/nasal_import.h @@ -22,7 +22,7 @@ private: public: nasal_import(nasal_err&); void link(nasal_parse&,const std::string&); - const std::vector& get_file() const {return files;} + const std::vector& filelist() const {return files;} }; nasal_import::nasal_import(nasal_err& e):lib_loaded(false),nerr(e){ diff --git a/nasal_vm.h b/nasal_vm.h index ac442b8..d0eb356 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -678,10 +678,10 @@ inline void nasal_vm::opr_callv() { std::string& str=vec.str(); int num=val.tonum(); - int str_size=str.length(); - if(num<-str_size || num>=str_size) + int len=str.length(); + if(num<-len || num>=len) die("callv: index out of range:"+std::to_string(val.tonum())); - top[0]={vm_num,double((uint8_t)str[num>=0? num:num+str_size])}; + top[0]={vm_num,double((uint8_t)str[num>=0? num:num+len])}; } else die("callv: must call a vector/hash/string"); @@ -745,7 +745,8 @@ inline void nasal_vm::opr_callfv() for(uint32_t i=min_size;i>=1;--i)// load arguments local[i]=local[i-1]; local[0]=func.local[0];// load "me" - for(uint32_t i=min_size+1;i=0) local[psize+1]=dynamic; @@ -803,7 +804,7 @@ inline void nasal_vm::opr_callb() // (top) will be set to another context.top, instead of main_context.top top[0]=(*builtin[imm[pc]].func)(localr,gc); if(top[0].type==vm_none) - die("native function error."); + die("native function error"); } inline void nasal_vm::opr_slcbeg() { @@ -814,7 +815,7 @@ inline void nasal_vm::opr_slcbeg() // +--------------+ (++top)[0]=gc.alloc(vm_vec); if(top[-1].type!=vm_vec) - die("slcbegin: must slice a vector"); + die("slcbeg: must slice a vector"); } inline void nasal_vm::opr_slcend() { @@ -973,7 +974,7 @@ void nasal_vm::run( const bool detail) { detail_info=detail; - init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file(),argv); + init(gen.strs(),gen.nums(),gen.codes(),linker.filelist(),argv); uint64_t count[op_ret+1]={0}; #ifndef _MSC_VER const void* oprs[]= @@ -999,7 +1000,7 @@ void nasal_vm::run( &&mcallv, &&mcallh, &&ret }; std::vector code; - for(auto& i:gen.get_code()) + for(auto& i:gen.codes()) { code.push_back(oprs[i.op]); imm.push_back(i.num); @@ -1049,16 +1050,15 @@ void nasal_vm::run( &nasal_vm::opr_mcallv, &nasal_vm::opr_mcallh, &nasal_vm::opr_ret }; - typedef struct{nafunc ptr;uint32_t type;} naf; - std::vector code; - for(auto& i:gen.get_code()) + std::vector code; + for(auto& i:gen.codes()) { - code.push_back({oprs[i.op],i.op}); + code.push_back(i.op); imm.push_back(i.num); } - while(code[pc].ptr){ - ++count[code[pc].type]; - (this->*code[pc].ptr)(); + while(oprs[code[pc]]){ + ++count[code[pc]]; + (this->*oprs[code[pc]])(); if(top>=canary) break; ++pc;