This commit is contained in:
blueloveTH 2023-06-26 19:42:18 +08:00
parent b3b6f8c87c
commit 3738d07941
7 changed files with 26 additions and 8 deletions

View File

@ -9,7 +9,7 @@ os.system("python3 preprocess.py")
def DONE(code=0):
exit(code)
linux_common = "-Wfatal-errors --std=c++17 -O2 -Wall -Wno-sign-compare -Wno-unused-variable -fno-rtti -stdlib=libc++"
linux_common = "-Wfatal-errors --std=c++17 -O2 -Wall -fno-rtti -stdlib=libc++"
linux_cmd = "clang++ -o pocketpy src/main.cpp " + linux_common
linux_lib_cmd = "clang++ -fPIC -shared -o pocketpy.so src/tmp.cpp " + linux_common

View File

@ -189,8 +189,8 @@ struct CodeObject {
}
ss.write_end_mark(); // ]
ss.write_begin_mark(); // [
for(StrName name: varnames){
ss.write_name(name); // name
for(StrName vn: varnames){
ss.write_name(vn); // name
}
ss.write_end_mark(); // ]
ss.write_begin_mark(); // [

View File

@ -48,6 +48,8 @@ struct GIL {
/*******************************************************************************/
#define PK_UNUSED(x) (void)(x)
namespace pkpy{
namespace std = ::std;

View File

@ -84,7 +84,7 @@ class Exception {
StackTrace stacktrace;
public:
Exception(StrName type, Str msg): type(type), msg(msg) {}
bool match_type(StrName type) const { return this->type == type;}
bool match_type(StrName t) const { return this->type == t;}
bool is_re = true;
void st_push(Str snapshot){

View File

@ -381,7 +381,7 @@ struct Lexer {
} else {
add_token(TK("@num"), Number::stoi(m[0], &size, base));
}
PK_ASSERT(size == m.length());
PK_ASSERT((int)size == (int)m.length());
}catch(std::exception& _){
SyntaxError("invalid number literal");
}

View File

@ -406,6 +406,7 @@ struct Py_<Super> final: PyObject {
template<>
struct Py_<DummyInstance> final: PyObject {
Py_(Type type, DummyInstance val): PyObject(type) {
PK_UNUSED(val);
enable_instance_dict();
}
void _obj_gc_mark() override {}
@ -423,6 +424,7 @@ struct Py_<Type> final: PyObject {
template<>
struct Py_<DummyModule> final: PyObject {
Py_(Type type, DummyModule val): PyObject(type) {
PK_UNUSED(val);
enable_instance_dict(kTypeAttrLoadFactor);
}
void _obj_gc_mark() override {}

View File

@ -31,6 +31,7 @@ namespace pkpy{
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype _py_cast<ctype>(VM* vm, PyObject* obj) { \
PK_UNUSED(vm); \
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype& py_cast<ctype&>(VM* vm, PyObject* obj) { \
@ -38,6 +39,7 @@ namespace pkpy{
return PK_OBJ_GET(ctype, obj); \
} \
template<> inline ctype& _py_cast<ctype&>(VM* vm, PyObject* obj) { \
PK_UNUSED(vm); \
return PK_OBJ_GET(ctype, obj); \
} \
inline PyObject* py_var(VM* vm, const ctype& value) { return vm->heap.gcnew(vm->ptype, value);} \
@ -147,12 +149,21 @@ public:
VM(bool enable_os=true) : heap(this), enable_os(enable_os) {
this->vm = this;
_stdout = [](VM* vm, const Str& s) { std::cout << s; };
_stderr = [](VM* vm, const Str& s) { std::cerr << s; };
_stdout = [](VM* vm, const Str& s) {
PK_UNUSED(vm);
std::cout << s;
};
_stderr = [](VM* vm, const Str& s) {
PK_UNUSED(vm);
std::cerr << s;
};
callstack.reserve(8);
_main = nullptr;
_last_exception = nullptr;
_import_handler = [](const Str& name) { return Bytes(); };
_import_handler = [](const Str& name) {
PK_UNUSED(name);
return Bytes();
};
init_builtin_types();
}
@ -706,6 +717,7 @@ template<> inline T py_cast<T>(VM* vm, PyObject* obj){ \
return (T)(PK_BITS(obj) >> 2); \
} \
template<> inline T _py_cast<T>(VM* vm, PyObject* obj){ \
PK_UNUSED(vm); \
return (T)(PK_BITS(obj) >> 2); \
}
@ -810,10 +822,12 @@ inline PyObject* py_var(VM* vm, std::string_view val){
}
inline PyObject* py_var(VM* vm, NoReturn val){
PK_UNUSED(val);
return vm->None;
}
inline PyObject* py_var(VM* vm, PyObject* val){
PK_UNUSED(vm);
return val;
}