From 452bb4a5d8c76d8c18fe24459969400e43b0a522 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Sun, 3 Jul 2022 22:46:28 +0800 Subject: [PATCH] :memo: change some identifiers' name. --- nasal_gc.h | 32 +++++++++++++++++--------------- nasal_lexer.h | 29 +++++++++++++++-------------- nasal_parse.h | 12 ++++++------ test/bf.nas | 7 +++++-- test/bfcolored.nas | 10 +++++----- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/nasal_gc.h b/nasal_gc.h index 223957a..0607c6a 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -22,7 +22,7 @@ enum vm_type:std::uint32_t{ const uint32_t gc_obj_size=vm_type_size-vm_str; // change parameters here to make your own efficient gc // better set bigger number on vm_vec -const uint32_t initialize[gc_obj_size]= +const uint32_t ini[gc_obj_size]= { 128, // vm_str 512, // vm_func @@ -32,7 +32,7 @@ const uint32_t initialize[gc_obj_size]= 0, // vm_obj 0 // vm_co }; -const uint32_t increment[gc_obj_size]= +const uint32_t incr[gc_obj_size]= { 256, // vm_str 512, // vm_func @@ -274,11 +274,12 @@ void nasal_vec::print() } printed=true; size_t iter=0; + size_t size=elems.size(); std::cout<<'['; for(auto& i:elems) { i.print(); - std::cout<<",]"[(++iter)==elems.size()]; + std::cout<<",]"[(++iter)==size]; } printed=false; } @@ -330,12 +331,13 @@ void nasal_hash::print() } printed=true; size_t iter=0; + size_t size=elems.size(); std::cout<<'{'; for(auto& i:elems) { std::cout<& s,const std::vector& get_tokens() const {return tokens;} + const std::vector& result() const {return tokens;} }; void nasal_lexer::open(const std::string& file) @@ -135,8 +136,7 @@ void nasal_lexer::open(const std::string& file) if(stat(file.c_str(),&buffer)==0 && !S_ISREG(buffer.st_mode)) { nerr.err("lexer","<"+file+"> is not a regular file."); - res=""; - return; + nerr.chkerr(); } std::ifstream fin(file,std::ios::binary); if(fin.fail()) @@ -148,11 +148,11 @@ void nasal_lexer::open(const std::string& file) res=ss.str(); } -uint32_t nasal_lexer::get_type(const std::string& tk_str) +uint32_t nasal_lexer::get_type(const std::string& str) { - for(int i=0;token_table[i].str;++i) - if(tk_str==token_table[i].str) - return token_table[i].tok_type; + for(uint32_t i=0;tok_table[i].str;++i) + if(str==tok_table[i].str) + return tok_table[i].type; return tok_null; } @@ -166,19 +166,20 @@ std::string nasal_lexer::utf8_gen() if(nbytes) { tmp+=res[ptr++]; - ++column; - for(uint32_t i=0;i12) cnt=0; @@ -171,7 +171,7 @@ var funcs=[ func{if(paper[ptr])pc=inum[pc];}, func{if(!paper[ptr])pc=inum[pc];}, func{paper[ptr]=input()[0];}, - func{print(table[paper[ptr]]);} + func{print(char[paper[ptr]]);} ]; var bf=func(program){