mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
rename UNREACHABLE()
to PK_UNREACHABLE()
This commit is contained in:
parent
315cbe5d1a
commit
e150ffae5e
@ -50,7 +50,7 @@ static cJSON* convert_python_object_to_cjson(PyObject* obj, VM* vm){
|
|||||||
}else{
|
}else{
|
||||||
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape()));
|
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape()));
|
||||||
}
|
}
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ void add_module_cjson(VM* vm){
|
|||||||
const char* end = start;
|
const char* end = start;
|
||||||
while(*end != '\0' && *end != '\n') end++;
|
while(*end != '\0' && *end != '\n') end++;
|
||||||
vm->IOError(fmt("cjson: ", std::string_view(start, end-start)));
|
vm->IOError(fmt("cjson: ", std::string_view(start, end-start)));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
PyObject* output = convert_cjson_to_python_object(json, vm);
|
PyObject* output = convert_cjson_to_python_object(json, vm);
|
||||||
cJSON_Delete(json);
|
cJSON_Delete(json);
|
||||||
|
@ -66,10 +66,10 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define PK_ENABLE_COMPUTED_GOTO 0
|
#define PK_ENABLE_COMPUTED_GOTO 0
|
||||||
#define UNREACHABLE() __assume(0)
|
#define PK_UNREACHABLE() __assume(0)
|
||||||
#else
|
#else
|
||||||
#define PK_ENABLE_COMPUTED_GOTO 1
|
#define PK_ENABLE_COMPUTED_GOTO 1
|
||||||
#define UNREACHABLE() __builtin_unreachable()
|
#define PK_UNREACHABLE() __builtin_unreachable()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define PK_ENABLE_COMPUTED_GOTO 0
|
#define PK_ENABLE_COMPUTED_GOTO 0
|
||||||
#define UNREACHABLE() __assume(0)
|
#define PK_UNREACHABLE() __assume(0)
|
||||||
#else
|
#else
|
||||||
#define PK_ENABLE_COMPUTED_GOTO 1
|
#define PK_ENABLE_COMPUTED_GOTO 1
|
||||||
#define UNREACHABLE() __builtin_unreachable()
|
#define PK_UNREACHABLE() __builtin_unreachable()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ struct SmallNameDict{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
V try_get(K key) const {
|
V try_get(K key) const {
|
||||||
|
@ -223,7 +223,6 @@ public:
|
|||||||
PyObject* _find_type_object(const Str& type);
|
PyObject* _find_type_object(const Str& type);
|
||||||
|
|
||||||
Type _type(const Str& type);
|
Type _type(const Str& type);
|
||||||
PyTypeInfo* _type_info(const Str& type);
|
|
||||||
PyTypeInfo* _type_info(Type type);
|
PyTypeInfo* _type_info(Type type);
|
||||||
const PyTypeInfo* _inst_type_info(PyObject* obj);
|
const PyTypeInfo* _inst_type_info(PyObject* obj);
|
||||||
|
|
||||||
|
@ -799,7 +799,7 @@ __NEXT_STEP:;
|
|||||||
}
|
}
|
||||||
if(!isinstance(TOP(), tp_exception)){
|
if(!isinstance(TOP(), tp_exception)){
|
||||||
_builtin_error("TypeError", "exceptions must derive from Exception");
|
_builtin_error("TypeError", "exceptions must derive from Exception");
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
_error(POPX());
|
_error(POPX());
|
||||||
} DISPATCH();
|
} DISPATCH();
|
||||||
@ -855,7 +855,7 @@ __NEXT_STEP:;
|
|||||||
#undef DISPATCH_OP_CALL
|
#undef DISPATCH_OP_CALL
|
||||||
#undef CEVAL_STEP
|
#undef CEVAL_STEP
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}catch(HandledException){
|
}catch(HandledException){
|
||||||
continue;
|
continue;
|
||||||
}catch(UnhandledException){
|
}catch(UnhandledException){
|
||||||
|
@ -611,7 +611,7 @@ namespace pkpy{
|
|||||||
case TK("!="): ctx->emit_(OP_COMPARE_NE, BC_NOARG, line); break;
|
case TK("!="): ctx->emit_(OP_COMPARE_NE, BC_NOARG, line); break;
|
||||||
case TK(">"): ctx->emit_(OP_COMPARE_GT, BC_NOARG, line); break;
|
case TK(">"): ctx->emit_(OP_COMPARE_GT, BC_NOARG, line); break;
|
||||||
case TK(">="): ctx->emit_(OP_COMPARE_GE, BC_NOARG, line); break;
|
case TK(">="): ctx->emit_(OP_COMPARE_GE, BC_NOARG, line); break;
|
||||||
default: UNREACHABLE();
|
default: PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
// [b, RES]
|
// [b, RES]
|
||||||
int index = ctx->emit_(OP_SHORTCUT_IF_FALSE_OR_POP, BC_NOARG, line);
|
int index = ctx->emit_(OP_SHORTCUT_IF_FALSE_OR_POP, BC_NOARG, line);
|
||||||
|
24
src/vm.cpp
24
src/vm.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "pocketpy/vm.h"
|
#include "pocketpy/vm.h"
|
||||||
|
#include "pocketpy/config.h"
|
||||||
|
|
||||||
namespace pkpy{
|
namespace pkpy{
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ namespace pkpy{
|
|||||||
first = false;
|
first = false;
|
||||||
if(!is_non_tagged_type(k, vm->tp_str)){
|
if(!is_non_tagged_type(k, vm->tp_str)){
|
||||||
vm->TypeError(fmt("json keys must be string, got ", obj_type_name(vm, vm->_tp(k))));
|
vm->TypeError(fmt("json keys must be string, got ", obj_type_name(vm, vm->_tp(k))));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
ss << _CAST(Str&, k).escape(false) << ": ";
|
ss << _CAST(Str&, k).escape(false) << ": ";
|
||||||
write_object(v);
|
write_object(v);
|
||||||
@ -57,7 +58,7 @@ namespace pkpy{
|
|||||||
write_dict(_CAST(Dict&, obj));
|
write_dict(_CAST(Dict&, obj));
|
||||||
}else{
|
}else{
|
||||||
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape()));
|
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape()));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,15 +237,6 @@ namespace pkpy{
|
|||||||
return PK_OBJ_GET(Type, obj);
|
return PK_OBJ_GET(Type, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyTypeInfo* VM::_type_info(const Str& type){
|
|
||||||
PyObject* obj = builtins->attr().try_get_likely_found(type);
|
|
||||||
if(obj == nullptr){
|
|
||||||
for(auto& t: _all_types) if(t.name == type) return &t;
|
|
||||||
PK_FATAL_ERROR();
|
|
||||||
}
|
|
||||||
return &_all_types[PK_OBJ_GET(Type, obj)];
|
|
||||||
}
|
|
||||||
|
|
||||||
PyTypeInfo* VM::_type_info(Type type){
|
PyTypeInfo* VM::_type_info(Type type){
|
||||||
return &_all_types[type];
|
return &_all_types[type];
|
||||||
}
|
}
|
||||||
@ -476,7 +468,7 @@ i64 VM::py_hash(PyObject* obj){
|
|||||||
}
|
}
|
||||||
if(has_custom_eq){
|
if(has_custom_eq){
|
||||||
TypeError(fmt("unhashable type: ", ti->name.escape()));
|
TypeError(fmt("unhashable type: ", ti->name.escape()));
|
||||||
return 0;
|
PK_UNREACHABLE();
|
||||||
}else{
|
}else{
|
||||||
return PK_BITS(obj);
|
return PK_BITS(obj);
|
||||||
}
|
}
|
||||||
@ -532,7 +524,7 @@ PyObject* VM::_format_string(Str spec, PyObject* obj){
|
|||||||
}
|
}
|
||||||
}catch(...){
|
}catch(...){
|
||||||
ValueError("invalid format specifer");
|
ValueError("invalid format specifer");
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type != 'f' && dot >= 0) ValueError("precision not allowed in the format specifier");
|
if(type != 'f' && dot >= 0) ValueError("precision not allowed in the format specifier");
|
||||||
@ -816,7 +808,7 @@ void VM::_prepare_py_call(PyObject** buffer, ArgsView args, ArgsView kwargs, con
|
|||||||
vm->TypeError(fmt(
|
vm->TypeError(fmt(
|
||||||
co->name, "() takes ", decl_argc, " positional arguments but ", args.size(), " were given"
|
co->name, "() takes ", decl_argc, " positional arguments but ", args.size(), " were given"
|
||||||
));
|
));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -925,11 +917,11 @@ PyObject* VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|||||||
TypeError(fmt(
|
TypeError(fmt(
|
||||||
co->name, "() takes ", decl->args.size(), " positional arguments but ", args.size(), " were given"
|
co->name, "() takes ", decl->args.size(), " positional arguments but ", args.size(), " were given"
|
||||||
));
|
));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
if(!kwargs.empty()){
|
if(!kwargs.empty()){
|
||||||
TypeError(fmt(co->name, "() takes no keyword arguments"));
|
TypeError(fmt(co->name, "() takes no keyword arguments"));
|
||||||
UNREACHABLE();
|
PK_UNREACHABLE();
|
||||||
}
|
}
|
||||||
s_data.reset(_base + co_nlocals);
|
s_data.reset(_base + co_nlocals);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
assert 'testing' == 'test' + 'ing'
|
assert 'testing' == 'test' + 'ing'
|
||||||
assert 'testing' != 'test' + 'ing2'
|
assert 'testing' != 'test' + 'ing2'
|
||||||
assert 'testing' < 'test' + 'ing2'
|
assert 'testing' < 'test' + 'ing2'
|
||||||
|
assert 'testing' <= 'test' + 'ing2'
|
||||||
assert 'testing5' > 'test' + 'ing1'
|
assert 'testing5' > 'test' + 'ing1'
|
||||||
|
assert 'testing5' >= 'test' + 'ing1'
|
||||||
|
|
||||||
# test + *=
|
# test + *=
|
||||||
assert 'abc' + 'def' == 'abcdef'
|
assert 'abc' + 'def' == 'abcdef'
|
||||||
assert 'abc' * 3 == 'abcabcabc'
|
assert 'abc' * 3 == 'abcabcabc'
|
||||||
|
|
||||||
|
assert repr('\\\n\t\'\r\b\x48') == r"'\\\n\t\'\r\bH'"
|
||||||
|
|
||||||
a = ''
|
a = ''
|
||||||
b = 'test'
|
b = 'test'
|
||||||
c ='test'
|
c ='test'
|
||||||
|
@ -70,4 +70,16 @@ assert repr([1, 2, 3]) == '[1, 2, 3]'
|
|||||||
assert repr([1]) == '[1]'
|
assert repr([1]) == '[1]'
|
||||||
assert json.dumps([]) == '[]'
|
assert json.dumps([]) == '[]'
|
||||||
assert json.dumps([1, 2, 3]) == '[1, 2, 3]'
|
assert json.dumps([1, 2, 3]) == '[1, 2, 3]'
|
||||||
assert json.dumps([1]) == '[1]'
|
assert json.dumps([1]) == '[1]'
|
||||||
|
|
||||||
|
try:
|
||||||
|
json.dumps({1: 2})
|
||||||
|
assert False
|
||||||
|
except TypeError:
|
||||||
|
assert True
|
||||||
|
|
||||||
|
try:
|
||||||
|
json.dumps(type)
|
||||||
|
assert False
|
||||||
|
except TypeError:
|
||||||
|
assert True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user