|
@@ -1,4 +1,7 @@
|
|
|
-#include "pocketpy/vm.h"
|
|
|
|
|
|
|
+#include "pocketpy/interpreter/vm.hpp"
|
|
|
|
|
+
|
|
|
|
|
+#include <iostream>
|
|
|
|
|
+#include <cmath>
|
|
|
|
|
|
|
|
static const char* OP_NAMES[] = {
|
|
static const char* OP_NAMES[] = {
|
|
|
#define OPCODE(name) #name,
|
|
#define OPCODE(name) #name,
|
|
@@ -358,7 +361,7 @@ namespace pkpy{
|
|
|
path = f_join(cpnts);
|
|
path = f_join(cpnts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- PK_ASSERT(path.begin()[0] != '.' && path.end()[-1] != '.');
|
|
|
|
|
|
|
+ assert(path.begin()[0] != '.' && path.end()[-1] != '.');
|
|
|
|
|
|
|
|
// check existing module
|
|
// check existing module
|
|
|
StrName name(path);
|
|
StrName name(path);
|
|
@@ -388,7 +391,7 @@ namespace pkpy{
|
|
|
if(throw_err) ImportError(_S("module ", path.escape(), " not found"));
|
|
if(throw_err) ImportError(_S("module ", path.escape(), " not found"));
|
|
|
else return nullptr;
|
|
else return nullptr;
|
|
|
}
|
|
}
|
|
|
- PK_ASSERT(out_size >= 0)
|
|
|
|
|
|
|
+ assert(out_size >= 0);
|
|
|
source = Str(std::string_view((char*)out, out_size));
|
|
source = Str(std::string_view((char*)out, out_size));
|
|
|
free(out);
|
|
free(out);
|
|
|
}else{
|
|
}else{
|
|
@@ -787,7 +790,7 @@ Str VM::disassemble(CodeObject_ co){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::string pointer;
|
|
std::string pointer;
|
|
|
- if(std::find(jumpTargets.begin(), jumpTargets.end(), i) != jumpTargets.end()){
|
|
|
|
|
|
|
+ if(jumpTargets.contains(i)){
|
|
|
pointer = "-> ";
|
|
pointer = "-> ";
|
|
|
}else{
|
|
}else{
|
|
|
pointer = " ";
|
|
pointer = " ";
|
|
@@ -817,7 +820,7 @@ void VM::__log_s_data(const char* title) {
|
|
|
if(title) ss << title << " | ";
|
|
if(title) ss << title << " | ";
|
|
|
std::map<PyVar*, int> sp_bases;
|
|
std::map<PyVar*, int> sp_bases;
|
|
|
callstack.apply([&](Frame& f){
|
|
callstack.apply([&](Frame& f){
|
|
|
- if(f._sp_base == nullptr) PK_FATAL_ERROR();
|
|
|
|
|
|
|
+ assert(f._sp_base != nullptr);
|
|
|
sp_bases[f._sp_base] += 1;
|
|
sp_bases[f._sp_base] += 1;
|
|
|
});
|
|
});
|
|
|
Frame* frame = &callstack.top();
|
|
Frame* frame = &callstack.top();
|
|
@@ -1046,7 +1049,7 @@ PyVar VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|
|
|
|
|
|
|
// handle boundmethod, do a patch
|
|
// handle boundmethod, do a patch
|
|
|
if(callable_t == tp_bound_method){
|
|
if(callable_t == tp_bound_method){
|
|
|
- PK_DEBUG_ASSERT(p0[1] == PY_NULL)
|
|
|
|
|
|
|
+ assert(p0[1] == PY_NULL);
|
|
|
BoundMethod& bm = PK_OBJ_GET(BoundMethod, callable);
|
|
BoundMethod& bm = PK_OBJ_GET(BoundMethod, callable);
|
|
|
callable = bm.func; // get unbound method
|
|
callable = bm.func; // get unbound method
|
|
|
callable_t = _tp(callable);
|
|
callable_t = _tp(callable);
|
|
@@ -1097,11 +1100,7 @@ PyVar VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|
|
callstack.popx(),
|
|
callstack.popx(),
|
|
|
ArgsView(__vectorcall_buffer, __vectorcall_buffer + co->nlocals)
|
|
ArgsView(__vectorcall_buffer, __vectorcall_buffer + co->nlocals)
|
|
|
);
|
|
);
|
|
|
-#if PK_DEBUG_EXTRA_CHECK
|
|
|
|
|
- default: PK_FATAL_ERROR(); break;
|
|
|
|
|
-#else
|
|
|
|
|
- default: PK_UNREACHABLE()
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ default: PK_UNREACHABLE();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// simple or normal
|
|
// simple or normal
|
|
@@ -1138,7 +1137,7 @@ PyVar VM::vectorcall(int ARGC, int KWARGC, bool op_call){
|
|
|
// [type, NULL, args..., kwargs...]
|
|
// [type, NULL, args..., kwargs...]
|
|
|
PyVar new_f = *find_name_in_mro(PK_OBJ_GET(Type, callable), __new__);
|
|
PyVar new_f = *find_name_in_mro(PK_OBJ_GET(Type, callable), __new__);
|
|
|
PyVar obj;
|
|
PyVar obj;
|
|
|
- PK_DEBUG_ASSERT(new_f != nullptr && p0[1]==PY_NULL);
|
|
|
|
|
|
|
+ assert(new_f != nullptr && p0[1]==PY_NULL);
|
|
|
if(new_f == __cached_object_new) {
|
|
if(new_f == __cached_object_new) {
|
|
|
// fast path for object.__new__
|
|
// fast path for object.__new__
|
|
|
obj = vm->new_object<DummyInstance>(PK_OBJ_GET(Type, callable));
|
|
obj = vm->new_object<DummyInstance>(PK_OBJ_GET(Type, callable));
|
|
@@ -1407,7 +1406,7 @@ PyObject* VM::bind(PyObject* obj, const char* sig, const char* docstring, Native
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
PyObject* VM::bind_property(PyObject* obj, const char* name, NativeFuncC fget, NativeFuncC fset){
|
|
PyObject* VM::bind_property(PyObject* obj, const char* name, NativeFuncC fget, NativeFuncC fset){
|
|
|
- PK_ASSERT(is_type(obj, tp_type));
|
|
|
|
|
|
|
+ assert(is_type(obj, tp_type));
|
|
|
std::string_view name_sv(name); int pos = name_sv.find(':');
|
|
std::string_view name_sv(name); int pos = name_sv.find(':');
|
|
|
if(pos > 0) name_sv = name_sv.substr(0, pos);
|
|
if(pos > 0) name_sv = name_sv.substr(0, pos);
|
|
|
PyVar _0 = new_object<NativeFunc>(tp_native_func, fget, 1);
|
|
PyVar _0 = new_object<NativeFunc>(tp_native_func, fget, 1);
|
|
@@ -1437,7 +1436,7 @@ void VM::AttributeError(PyVar obj, StrName name){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void VM::_error(PyVar e_obj){
|
|
void VM::_error(PyVar e_obj){
|
|
|
- PK_ASSERT(isinstance(e_obj, tp_exception))
|
|
|
|
|
|
|
+ assert(isinstance(e_obj, tp_exception));
|
|
|
Exception& e = PK_OBJ_GET(Exception, e_obj);
|
|
Exception& e = PK_OBJ_GET(Exception, e_obj);
|
|
|
if(callstack.empty()){
|
|
if(callstack.empty()){
|
|
|
e.is_re = false;
|
|
e.is_re = false;
|
|
@@ -1752,8 +1751,8 @@ void VM::__breakpoint(){
|
|
|
|
|
|
|
|
if(is_list){
|
|
if(is_list){
|
|
|
int max_line = frame_0->co->src->line_starts.size() + 1;
|
|
int max_line = frame_0->co->src->line_starts.size() + 1;
|
|
|
- start = std::max(1, lineno-5);
|
|
|
|
|
- end = std::min(max_line, lineno+5);
|
|
|
|
|
|
|
+ start = (std::max)(1, lineno-5);
|
|
|
|
|
+ end = (std::min)(max_line, lineno+5);
|
|
|
}else{
|
|
}else{
|
|
|
start = frame_0->co->start_line;
|
|
start = frame_0->co->start_line;
|
|
|
end = frame_0->co->end_line;
|
|
end = frame_0->co->end_line;
|