Browse Source

some refactor

blueloveTH 2 years ago
parent
commit
90a9a404e2
4 changed files with 1 additions and 7 deletions
  1. 0 1
      include/pocketpy/compiler.h
  2. 0 1
      include/pocketpy/lexer.h
  3. 1 3
      src/compiler.cpp
  4. 0 2
      src/lexer.cpp

+ 0 - 1
include/pocketpy/compiler.h

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

+ 0 - 1
include/pocketpy/lexer.h

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

+ 1 - 3
src/compiler.cpp

@@ -1196,15 +1196,13 @@ __EAT_DOTS_END:
     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)){
         this->vm = vm;
-        this->used = false;
         this->unknown_global_scope = unknown_global_scope;
         init_pratt_rules();
     }
 
 
     CodeObject_ Compiler::compile(){
-        PK_ASSERT(!used)
-        used = true;
+        PK_ASSERT(i == 0)       // make sure it is the first time to compile
 
         tokens = lexer.run();
         CodeObject_ code = push_global_context();

+ 0 - 2
src/lexer.cpp

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