blueloveTH 1 год назад
Родитель
Сommit
5c486d1317
3 измененных файлов с 11 добавлено и 7 удалено
  1. 3 3
      include/pocketpy/compiler/lexer.hpp
  2. 1 1
      src/compiler/compiler.cpp
  3. 7 3
      src/compiler/lexer.cpp

+ 3 - 3
include/pocketpy/compiler/lexer.hpp

@@ -126,10 +126,10 @@ struct Lexer {
     [[nodiscard]] Error* lex_one_token(bool* eof) noexcept;
     [[nodiscard]] Error* lex_one_token(bool* eof) noexcept;
 
 
     /***** Error Reporter *****/
     /***** Error Reporter *****/
-    [[nodiscard]] Error* _error(bool lexer_err, const char* type, const char* msg, va_list args, i64 userdata=0) noexcept;
+    [[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* 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* IndentationError(const char* msg) noexcept { return _error(true, "IndentationError", msg, NULL); }
+    [[nodiscard]] Error* NeedMoreLines() noexcept { return _error(true, "NeedMoreLines", "", NULL, 0); }
 
 
     Lexer(VM* vm, std::shared_ptr<SourceData> src) noexcept;
     Lexer(VM* vm, std::shared_ptr<SourceData> src) noexcept;
     
     

+ 1 - 1
src/compiler/compiler.cpp

@@ -1340,7 +1340,7 @@ Compiler::~Compiler(){
 Error* Compiler::SyntaxError(const char* msg, ...) noexcept{
 Error* Compiler::SyntaxError(const char* msg, ...) noexcept{
     va_list args;
     va_list args;
     va_start(args, msg);
     va_start(args, msg);
-    Error* e = lexer._error(false, "SyntaxError", msg, args);
+    Error* e = lexer._error(false, "SyntaxError", msg, &args);
     e->lineno = err().line;
     e->lineno = err().line;
     e->cursor = err().start;
     e->cursor = err().start;
     va_end(args);
     va_end(args);

+ 7 - 3
src/compiler/lexer.cpp

@@ -500,7 +500,7 @@ Error* Lexer::lex_one_token(bool* eof) noexcept{
     return NULL;
     return NULL;
 }
 }
 
 
-Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list args, i64 userdata) noexcept{
+Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list* args, i64 userdata) noexcept{
     PK_THREAD_LOCAL Error err;
     PK_THREAD_LOCAL Error err;
     err.type = type;
     err.type = type;
     err.src = src;
     err.src = src;
@@ -515,7 +515,11 @@ Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list
         err.lineno = -1;
         err.lineno = -1;
         err.cursor = NULL;
         err.cursor = NULL;
     }
     }
-    vsnprintf(err.msg, sizeof(err.msg), msg, args);
+    if(args){
+        vsnprintf(err.msg, sizeof(err.msg), msg, *args);
+    }else{
+        std::strncpy(err.msg, msg, sizeof(err.msg));
+    }
     err.userdata = userdata;
     err.userdata = userdata;
     return &err;
     return &err;
 }
 }
@@ -523,7 +527,7 @@ Error* Lexer::_error(bool lexer_err, const char* type, const char* msg, va_list
 Error* Lexer::SyntaxError(const char* fmt, ...) noexcept{
 Error* Lexer::SyntaxError(const char* fmt, ...) noexcept{
     va_list args;
     va_list args;
     va_start(args, fmt);
     va_start(args, fmt);
-    Error* err = _error(true, "SyntaxError", fmt, args);
+    Error* err = _error(true, "SyntaxError", fmt, &args);
     va_end(args);
     va_end(args);
     return err;
     return err;
 }
 }