|
|
@@ -26,8 +26,8 @@ namespace pkpy{
|
|
|
#define POPX() (s_data.popx())
|
|
|
#define STACK_VIEW(n) (s_data.view(n))
|
|
|
|
|
|
-typedef PyObject* (*BinaryFuncC)(VM*, PyObject*, PyObject*);
|
|
|
-typedef void (*RegisterFunc)(VM*, PyObject*, PyObject*);
|
|
|
+typedef PyVar (*BinaryFuncC)(VM*, PyVar, PyVar);
|
|
|
+typedef void (*RegisterFunc)(VM*, PyVar, PyVar);
|
|
|
|
|
|
#if PK_ENABLE_PROFILER
|
|
|
struct NextBreakpoint{
|
|
|
@@ -42,23 +42,23 @@ struct NextBreakpoint{
|
|
|
#endif
|
|
|
|
|
|
struct PyTypeInfo{
|
|
|
- PyObject* obj; // never be garbage collected
|
|
|
+ PyVar obj; // never be garbage collected
|
|
|
Type base;
|
|
|
- PyObject* mod; // never be garbage collected
|
|
|
+ PyVar mod; // never be garbage collected
|
|
|
StrName name;
|
|
|
bool subclass_enabled;
|
|
|
|
|
|
std::vector<StrName> annotated_fields = {};
|
|
|
|
|
|
// unary operators
|
|
|
- Str (*m__repr__)(VM* vm, PyObject*) = nullptr;
|
|
|
- Str (*m__str__)(VM* vm, PyObject*) = nullptr;
|
|
|
- i64 (*m__hash__)(VM* vm, PyObject*) = nullptr;
|
|
|
- i64 (*m__len__)(VM* vm, PyObject*) = nullptr;
|
|
|
- PyObject* (*m__iter__)(VM* vm, PyObject*) = nullptr;
|
|
|
- unsigned (*m__next__)(VM* vm, PyObject*) = nullptr;
|
|
|
- PyObject* (*m__neg__)(VM* vm, PyObject*) = nullptr;
|
|
|
- PyObject* (*m__invert__)(VM* vm, PyObject*) = nullptr;
|
|
|
+ Str (*m__repr__)(VM* vm, PyVar) = nullptr;
|
|
|
+ Str (*m__str__)(VM* vm, PyVar) = nullptr;
|
|
|
+ i64 (*m__hash__)(VM* vm, PyVar) = nullptr;
|
|
|
+ i64 (*m__len__)(VM* vm, PyVar) = nullptr;
|
|
|
+ PyVar (*m__iter__)(VM* vm, PyVar) = nullptr;
|
|
|
+ unsigned (*m__next__)(VM* vm, PyVar) = nullptr;
|
|
|
+ PyVar (*m__neg__)(VM* vm, PyVar) = nullptr;
|
|
|
+ PyVar (*m__invert__)(VM* vm, PyVar) = nullptr;
|
|
|
|
|
|
BinaryFuncC m__eq__ = nullptr;
|
|
|
BinaryFuncC m__lt__ = nullptr;
|
|
|
@@ -84,14 +84,14 @@ struct PyTypeInfo{
|
|
|
BinaryFuncC m__xor__ = nullptr;
|
|
|
|
|
|
// indexer
|
|
|
- PyObject* (*m__getitem__)(VM* vm, PyObject*, PyObject*) = nullptr;
|
|
|
- void (*m__setitem__)(VM* vm, PyObject*, PyObject*, PyObject*) = nullptr;
|
|
|
- void (*m__delitem__)(VM* vm, PyObject*, PyObject*) = nullptr;
|
|
|
+ PyVar (*m__getitem__)(VM* vm, PyVar, PyVar) = nullptr;
|
|
|
+ void (*m__setitem__)(VM* vm, PyVar, PyVar, PyVar) = nullptr;
|
|
|
+ void (*m__delitem__)(VM* vm, PyVar, PyVar) = nullptr;
|
|
|
|
|
|
// attributes
|
|
|
- void (*m__setattr__)(VM* vm, PyObject*, StrName, PyObject*) = nullptr;
|
|
|
- PyObject* (*m__getattr__)(VM* vm, PyObject*, StrName) = nullptr;
|
|
|
- bool (*m__delattr__)(VM* vm, PyObject*, StrName) = nullptr;
|
|
|
+ void (*m__setattr__)(VM* vm, PyVar, StrName, PyVar) = nullptr;
|
|
|
+ PyVar (*m__getattr__)(VM* vm, PyVar, StrName) = nullptr;
|
|
|
+ bool (*m__delattr__)(VM* vm, PyVar, StrName) = nullptr;
|
|
|
|
|
|
// backdoors
|
|
|
void (*on_end_subclass)(VM* vm, PyTypeInfo*) = nullptr;
|
|
|
@@ -138,25 +138,25 @@ public:
|
|
|
std::map<StrName, Str> _lazy_modules; // lazy loaded modules
|
|
|
|
|
|
struct{
|
|
|
- PyObject* error;
|
|
|
+ PyVar error;
|
|
|
stack_no_copy<ArgsView> s_view;
|
|
|
} __c;
|
|
|
|
|
|
- PyObject *None, *True, *False, *NotImplemented;
|
|
|
- PyObject *StopIteration, *Ellipsis;
|
|
|
- PyObject *builtins, *_main;
|
|
|
+ PyVar None, True, False, NotImplemented;
|
|
|
+ PyVar StopIteration, Ellipsis;
|
|
|
+ PyVar builtins, _main;
|
|
|
|
|
|
// typeid -> Type
|
|
|
std::map<const std::type_index, Type> _cxx_typeid_map;
|
|
|
// this is for repr() recursion detection (no need to mark)
|
|
|
- std::set<PyObject*> _repr_recursion_set;
|
|
|
+ std::set<PyVar> _repr_recursion_set;
|
|
|
|
|
|
ImportContext __import_context;
|
|
|
- PyObject* __last_exception;
|
|
|
- PyObject* __curr_class;
|
|
|
- PyObject* __cached_object_new;
|
|
|
+ PyVar __last_exception;
|
|
|
+ PyVar __curr_class;
|
|
|
+ PyVar __cached_object_new;
|
|
|
std::map<std::string_view, CodeObject_> __cached_codes;
|
|
|
- std::map<std::string_view, PyObject*> __cached_op_funcs;
|
|
|
+ std::map<std::string_view, PyVar> __cached_op_funcs;
|
|
|
FuncDecl_ __dynamic_func_decl;
|
|
|
|
|
|
#if PK_ENABLE_PROFILER
|
|
|
@@ -186,38 +186,38 @@ public:
|
|
|
VM(bool enable_os=true);
|
|
|
|
|
|
#if PK_REGION("Python Equivalents")
|
|
|
- Str py_str(PyObject* obj); // x -> str(x)
|
|
|
- Str py_repr(PyObject* obj); // x -> repr(x)
|
|
|
- Str py_json(PyObject* obj); // x -> json.dumps(x)
|
|
|
-
|
|
|
- PyObject* py_iter(PyObject* obj); // x -> iter(x)
|
|
|
- PyObject* py_next(PyObject*); // x -> next(x)
|
|
|
- PyObject* _py_next(const PyTypeInfo*, PyObject*); // x -> next(x) with type info cache
|
|
|
- PyObject* py_import(Str path, bool throw_err=true); // x -> __import__(x)
|
|
|
- PyObject* py_negate(PyObject* obj); // x -> -x
|
|
|
-
|
|
|
- List py_list(PyObject*); // x -> list(x)
|
|
|
- bool py_callable(PyObject* obj); // x -> callable(x)
|
|
|
- bool py_bool(PyObject* obj); // x -> bool(x)
|
|
|
- i64 py_hash(PyObject* obj); // x -> hash(x)
|
|
|
-
|
|
|
- bool py_eq(PyObject* lhs, PyObject* rhs); // (lhs, rhs) -> lhs == rhs
|
|
|
- bool py_lt(PyObject* lhs, PyObject* rhs); // (lhs, rhs) -> lhs < rhs
|
|
|
- bool py_le(PyObject* lhs, PyObject* rhs); // (lhs, rhs) -> lhs <= rhs
|
|
|
- bool py_gt(PyObject* lhs, PyObject* rhs); // (lhs, rhs) -> lhs > rhs
|
|
|
- bool py_ge(PyObject* lhs, PyObject* rhs); // (lhs, rhs) -> lhs >= rhs
|
|
|
- bool py_ne(PyObject* lhs, PyObject* rhs){ // (lhs, rhs) -> lhs != rhs
|
|
|
+ Str py_str(PyVar obj); // x -> str(x)
|
|
|
+ Str py_repr(PyVar obj); // x -> repr(x)
|
|
|
+ Str py_json(PyVar obj); // x -> json.dumps(x)
|
|
|
+
|
|
|
+ PyVar py_iter(PyVar obj); // x -> iter(x)
|
|
|
+ PyVar py_next(PyVar); // x -> next(x)
|
|
|
+ PyVar _py_next(const PyTypeInfo*, PyVar); // x -> next(x) with type info cache
|
|
|
+ PyVar py_import(Str path, bool throw_err=true); // x -> __import__(x)
|
|
|
+ PyVar py_negate(PyVar obj); // x -> -x
|
|
|
+
|
|
|
+ List py_list(PyVar); // x -> list(x)
|
|
|
+ bool py_callable(PyVar obj); // x -> callable(x)
|
|
|
+ bool py_bool(PyVar obj); // x -> bool(x)
|
|
|
+ i64 py_hash(PyVar obj); // x -> hash(x)
|
|
|
+
|
|
|
+ bool py_eq(PyVar lhs, PyVar rhs); // (lhs, rhs) -> lhs == rhs
|
|
|
+ bool py_lt(PyVar lhs, PyVar rhs); // (lhs, rhs) -> lhs < rhs
|
|
|
+ bool py_le(PyVar lhs, PyVar rhs); // (lhs, rhs) -> lhs <= rhs
|
|
|
+ bool py_gt(PyVar lhs, PyVar rhs); // (lhs, rhs) -> lhs > rhs
|
|
|
+ bool py_ge(PyVar lhs, PyVar rhs); // (lhs, rhs) -> lhs >= rhs
|
|
|
+ bool py_ne(PyVar lhs, PyVar rhs){ // (lhs, rhs) -> lhs != rhs
|
|
|
return !py_eq(lhs, rhs);
|
|
|
}
|
|
|
|
|
|
- PyObject* py_op(std::string_view name); // (name) -> operator.name
|
|
|
+ PyVar py_op(std::string_view name); // (name) -> operator.name
|
|
|
|
|
|
- void py_exec(std::string_view, PyObject*, PyObject*); // exec(source, globals, locals)
|
|
|
- PyObject* py_eval(std::string_view, PyObject*, PyObject*); // eval(source, globals, locals)
|
|
|
+ void py_exec(std::string_view, PyVar, PyVar); // exec(source, globals, locals)
|
|
|
+ PyVar py_eval(std::string_view, PyVar, PyVar); // eval(source, globals, locals)
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Utility Methods")
|
|
|
- ArgsView cast_array_view(PyObject* obj);
|
|
|
+ ArgsView cast_array_view(PyVar obj);
|
|
|
void set_main_argv(int argc, char** argv);
|
|
|
i64 normalized_index(i64 index, int size);
|
|
|
Str disassemble(CodeObject_ co);
|
|
|
@@ -225,47 +225,47 @@ public:
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Name Lookup Methods")
|
|
|
- PyObject* find_name_in_mro(Type cls, StrName name);
|
|
|
- PyObject* get_unbound_method(PyObject* obj, StrName name, PyObject** self, bool throw_err=true, bool fallback=false);
|
|
|
- PyObject* getattr(PyObject* obj, StrName name, bool throw_err=true);
|
|
|
- void delattr(PyObject* obj, StrName name);
|
|
|
- void setattr(PyObject* obj, StrName name, PyObject* value);
|
|
|
+ PyVar find_name_in_mro(Type cls, StrName name);
|
|
|
+ PyVar get_unbound_method(PyVar obj, StrName name, PyVar* self, bool throw_err=true, bool fallback=false);
|
|
|
+ PyVar getattr(PyVar obj, StrName name, bool throw_err=true);
|
|
|
+ void delattr(PyVar obj, StrName name);
|
|
|
+ void setattr(PyVar obj, StrName name, PyVar value);
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Source Execution Methods")
|
|
|
CodeObject_ compile(std::string_view source, const Str& filename, CompileMode mode, bool unknown_global_scope=false);
|
|
|
Str precompile(std::string_view source, const Str& filename, CompileMode mode);
|
|
|
- PyObject* exec(std::string_view source, Str filename, CompileMode mode, PyObject* _module=nullptr);
|
|
|
- PyObject* exec(std::string_view source);
|
|
|
- PyObject* eval(std::string_view source);
|
|
|
+ PyVar exec(std::string_view source, Str filename, CompileMode mode, PyVar _module=nullptr);
|
|
|
+ PyVar exec(std::string_view source);
|
|
|
+ PyVar eval(std::string_view source);
|
|
|
|
|
|
template<typename ...Args>
|
|
|
- PyObject* _exec(Args&&... args){
|
|
|
+ PyVar _exec(Args&&... args){
|
|
|
callstack.emplace(s_data._sp, std::forward<Args>(args)...);
|
|
|
return __run_top_frame();
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Invocation Methods")
|
|
|
- PyObject* vectorcall(int ARGC, int KWARGC=0, bool op_call=false);
|
|
|
+ PyVar vectorcall(int ARGC, int KWARGC=0, bool op_call=false);
|
|
|
|
|
|
template<typename... Args>
|
|
|
- PyObject* call(PyObject* callable, Args&&... args){
|
|
|
+ PyVar call(PyVar callable, Args&&... args){
|
|
|
PUSH(callable); PUSH(PY_NULL);
|
|
|
__push_varargs(args...);
|
|
|
return vectorcall(sizeof...(args));
|
|
|
}
|
|
|
|
|
|
template<typename... Args>
|
|
|
- PyObject* call_method(PyObject* self, PyObject* callable, Args&&... args){
|
|
|
+ PyVar call_method(PyVar self, PyVar callable, Args&&... args){
|
|
|
PUSH(callable); PUSH(self);
|
|
|
__push_varargs(args...);
|
|
|
return vectorcall(sizeof...(args));
|
|
|
}
|
|
|
|
|
|
template<typename... Args>
|
|
|
- PyObject* call_method(PyObject* self, StrName name, Args&&... args){
|
|
|
- PyObject* callable = get_unbound_method(self, name, &self);
|
|
|
+ PyVar call_method(PyVar self, StrName name, Args&&... args){
|
|
|
+ PyVar callable = get_unbound_method(self, name, &self);
|
|
|
return call_method(self, callable, args...);
|
|
|
}
|
|
|
#endif
|
|
|
@@ -276,16 +276,16 @@ public:
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Magic Bindings")
|
|
|
- void bind__repr__(Type type, Str (*f)(VM*, PyObject*));
|
|
|
- void bind__str__(Type type, Str (*f)(VM*, PyObject*));
|
|
|
- void bind__iter__(Type type, PyObject* (*f)(VM*, PyObject*));
|
|
|
+ void bind__repr__(Type type, Str (*f)(VM*, PyVar));
|
|
|
+ void bind__str__(Type type, Str (*f)(VM*, PyVar));
|
|
|
+ void bind__iter__(Type type, PyVar (*f)(VM*, PyVar));
|
|
|
|
|
|
- void bind__next__(Type type, unsigned (*f)(VM*, PyObject*));
|
|
|
- [[deprecated]] void bind__next__(Type type, PyObject* (*f)(VM*, PyObject*));
|
|
|
- void bind__neg__(Type type, PyObject* (*f)(VM*, PyObject*));
|
|
|
- void bind__invert__(Type type, PyObject* (*f)(VM*, PyObject*));
|
|
|
- void bind__hash__(Type type, i64 (*f)(VM* vm, PyObject*));
|
|
|
- void bind__len__(Type type, i64 (*f)(VM* vm, PyObject*));
|
|
|
+ void bind__next__(Type type, unsigned (*f)(VM*, PyVar));
|
|
|
+ [[deprecated]] void bind__next__(Type type, PyVar (*f)(VM*, PyVar));
|
|
|
+ void bind__neg__(Type type, PyVar (*f)(VM*, PyVar));
|
|
|
+ void bind__invert__(Type type, PyVar (*f)(VM*, PyVar));
|
|
|
+ void bind__hash__(Type type, i64 (*f)(VM* vm, PyVar));
|
|
|
+ void bind__len__(Type type, i64 (*f)(VM* vm, PyVar));
|
|
|
|
|
|
void bind__eq__(Type type, BinaryFuncC f);
|
|
|
void bind__lt__(Type type, BinaryFuncC f);
|
|
|
@@ -309,35 +309,35 @@ public:
|
|
|
void bind__or__(Type type, BinaryFuncC f);
|
|
|
void bind__xor__(Type type, BinaryFuncC f);
|
|
|
|
|
|
- void bind__getitem__(Type type, PyObject* (*f)(VM*, PyObject*, PyObject*));
|
|
|
- void bind__setitem__(Type type, void (*f)(VM*, PyObject*, PyObject*, PyObject*));
|
|
|
- void bind__delitem__(Type type, void (*f)(VM*, PyObject*, PyObject*));
|
|
|
+ void bind__getitem__(Type type, PyVar (*f)(VM*, PyVar, PyVar));
|
|
|
+ void bind__setitem__(Type type, void (*f)(VM*, PyVar, PyVar, PyVar));
|
|
|
+ void bind__delitem__(Type type, void (*f)(VM*, PyVar, PyVar));
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("General Bindings")
|
|
|
- PyObject* bind_func(PyObject* obj, StrName name, int argc, NativeFuncC fn, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
- PyObject* bind_func(Type type, StrName name, int argc, NativeFuncC fn, any userdata={}, BindType bt=BindType::DEFAULT){
|
|
|
+ PyVar bind_func(PyVar obj, StrName name, int argc, NativeFuncC fn, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind_func(Type type, StrName name, int argc, NativeFuncC fn, any userdata={}, BindType bt=BindType::DEFAULT){
|
|
|
return bind_func(_t(type), name, argc, fn, std::move(userdata), bt);
|
|
|
}
|
|
|
- PyObject* bind_property(PyObject*, const char*, NativeFuncC fget, NativeFuncC fset=nullptr);
|
|
|
+ PyVar bind_property(PyVar, const char*, NativeFuncC fget, NativeFuncC fset=nullptr);
|
|
|
template<typename T, typename F, bool ReadOnly=false>
|
|
|
- PyObject* bind_field(PyObject*, const char*, F T::*);
|
|
|
+ PyVar bind_field(PyVar, const char*, F T::*);
|
|
|
|
|
|
- PyObject* bind(PyObject*, const char*, NativeFuncC, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, NativeFuncC, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
template<typename Ret, typename... Params>
|
|
|
- PyObject* bind(PyObject*, const char*, Ret(*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, Ret(*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
template<typename Ret, typename T, typename... Params>
|
|
|
- PyObject* bind(PyObject*, const char*, Ret(T::*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, Ret(T::*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
|
|
|
- PyObject* bind(PyObject*, const char*, const char*, NativeFuncC, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, const char*, NativeFuncC, any userdata={}, BindType bt=BindType::DEFAULT);
|
|
|
template<typename Ret, typename... Params>
|
|
|
- PyObject* bind(PyObject*, const char*, const char*, Ret(*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, const char*, Ret(*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
template<typename Ret, typename T, typename... Params>
|
|
|
- PyObject* bind(PyObject*, const char*, const char*, Ret(T::*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
+ PyVar bind(PyVar, const char*, const char*, Ret(T::*)(Params...), BindType bt=BindType::DEFAULT);
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Error Reporting Methods")
|
|
|
- void _error(PyObject*);
|
|
|
+ void _error(PyVar);
|
|
|
void StackOverflowError() { __builtin_error("StackOverflowError"); }
|
|
|
void IOError(const Str& msg) { __builtin_error("IOError", msg); }
|
|
|
void NotImplementedError(){ __builtin_error("NotImplementedError"); }
|
|
|
@@ -350,44 +350,44 @@ public:
|
|
|
void ZeroDivisionError(){ __builtin_error("ZeroDivisionError", "division by zero"); }
|
|
|
void NameError(StrName name){ __builtin_error("NameError", _S("name ", name.escape() + " is not defined")); }
|
|
|
void UnboundLocalError(StrName name){ __builtin_error("UnboundLocalError", _S("local variable ", name.escape() + " referenced before assignment")); }
|
|
|
- void KeyError(PyObject* obj){ __builtin_error("KeyError", obj); }
|
|
|
+ void KeyError(PyVar obj){ __builtin_error("KeyError", obj); }
|
|
|
void ImportError(const Str& msg){ __builtin_error("ImportError", msg); }
|
|
|
void AssertionError(const Str& msg){ __builtin_error("AssertionError", msg); }
|
|
|
void AssertionError(){ __builtin_error("AssertionError"); }
|
|
|
- void BinaryOptError(const char* op, PyObject* _0, PyObject* _1);
|
|
|
- void AttributeError(PyObject* obj, StrName name);
|
|
|
+ void BinaryOptError(const char* op, PyVar _0, PyVar _1);
|
|
|
+ void AttributeError(PyVar obj, StrName name);
|
|
|
void AttributeError(const Str& msg){ __builtin_error("AttributeError", msg); }
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("Type Checking Methods")
|
|
|
- bool isinstance(PyObject* obj, Type base);
|
|
|
+ bool isinstance(PyVar obj, Type base);
|
|
|
bool issubclass(Type cls, Type base);
|
|
|
- void check_type(PyObject* obj, Type type){ if(!is_type(obj, type)) TypeError(type, _tp(obj)); }
|
|
|
- void check_compatible_type(PyObject* obj, Type type){ if(!isinstance(obj, type)) TypeError(type, _tp(obj)); }
|
|
|
+ void check_type(PyVar obj, Type type){ if(!is_type(obj, type)) TypeError(type, _tp(obj)); }
|
|
|
+ void check_compatible_type(PyVar obj, Type type){ if(!isinstance(obj, type)) TypeError(type, _tp(obj)); }
|
|
|
|
|
|
- Type _tp(PyObject* obj){ return is_small_int(obj) ? tp_int : obj->type; }
|
|
|
- const PyTypeInfo* _tp_info(PyObject* obj) { return &_all_types[_tp(obj)]; }
|
|
|
+ Type _tp(PyVar obj){ return is_small_int(obj) ? tp_int : obj->type; }
|
|
|
+ const PyTypeInfo* _tp_info(PyVar obj) { return &_all_types[_tp(obj)]; }
|
|
|
const PyTypeInfo* _tp_info(Type type) { return &_all_types[type]; }
|
|
|
- PyObject* _t(PyObject* obj){ return _all_types[_tp(obj)].obj; }
|
|
|
- PyObject* _t(Type type){ return _all_types[type].obj; }
|
|
|
+ PyVar _t(PyVar obj){ return _all_types[_tp(obj)].obj; }
|
|
|
+ PyVar _t(Type type){ return _all_types[type].obj; }
|
|
|
#endif
|
|
|
|
|
|
#if PK_REGION("User Type Registration")
|
|
|
- PyObject* new_module(Str name, Str package="");
|
|
|
- PyObject* new_type_object(PyObject* mod, StrName name, Type base, bool subclass_enabled=true);
|
|
|
+ PyVar new_module(Str name, Str package="");
|
|
|
+ PyVar new_type_object(PyVar mod, StrName name, Type base, bool subclass_enabled=true);
|
|
|
|
|
|
template<typename T>
|
|
|
Type _tp_user(){ return _find_type_in_cxx_typeid_map<T>(); }
|
|
|
template<typename T>
|
|
|
- bool is_user_type(PyObject* obj){ return _tp(obj) == _tp_user<T>(); }
|
|
|
+ bool is_user_type(PyVar obj){ return _tp(obj) == _tp_user<T>(); }
|
|
|
|
|
|
template<typename T>
|
|
|
- PyObject* register_user_class(PyObject*, StrName, RegisterFunc, Type base=tp_object, bool subclass_enabled=false);
|
|
|
+ PyVar register_user_class(PyVar, StrName, RegisterFunc, Type base=tp_object, bool subclass_enabled=false);
|
|
|
template<typename T>
|
|
|
- PyObject* register_user_class(PyObject*, StrName, Type base=tp_object, bool subclass_enabled=false);
|
|
|
+ PyVar register_user_class(PyVar, StrName, Type base=tp_object, bool subclass_enabled=false);
|
|
|
|
|
|
template<typename T, typename ...Args>
|
|
|
- PyObject* new_user_object(Args&&... args){
|
|
|
+ PyVar new_user_object(Args&&... args){
|
|
|
return heap.gcnew<T>(_tp_user<T>(), std::forward<Args>(args)...);
|
|
|
}
|
|
|
#endif
|
|
|
@@ -413,29 +413,29 @@ public:
|
|
|
#if PK_DEBUG_CEVAL_STEP
|
|
|
void __log_s_data(const char* title = nullptr);
|
|
|
#endif
|
|
|
- PyObject* __py_exec_internal(const CodeObject_& code, PyObject* globals, PyObject* locals);
|
|
|
+ PyVar __py_exec_internal(const CodeObject_& code, PyVar globals, PyVar locals);
|
|
|
void __breakpoint();
|
|
|
- PyObject* __format_object(PyObject*, Str);
|
|
|
- PyObject* __run_top_frame();
|
|
|
+ PyVar __format_object(PyVar, Str);
|
|
|
+ PyVar __run_top_frame();
|
|
|
void __pop_frame();
|
|
|
- PyObject* __py_generator(Frame&& frame, ArgsView buffer);
|
|
|
+ PyVar __py_generator(Frame&& frame, ArgsView buffer);
|
|
|
void __op_unpack_sequence(uint16_t arg);
|
|
|
- void __prepare_py_call(PyObject**, ArgsView, ArgsView, const FuncDecl_&);
|
|
|
+ void __prepare_py_call(PyVar*, ArgsView, ArgsView, const FuncDecl_&);
|
|
|
void __unpack_as_list(ArgsView args, List& list);
|
|
|
void __unpack_as_dict(ArgsView args, Dict& dict);
|
|
|
void __raise_exc(bool re_raise=false);
|
|
|
void __init_builtin_types();
|
|
|
void __post_init_builtin_types();
|
|
|
void __builtin_error(StrName type);
|
|
|
- void __builtin_error(StrName type, PyObject* arg);
|
|
|
+ void __builtin_error(StrName type, PyVar arg);
|
|
|
void __builtin_error(StrName type, const Str& msg);
|
|
|
void __push_varargs(){}
|
|
|
- void __push_varargs(PyObject* _0){ PUSH(_0); }
|
|
|
- void __push_varargs(PyObject* _0, PyObject* _1){ PUSH(_0); PUSH(_1); }
|
|
|
- void __push_varargs(PyObject* _0, PyObject* _1, PyObject* _2){ PUSH(_0); PUSH(_1); PUSH(_2); }
|
|
|
- void __push_varargs(PyObject* _0, PyObject* _1, PyObject* _2, PyObject* _3){ PUSH(_0); PUSH(_1); PUSH(_2); PUSH(_3); }
|
|
|
- PyObject* __pack_next_retval(unsigned);
|
|
|
- PyObject* __minmax_reduce(bool (VM::*op)(PyObject*, PyObject*), PyObject* args, PyObject* key);
|
|
|
+ void __push_varargs(PyVar _0){ PUSH(_0); }
|
|
|
+ void __push_varargs(PyVar _0, PyVar _1){ PUSH(_0); PUSH(_1); }
|
|
|
+ void __push_varargs(PyVar _0, PyVar _1, PyVar _2){ PUSH(_0); PUSH(_1); PUSH(_2); }
|
|
|
+ void __push_varargs(PyVar _0, PyVar _1, PyVar _2, PyVar _3){ PUSH(_0); PUSH(_1); PUSH(_2); PUSH(_3); }
|
|
|
+ PyVar __pack_next_retval(unsigned);
|
|
|
+ PyVar __minmax_reduce(bool (VM::*op)(PyVar, PyVar), PyVar args, PyVar key);
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -464,10 +464,10 @@ template<> constexpr Type _find_type_in_const_cxx_typeid_map<StaticMethod>(){ re
|
|
|
template<> constexpr Type _find_type_in_const_cxx_typeid_map<ClassMethod>(){ return VM::tp_classmethod; }
|
|
|
|
|
|
template<typename __T>
|
|
|
-PyObject* py_var(VM* vm, __T&& value){
|
|
|
+PyVar py_var(VM* vm, __T&& value){
|
|
|
using T = std::decay_t<__T>;
|
|
|
|
|
|
- static_assert(!std::is_same_v<T, PyObject*>, "py_var(VM*, PyObject*) is not allowed");
|
|
|
+ static_assert(!std::is_same_v<T, PyVar>, "py_var(VM*, PyVar) is not allowed");
|
|
|
|
|
|
if constexpr(std::is_same_v<T, const char*> || std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>){
|
|
|
// str (shortcuts)
|
|
|
@@ -483,7 +483,7 @@ PyObject* py_var(VM* vm, __T&& value){
|
|
|
i64 val = static_cast<i64>(std::forward<__T>(value));
|
|
|
if(val >= Number::kMinSmallInt && val <= Number::kMaxSmallInt){
|
|
|
val = (val << 2) | 0b10;
|
|
|
- return reinterpret_cast<PyObject*>(val);
|
|
|
+ return reinterpret_cast<PyVar>(val);
|
|
|
}else{
|
|
|
return vm->heap.gcnew<i64>(vm->tp_int, val);
|
|
|
}
|
|
|
@@ -504,7 +504,7 @@ PyObject* py_var(VM* vm, __T&& value){
|
|
|
}
|
|
|
|
|
|
template<typename __T, bool with_check>
|
|
|
-__T _py_cast__internal(VM* vm, PyObject* obj) {
|
|
|
+__T _py_cast__internal(VM* vm, PyVar obj) {
|
|
|
static_assert(!std::is_rvalue_reference_v<__T>, "rvalue reference is not allowed");
|
|
|
|
|
|
using T = std::decay_t<__T>;
|
|
|
@@ -569,13 +569,13 @@ __T _py_cast__internal(VM* vm, PyObject* obj) {
|
|
|
}
|
|
|
|
|
|
template<typename __T>
|
|
|
-__T py_cast(VM* vm, PyObject* obj) { return _py_cast__internal<__T, true>(vm, obj); }
|
|
|
+__T py_cast(VM* vm, PyVar obj) { return _py_cast__internal<__T, true>(vm, obj); }
|
|
|
template<typename __T>
|
|
|
-__T _py_cast(VM* vm, PyObject* obj) { return _py_cast__internal<__T, false>(vm, obj); }
|
|
|
+__T _py_cast(VM* vm, PyVar obj) { return _py_cast__internal<__T, false>(vm, obj); }
|
|
|
|
|
|
template<typename T>
|
|
|
-PyObject* VM::register_user_class(PyObject* mod, StrName name, RegisterFunc _register, Type base, bool subclass_enabled){
|
|
|
- PyObject* type = new_type_object(mod, name, base, subclass_enabled);
|
|
|
+PyVar VM::register_user_class(PyVar mod, StrName name, RegisterFunc _register, Type base, bool subclass_enabled){
|
|
|
+ PyVar type = new_type_object(mod, name, base, subclass_enabled);
|
|
|
mod->attr().set(name, type);
|
|
|
_cxx_typeid_map[typeid(T)] = PK_OBJ_GET(Type, type);
|
|
|
_register(this, mod, type);
|
|
|
@@ -593,7 +593,7 @@ PyObject* VM::register_user_class(PyObject* mod, StrName name, RegisterFunc _reg
|
|
|
}
|
|
|
|
|
|
template<typename T>
|
|
|
-PyObject* VM::register_user_class(PyObject* mod, StrName name, Type base, bool subclass_enabled){
|
|
|
+PyVar VM::register_user_class(PyVar mod, StrName name, Type base, bool subclass_enabled){
|
|
|
return register_user_class<T>(mod, name, &T::_register, base, subclass_enabled);
|
|
|
}
|
|
|
|