rename FATAL_ERROR to PK_FATAL_ERROR

This commit is contained in:
blueloveTH 2024-01-04 12:37:28 +08:00
parent ab458b4af4
commit 315cbe5d1a
11 changed files with 29 additions and 29 deletions

View File

@ -187,12 +187,12 @@ struct Type {
#define PK_ACTION(x) ([](VM* vm, ArgsView args) { x; return vm->None; })
#ifdef POCKETPY_H
#define FATAL_ERROR() throw std::runtime_error( "L" + std::to_string(__LINE__) + " FATAL_ERROR()!");
#define PK_FATAL_ERROR() throw std::runtime_error( "L" + std::to_string(__LINE__) + " FATAL_ERROR()!");
#else
#define FATAL_ERROR() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " FATAL_ERROR()!");
#define PK_FATAL_ERROR() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " FATAL_ERROR()!");
#endif
#define PK_ASSERT(x) if(!(x)) FATAL_ERROR();
#define PK_ASSERT(x) if(!(x)) PK_FATAL_ERROR();
struct PyObject;
#define PK_BITS(p) (reinterpret_cast<Number::int_t>(p))

View File

@ -59,7 +59,7 @@ struct ValueStackImpl {
PyObject** end() { return _sp; }
void reset(PyObject** sp) {
#if PK_DEBUG_EXTRA_CHECK
if(sp < _begin || sp > _begin + MAX_SIZE) FATAL_ERROR();
if(sp < _begin || sp > _begin + MAX_SIZE) PK_FATAL_ERROR();
#endif
_sp = sp;
}
@ -105,7 +105,7 @@ struct Frame {
Bytecode next_bytecode() {
_ip = _next_ip++;
#if PK_DEBUG_EXTRA_CHECK
if(_ip >= co->codes.size()) FATAL_ERROR();
if(_ip >= co->codes.size()) PK_FATAL_ERROR();
#endif
return co->codes[_ip];
}

View File

@ -159,7 +159,7 @@ while(!_items[i].first.empty()) { \
if(old_items[i].first.empty()) continue;
bool ok; uint16_t j;
HASH_PROBE_1(old_items[i].first, ok, j);
if(ok) FATAL_ERROR();
if(ok) PK_FATAL_ERROR();
_items[j] = old_items[i];
}
free(old_items);

View File

@ -23,7 +23,7 @@ struct Str{
Str(int size, bool is_ascii);
Str(const std::string& s);
Str(std::string_view s);
Str(std::nullptr_t) { FATAL_ERROR(); }
Str(std::nullptr_t) { PK_FATAL_ERROR(); }
Str(const char* s);
Str(const char* s, int len);
Str(std::pair<char *, int>);

View File

@ -55,7 +55,7 @@ PyObject* VM::_run_top_frame(){
while(true){
#if PK_DEBUG_EXTRA_CHECK
if(frame.index < base_id) FATAL_ERROR();
if(frame.index < base_id) PK_FATAL_ERROR();
#endif
try{
if(need_raise){ need_raise = false; _raise(); }
@ -845,7 +845,7 @@ __NEXT_STEP:;
#if !PK_ENABLE_COMPUTED_GOTO
static_assert(OP_DEC_GLOBAL == 111);
case 112: case 113: case 114: case 115: case 116: case 117: case 118: case 119: case 120: case 121: case 122: case 123: case 124: case 125: case 126: case 127: case 128: case 129: case 130: case 131: case 132: case 133: case 134: case 135: case 136: case 137: case 138: case 139: case 140: case 141: case 142: case 143: case 144: case 145: case 146: case 147: case 148: case 149: case 150: case 151: case 152: case 153: case 154: case 155: case 156: case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 169: case 170: case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: case 237: case 238: case 239: case 240: case 241: case 242: case 243: case 244: case 245: case 246: case 247: case 248: case 249: case 250: case 251: case 252: case 253: case 254: case 255: FATAL_ERROR(); break;
case 112: case 113: case 114: case 115: case 116: case 117: case 118: case 119: case 120: case 121: case 122: case 123: case 124: case 125: case 126: case 127: case 128: case 129: case 130: case 131: case 132: case 133: case 134: case 135: case 136: case 137: case 138: case 139: case 140: case 141: case 142: case 143: case 144: case 145: case 146: case 147: case 148: case 149: case 150: case 151: case 152: case 153: case 154: case 155: case 156: case 157: case 158: case 159: case 160: case 161: case 162: case 163: case 164: case 165: case 166: case 167: case 168: case 169: case 170: case 171: case 172: case 173: case 174: case 175: case 176: case 177: case 178: case 179: case 180: case 181: case 182: case 183: case 184: case 185: case 186: case 187: case 188: case 189: case 190: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 201: case 202: case 203: case 204: case 205: case 206: case 207: case 208: case 209: case 210: case 211: case 212: case 213: case 214: case 215: case 216: case 217: case 218: case 219: case 220: case 221: case 222: case 223: case 224: case 225: case 226: case 227: case 228: case 229: case 230: case 231: case 232: case 233: case 234: case 235: case 236: case 237: case 238: case 239: case 240: case 241: case 242: case 243: case 244: case 245: case 246: case 247: case 248: case 249: case 250: case 251: case 252: case 253: case 254: case 255: PK_FATAL_ERROR(); break;
}
#endif
}

View File

@ -299,7 +299,7 @@ namespace pkpy{
case TK("**"):
ctx()->s_expr.push(make_expr<StarredExpr>(2, ctx()->s_expr.popx()));
break;
default: FATAL_ERROR();
default: PK_FATAL_ERROR();
}
}
@ -489,7 +489,7 @@ __SUBSCR_END:
if(is_slice){
e->b = std::move(slice);
}else{
if(state != 1) FATAL_ERROR();
PK_ASSERT(state == 1)
e->b = std::move(slice->start);
}
ctx()->s_expr.push(std::move(e));
@ -1128,7 +1128,7 @@ __EAT_DOTS_END:
if(std::holds_alternative<Str>(value)){
obj = VAR(std::get<Str>(value));
}
if(obj == nullptr) FATAL_ERROR();
PK_ASSERT(obj != nullptr)
return obj;
}
@ -1163,7 +1163,7 @@ __EAT_DOTS_END:
CodeObject_ Compiler::compile(){
if(used) FATAL_ERROR();
PK_ASSERT(!used)
used = true;
tokens = lexer->run();

View File

@ -26,7 +26,7 @@ namespace pkpy{
if(curr_type == FOR_LOOP) for_loop_depth--;
co->blocks[curr_block_i].end = co->codes.size();
curr_block_i = co->blocks[curr_block_i].parent;
if(curr_block_i < 0) FATAL_ERROR();
if(curr_block_i < 0) PK_FATAL_ERROR();
if(curr_type == FOR_LOOP){
// add a no op here to make block check work
@ -116,7 +116,7 @@ namespace pkpy{
case NAME_GLOBAL_UNKNOWN:
emit_(OP_STORE_NAME, StrName(name).index, line);
break;
default: FATAL_ERROR(); break;
default: PK_FATAL_ERROR(); break;
}
}
@ -151,7 +151,7 @@ namespace pkpy{
case NAME_GLOBAL_UNKNOWN:
ctx->emit_(OP_DELETE_NAME, StrName(name).index, line);
break;
default: FATAL_ERROR(); break;
default: PK_FATAL_ERROR(); break;
}
return true;
}
@ -206,7 +206,7 @@ namespace pkpy{
case TK("True"): ctx->emit_(OP_LOAD_TRUE, BC_NOARG, line); break;
case TK("False"): ctx->emit_(OP_LOAD_FALSE, BC_NOARG, line); break;
case TK("..."): ctx->emit_(OP_LOAD_ELLIPSIS, BC_NOARG, line); break;
default: FATAL_ERROR();
default: PK_FATAL_ERROR();
}
}
@ -245,7 +245,7 @@ namespace pkpy{
if(std::holds_alternative<Str>(value)){
obj = VAR(std::get<Str>(value));
}
if(obj == nullptr) FATAL_ERROR();
PK_ASSERT(obj != nullptr)
ctx->emit_(OP_LOAD_CONST, ctx->add_const(obj), line);
}
@ -557,7 +557,7 @@ namespace pkpy{
if(!kwargs.empty()){
for(auto& item: kwargs){
if(item.second->is_starred()){
if(item.second->star_level() != 2) FATAL_ERROR();
PK_ASSERT(item.second->star_level() == 2)
item.second->emit_(ctx);
}else{
// k=v
@ -658,7 +658,7 @@ namespace pkpy{
case TK("^"): ctx->emit_(OP_BITWISE_XOR, BC_NOARG, line); break;
case TK("@"): ctx->emit_(OP_BINARY_MATMUL, BC_NOARG, line); break;
default: FATAL_ERROR();
default: PK_FATAL_ERROR();
}
for(int i: jmps) ctx->patch_jump(i);

View File

@ -41,7 +41,7 @@ namespace pkpy{
}
int ManagedHeap::collect(){
if(_gc_lock_counter > 0) FATAL_ERROR();
PK_ASSERT(_gc_lock_counter == 0)
mark();
int freed = sweep();
return freed;

View File

@ -438,7 +438,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
case 2: SyntaxError("invalid utf8 sequence: " + std::string(1, c)); break;
case 3: SyntaxError("@id contains invalid char"); break;
case 4: SyntaxError("invalid JSON token"); break;
default: FATAL_ERROR();
default: PK_FATAL_ERROR();
}
return true;
}
@ -473,7 +473,7 @@ static bool is_unicode_Lo_char(uint32_t c) {
}
std::vector<Token> Lexer::run() {
if(used) FATAL_ERROR();
PK_ASSERT(!used)
used = true;
while (lex_one_token());
return std::move(nexts);

View File

@ -276,7 +276,7 @@ void init_builtins(VM* _vm) {
});
_vm->bind__repr__(_vm->tp_object, [](VM* vm, PyObject* obj) {
if(is_tagged(obj)) FATAL_ERROR();
if(is_tagged(obj)) PK_FATAL_ERROR();
std::stringstream ss; // hex
ss << "<" << OBJ_NAME(vm->_t(obj)) << " object at 0x";
ss << std::hex << reinterpret_cast<intptr_t>(obj) << ">";

View File

@ -121,7 +121,7 @@ namespace pkpy{
FrameId VM::top_frame(){
#if PK_DEBUG_EXTRA_CHECK
if(callstack.empty()) FATAL_ERROR();
if(callstack.empty()) PK_FATAL_ERROR();
#endif
return FrameId(&callstack.data(), callstack.size()-1);
}
@ -240,7 +240,7 @@ namespace pkpy{
PyObject* obj = builtins->attr().try_get_likely_found(type);
if(obj == nullptr){
for(auto& t: _all_types) if(t.name == type) return &t;
FATAL_ERROR();
PK_FATAL_ERROR();
}
return &_all_types[PK_OBJ_GET(Type, obj)];
}
@ -669,7 +669,7 @@ void VM::_log_s_data(const char* title) {
if(title) ss << title << " | ";
std::map<PyObject**, int> sp_bases;
for(Frame& f: callstack.data()){
if(f._sp_base == nullptr) FATAL_ERROR();
if(f._sp_base == nullptr) PK_FATAL_ERROR();
sp_bases[f._sp_base] += 1;
}
FrameId frame = top_frame();
@ -877,7 +877,7 @@ PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
// handle boundmethod, do a patch
if(is_non_tagged_type(callable, tp_bound_method)){
if(method_call) FATAL_ERROR();
if(method_call) PK_FATAL_ERROR();
auto& bm = CAST(BoundMethod&, callable);
callable = bm.func; // get unbound method
p1[-(ARGC + 2)] = bm.func;
@ -962,7 +962,7 @@ __FAST_CALL:
}
if(is_non_tagged_type(callable, tp_type)){
if(method_call) FATAL_ERROR();
if(method_call) PK_FATAL_ERROR();
// [type, NULL, args..., kwargs...]
PyObject* new_f = find_name_in_mro(callable, __new__);
PyObject* obj;