mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-25 14:00:18 +00:00
some refactor
This commit is contained in:
parent
51a3c93f69
commit
90a9a404e2
@ -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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user