blueloveTH il y a 1 an
Parent
commit
fe8d102748

+ 1 - 4
3rd/lua_bridge/src/lua_bridge.cpp

@@ -321,10 +321,7 @@ PyVar lua_popx_to_python(VM* vm) {
 
 void initialize_lua_bridge(VM* vm, lua_State* newL){
     PyObject* mod = vm->new_module("lua");
-
-    if(_L != nullptr){
-        throw std::runtime_error("lua bridge already initialized");
-    }
+    assert(_L == nullptr);  // lua bridge already initialized
     _L = newL;
 
     vm->register_user_class<PyLuaTable>(mod, "Table");

+ 1 - 0
CMakeLists.txt

@@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 if(MSVC)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /Ox /jumptablerdata /GS-")
+    add_compile_options(/wd4267 /wd4244)
 else()
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -O2")
 

+ 2 - 0
include/pocketpy/common/namedict.hpp

@@ -5,6 +5,8 @@
 
 #include "pocketpy/config.h"
 
+#include <stdexcept>
+
 namespace pkpy{
 
 template<typename T>

+ 2 - 0
include/pocketpy/interpreter/profiler.hpp

@@ -2,6 +2,8 @@
 
 #include "pocketpy/interpreter/frame.hpp"
 
+#include <ctime>
+
 namespace pkpy {
 
 struct _LineRecord{

+ 2 - 0
include/pocketpy/interpreter/vm.hpp

@@ -9,6 +9,8 @@
 #include "pocketpy/interpreter/frame.hpp"
 #include "pocketpy/interpreter/profiler.hpp"
 
+#include <stdexcept>
+
 namespace pkpy{
 
 /* Stack manipulation macros */

+ 1 - 0
src/common/memorypool.cpp

@@ -3,6 +3,7 @@
 #include "pocketpy/config.h"
 
 #include <cstring>
+#include <stdexcept>
 
 namespace pkpy{
 

+ 2 - 0
src/compiler/compiler.cpp

@@ -2,6 +2,8 @@
 #include "pocketpy/common/version.hpp"
 #include "pocketpy/interpreter/vm.hpp"
 
+#include <stdexcept>
+
 namespace pkpy{
     PrattRule Compiler::rules[kTokenCount];
 

+ 2 - 2
src/compiler/expr.cpp

@@ -43,7 +43,7 @@ namespace pkpy{
 
     // clear the expression stack and generate bytecode
     void CodeEmitContext::emit_expr(){
-        if(s_expr.size() != 1) throw std::runtime_error("s_expr.size() != 1");
+        assert(s_expr.size() == 1);
         Expr_ expr = s_expr.popx();
         expr->emit_(this);
     }
@@ -396,7 +396,7 @@ namespace pkpy{
         int for_codei = ctx->emit_(OP_FOR_ITER, curr_iblock, BC_KEEPLINE);
         bool ok = vars->emit_store(ctx);
         // this error occurs in `vars` instead of this line, but...nevermind
-        if(!ok) throw std::runtime_error("SyntaxError");
+        assert(ok);     // this should raise a SyntaxError, but we just assert it
         ctx->try_merge_for_iter_store(for_codei);
         if(cond){
             cond->emit_(ctx);

+ 1 - 1
src/compiler/lexer.cpp

@@ -79,7 +79,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
 
     char Lexer::eatchar() {
         char c = peekchar();
-        if(c == '\n') throw std::runtime_error("eatchar() cannot consume a newline");
+        assert(c != '\n');  // eatchar() cannot consume a newline
         curr_char++;
         return c;
     }

+ 2 - 0
src/interpreter/frame.cpp

@@ -1,6 +1,8 @@
 #include "pocketpy/objects/stackmemory.hpp"
 #include "pocketpy/interpreter/frame.hpp"
 
+#include <stdexcept>
+
 namespace pkpy{
     PyVar* FastLocals::try_get_name(StrName name){
         int index = co->varnames_inv.try_get(name);

+ 1 - 0
src/interpreter/vm.cpp

@@ -2,6 +2,7 @@
 
 #include <iostream>
 #include <cmath>
+#include <stdexcept>
 
 static const char* OP_NAMES[] = {
     #define OPCODE(name) #name,

+ 1 - 3
src/pocketpy_c.cpp

@@ -38,9 +38,7 @@ static PyVar stack_item(VM* vm, int index){
     }
     int size = end - begin;
     if(index < 0) index += size;
-    if(index < 0 || index >= size){
-        throw std::runtime_error("stack_item() => index out of range");
-    }
+    assert(index >= 0 && index < size);
     return begin[index];
 }