This commit is contained in:
blueloveTH 2024-06-02 17:20:37 +08:00
parent 10842207ea
commit fe8d102748
12 changed files with 18 additions and 10 deletions

View File

@ -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");

View File

@ -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")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

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

View File

@ -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];
}