some refactor

This commit is contained in:
blueloveTH 2024-02-25 13:06:41 +08:00
parent 51a3c93f69
commit 90a9a404e2
4 changed files with 1 additions and 7 deletions

View File

@ -25,7 +25,6 @@ class Compiler {
stack_no_copy<CodeEmitContext> contexts; stack_no_copy<CodeEmitContext> contexts;
VM* vm; VM* vm;
bool unknown_global_scope; // for eval/exec() call bool unknown_global_scope; // for eval/exec() call
bool used;
// for parsing token stream // for parsing token stream
int i = 0; int i = 0;
std::vector<Token> tokens; std::vector<Token> tokens;

View File

@ -106,7 +106,6 @@ struct Lexer {
std::vector<Token> nexts; std::vector<Token> nexts;
stack_no_copy<int, small_vector_no_copy_and_move<int, 8>> indents; stack_no_copy<int, small_vector_no_copy_and_move<int, 8>> indents;
int brackets_level = 0; int brackets_level = 0;
bool used = false;
char peekchar() const{ return *curr_char; } char peekchar() const{ return *curr_char; }
bool match_n_chars(int n, char c0); bool match_n_chars(int n, char c0);

View File

@ -1196,15 +1196,13 @@ __EAT_DOTS_END:
Compiler::Compiler(VM* vm, std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope) Compiler::Compiler(VM* vm, std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope)
:lexer(vm, std::make_shared<SourceData>(source, filename, mode)){ :lexer(vm, std::make_shared<SourceData>(source, filename, mode)){
this->vm = vm; this->vm = vm;
this->used = false;
this->unknown_global_scope = unknown_global_scope; this->unknown_global_scope = unknown_global_scope;
init_pratt_rules(); init_pratt_rules();
} }
CodeObject_ Compiler::compile(){ CodeObject_ Compiler::compile(){
PK_ASSERT(!used) PK_ASSERT(i == 0) // make sure it is the first time to compile
used = true;
tokens = lexer.run(); tokens = lexer.run();
CodeObject_ code = push_global_context(); CodeObject_ code = push_global_context();

View File

@ -472,8 +472,6 @@ static bool is_unicode_Lo_char(uint32_t c) {
} }
std::vector<Token> Lexer::run() { std::vector<Token> Lexer::run() {
PK_ASSERT(!used)
used = true;
while (lex_one_token()); while (lex_one_token());
return std::move(nexts); return std::move(nexts);
} }