mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 13:00:17 +00:00
...
This commit is contained in:
parent
b3b6f8c87c
commit
3738d07941
2
build.py
2
build.py
@ -9,7 +9,7 @@ os.system("python3 preprocess.py")
|
|||||||
def DONE(code=0):
|
def DONE(code=0):
|
||||||
exit(code)
|
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_cmd = "clang++ -o pocketpy src/main.cpp " + linux_common
|
||||||
linux_lib_cmd = "clang++ -fPIC -shared -o pocketpy.so src/tmp.cpp " + linux_common
|
linux_lib_cmd = "clang++ -fPIC -shared -o pocketpy.so src/tmp.cpp " + linux_common
|
||||||
|
|
||||||
|
@ -189,8 +189,8 @@ struct CodeObject {
|
|||||||
}
|
}
|
||||||
ss.write_end_mark(); // ]
|
ss.write_end_mark(); // ]
|
||||||
ss.write_begin_mark(); // [
|
ss.write_begin_mark(); // [
|
||||||
for(StrName name: varnames){
|
for(StrName vn: varnames){
|
||||||
ss.write_name(name); // name
|
ss.write_name(vn); // name
|
||||||
}
|
}
|
||||||
ss.write_end_mark(); // ]
|
ss.write_end_mark(); // ]
|
||||||
ss.write_begin_mark(); // [
|
ss.write_begin_mark(); // [
|
||||||
|
@ -48,6 +48,8 @@ struct GIL {
|
|||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
|
||||||
|
#define PK_UNUSED(x) (void)(x)
|
||||||
|
|
||||||
namespace pkpy{
|
namespace pkpy{
|
||||||
|
|
||||||
namespace std = ::std;
|
namespace std = ::std;
|
||||||
|
@ -84,7 +84,7 @@ class Exception {
|
|||||||
StackTrace stacktrace;
|
StackTrace stacktrace;
|
||||||
public:
|
public:
|
||||||
Exception(StrName type, Str msg): type(type), msg(msg) {}
|
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;
|
bool is_re = true;
|
||||||
|
|
||||||
void st_push(Str snapshot){
|
void st_push(Str snapshot){
|
||||||
|
@ -381,7 +381,7 @@ struct Lexer {
|
|||||||
} else {
|
} else {
|
||||||
add_token(TK("@num"), Number::stoi(m[0], &size, base));
|
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& _){
|
}catch(std::exception& _){
|
||||||
SyntaxError("invalid number literal");
|
SyntaxError("invalid number literal");
|
||||||
}
|
}
|
||||||
|
@ -406,6 +406,7 @@ struct Py_<Super> final: PyObject {
|
|||||||
template<>
|
template<>
|
||||||
struct Py_<DummyInstance> final: PyObject {
|
struct Py_<DummyInstance> final: PyObject {
|
||||||
Py_(Type type, DummyInstance val): PyObject(type) {
|
Py_(Type type, DummyInstance val): PyObject(type) {
|
||||||
|
PK_UNUSED(val);
|
||||||
enable_instance_dict();
|
enable_instance_dict();
|
||||||
}
|
}
|
||||||
void _obj_gc_mark() override {}
|
void _obj_gc_mark() override {}
|
||||||
@ -423,6 +424,7 @@ struct Py_<Type> final: PyObject {
|
|||||||
template<>
|
template<>
|
||||||
struct Py_<DummyModule> final: PyObject {
|
struct Py_<DummyModule> final: PyObject {
|
||||||
Py_(Type type, DummyModule val): PyObject(type) {
|
Py_(Type type, DummyModule val): PyObject(type) {
|
||||||
|
PK_UNUSED(val);
|
||||||
enable_instance_dict(kTypeAttrLoadFactor);
|
enable_instance_dict(kTypeAttrLoadFactor);
|
||||||
}
|
}
|
||||||
void _obj_gc_mark() override {}
|
void _obj_gc_mark() override {}
|
||||||
|
20
src/vm.h
20
src/vm.h
@ -31,6 +31,7 @@ namespace pkpy{
|
|||||||
return PK_OBJ_GET(ctype, obj); \
|
return PK_OBJ_GET(ctype, obj); \
|
||||||
} \
|
} \
|
||||||
template<> inline ctype _py_cast<ctype>(VM* vm, PyObject* obj) { \
|
template<> inline ctype _py_cast<ctype>(VM* vm, PyObject* obj) { \
|
||||||
|
PK_UNUSED(vm); \
|
||||||
return PK_OBJ_GET(ctype, obj); \
|
return PK_OBJ_GET(ctype, obj); \
|
||||||
} \
|
} \
|
||||||
template<> inline ctype& py_cast<ctype&>(VM* vm, PyObject* obj) { \
|
template<> inline ctype& py_cast<ctype&>(VM* vm, PyObject* obj) { \
|
||||||
@ -38,6 +39,7 @@ namespace pkpy{
|
|||||||
return PK_OBJ_GET(ctype, obj); \
|
return PK_OBJ_GET(ctype, obj); \
|
||||||
} \
|
} \
|
||||||
template<> inline ctype& _py_cast<ctype&>(VM* vm, PyObject* obj) { \
|
template<> inline ctype& _py_cast<ctype&>(VM* vm, PyObject* obj) { \
|
||||||
|
PK_UNUSED(vm); \
|
||||||
return PK_OBJ_GET(ctype, obj); \
|
return PK_OBJ_GET(ctype, obj); \
|
||||||
} \
|
} \
|
||||||
inline PyObject* py_var(VM* vm, const ctype& value) { return vm->heap.gcnew(vm->ptype, value);} \
|
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) {
|
VM(bool enable_os=true) : heap(this), enable_os(enable_os) {
|
||||||
this->vm = this;
|
this->vm = this;
|
||||||
_stdout = [](VM* vm, const Str& s) { std::cout << s; };
|
_stdout = [](VM* vm, const Str& s) {
|
||||||
_stderr = [](VM* vm, const Str& s) { std::cerr << s; };
|
PK_UNUSED(vm);
|
||||||
|
std::cout << s;
|
||||||
|
};
|
||||||
|
_stderr = [](VM* vm, const Str& s) {
|
||||||
|
PK_UNUSED(vm);
|
||||||
|
std::cerr << s;
|
||||||
|
};
|
||||||
callstack.reserve(8);
|
callstack.reserve(8);
|
||||||
_main = nullptr;
|
_main = nullptr;
|
||||||
_last_exception = nullptr;
|
_last_exception = nullptr;
|
||||||
_import_handler = [](const Str& name) { return Bytes(); };
|
_import_handler = [](const Str& name) {
|
||||||
|
PK_UNUSED(name);
|
||||||
|
return Bytes();
|
||||||
|
};
|
||||||
init_builtin_types();
|
init_builtin_types();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,6 +717,7 @@ template<> inline T py_cast<T>(VM* vm, PyObject* obj){ \
|
|||||||
return (T)(PK_BITS(obj) >> 2); \
|
return (T)(PK_BITS(obj) >> 2); \
|
||||||
} \
|
} \
|
||||||
template<> inline T _py_cast<T>(VM* vm, PyObject* obj){ \
|
template<> inline T _py_cast<T>(VM* vm, PyObject* obj){ \
|
||||||
|
PK_UNUSED(vm); \
|
||||||
return (T)(PK_BITS(obj) >> 2); \
|
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){
|
inline PyObject* py_var(VM* vm, NoReturn val){
|
||||||
|
PK_UNUSED(val);
|
||||||
return vm->None;
|
return vm->None;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PyObject* py_var(VM* vm, PyObject* val){
|
inline PyObject* py_var(VM* vm, PyObject* val){
|
||||||
|
PK_UNUSED(vm);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user