This commit is contained in:
blueloveTH 2023-05-25 12:33:48 +08:00
parent 1d9c565b64
commit e982a4e60b
4 changed files with 16 additions and 2 deletions

View File

@ -615,3 +615,10 @@ bool pkpy_eval(pkpy_vm* vm_handle, const char* code) {
ERRHANDLER_CLOSE
return true;
}
void* pkpy_get_id(pkpy_vm* vm_handle, int index) {
CVM* vm = (CVM*) vm_handle;
index = lua_to_cstack_index(index, vm->c_data->size());
PyObject* o = vm->c_data->begin()[index];
return (void*) o;
}

View File

@ -114,6 +114,8 @@ PK_EXPORT bool pkpy_getattr(pkpy_vm*, const char* name);
PK_EXPORT bool pkpy_setattr(pkpy_vm*, const char* name);
PK_EXPORT bool pkpy_eval(pkpy_vm*, const char* source);
PK_EXPORT void* pkpy_get_id(pkpy_vm*, int index);
#ifdef __cplusplus
}
#endif

View File

@ -75,6 +75,11 @@ struct VoidP{
return _CAST(VoidP&, lhs).ptr <= CAST(VoidP&, rhs).ptr;
});
vm->bind__hash__(OBJ_GET(Type, type), [](VM* vm, PyObject* obj){
VoidP& self = _CAST(VoidP&, obj);
return reinterpret_cast<i64>(self.ptr);
});
vm->bind_method<1>(type, "set_base_offset", [](VM* vm, ArgsView args){
VoidP& self = _CAST(VoidP&, args[0]);
if(is_non_tagged_type(args[1], vm->tp_str)){

View File

@ -100,8 +100,8 @@ inline void init_builtins(VM* _vm) {
_vm->bind_builtin_func<1>("id", [](VM* vm, ArgsView args) {
PyObject* obj = args[0];
if(is_tagged(obj)) return VAR((i64)0);
return VAR(BITS(obj));
if(is_tagged(obj)) return vm->None;
return VAR_T(VoidP, obj);
});
_vm->bind_builtin_func<2>("divmod", [](VM* vm, ArgsView args) {