Ver Fonte

some fix

blueloveTH há 1 ano atrás
pai
commit
bec168ab53

+ 1 - 1
cmake_build.py

@@ -14,7 +14,7 @@ if len(sys.argv) == 2:
 else:
     config = 'Release'
 
-assert config in ['Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel']
+assert config in ['Debug', 'Release', 'RelWithDebInfo']
 
 os.chdir("build")
 

+ 4 - 1
include/pocketpy/compiler/compiler.hpp

@@ -129,7 +129,10 @@ struct Compiler {
 
     [[nodiscard]] Error* SyntaxError(const char* msg = "invalid syntax", ...) noexcept;
     [[nodiscard]] Error* IndentationError(const char* msg) noexcept{ return lexer._error(false, "IndentationError", msg, {}); }
-    [[nodiscard]] Error* NeedMoreLines() noexcept{ return lexer._error(false, "NeedMoreLines", "", {}, (i64)ctx()->is_compiling_class); }
+    [[nodiscard]] Error* NeedMoreLines() noexcept{
+        assert(false);
+        return lexer._error(false, "NeedMoreLines", "", {}, (i64)ctx()->is_compiling_class);
+    }
 
 public:
     Compiler(VM* vm, std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope = false) noexcept;

+ 6 - 4
include/pocketpy/compiler/lexer.hpp

@@ -129,14 +129,16 @@ struct Lexer {
     [[nodiscard]] Error* _error(bool lexer_err, const char* type, const char* msg, va_list args, i64 userdata=0) noexcept;
     [[nodiscard]] Error* SyntaxError(const char* fmt, ...) noexcept;
     [[nodiscard]] Error* IndentationError(const char* msg) noexcept { return _error(true, "IndentationError", msg, {}); }
-    [[nodiscard]] Error* NeedMoreLines() noexcept { return _error(true, "NeedMoreLines", "", {}, 0); }
+    [[nodiscard]] Error* NeedMoreLines() noexcept {
+        assert(false);
+        return _error(true, "NeedMoreLines", "", {}, 0);
+    }
 
     Lexer(VM* vm, std::shared_ptr<SourceData> src) noexcept;
     
     [[nodiscard]] Error* run() noexcept;
-
-    void from_precompiled();
-    [[nodiscard]] Error* precompile(Str* out);
+    [[nodiscard]] Error* from_precompiled() noexcept;
+    [[nodiscard]] Error* precompile(Str* out) noexcept;
 };
 
 enum class IntParsingResult {

+ 6 - 2
src/compiler/compiler.cpp

@@ -1279,12 +1279,16 @@ Error* Compiler::compile(CodeObject_* out) noexcept{
     Error* err;
     check(lexer.run());
 
-    // for(int i=0; i<lexer.nexts.size(); i++){
-    //     printf("%s: %s\n", TK_STR(tk(i).type), tk(i).str().escape().c_str());
+    // if(lexer.src->filename[0] != '<'){
+    //     printf("%s\n", lexer.src->filename.c_str());
+    //     for(int i=0; i<lexer.nexts.size(); i++){
+    //         printf("%s: %s\n", TK_STR(tk(i).type), tk(i).str().escape().c_str());
+    //     }
     // }
 
     CodeObject_ code = push_global_context();
 
+    assert(curr().type == TK("@sof"));
     advance();         // skip @sof, so prev() is always valid
     match_newlines();  // skip possible leading '\n'
 

+ 10 - 6
src/compiler/lexer.cpp

@@ -537,8 +537,7 @@ Error* Lexer::run() noexcept{
     assert(!this->used);
     this->used = true;
     if(src->is_precompiled) {
-        from_precompiled();
-        return NULL;
+        return from_precompiled();
     }
     // push initial tokens
     this->nexts.push_back(Token{TK("@sof"), token_start, 0, current_line, brackets_level, {}});
@@ -552,13 +551,17 @@ Error* Lexer::run() noexcept{
     return NULL;
 }
 
-void Lexer::from_precompiled() {
+Error* Lexer::from_precompiled() noexcept{
     TokenDeserializer deserializer(src->source.c_str());
     deserializer.curr += 5;  // skip "pkpy:"
     std::string_view version = deserializer.read_string('\n');
 
-    assert(version == PK_VERSION);
-    assert(deserializer.read_uint('\n') == (i64)src->mode);
+    if(version != PK_VERSION){
+        return SyntaxError("precompiled version mismatch");
+    }
+    if(deserializer.read_uint('\n') != (i64)src->mode){
+        return SyntaxError("precompiled mode mismatch");
+    }
 
     int count = deserializer.read_count();
     vector<Str>& precompiled_tokens = src->_precompiled_tokens;
@@ -600,9 +603,10 @@ void Lexer::from_precompiled() {
         }
         nexts.push_back(t);
     }
+    return NULL;
 }
 
-Error* Lexer::precompile(Str* out) {
+Error* Lexer::precompile(Str* out) noexcept{
     assert(!src->is_precompiled);
     Error* err = run();
     if(err) return err;