mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
07f8c6fc06
commit
0d99fbb947
@ -128,8 +128,9 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
return vm->PyStr(s);
|
return vm->PyStr(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_vm->bindMethod<1>("object", "__eq__", CPP_LAMBDA(vm->PyBool(args[0] == args[1])));
|
||||||
|
|
||||||
_vm->bindStaticMethod<1>("type", "__new__", CPP_LAMBDA(args[0]->_type));
|
_vm->bindStaticMethod<1>("type", "__new__", CPP_LAMBDA(args[0]->_type));
|
||||||
_vm->bindMethod<1>("type", "__eq__", CPP_LAMBDA(vm->PyBool(args[0] == args[1])));
|
|
||||||
|
|
||||||
_vm->bindStaticMethod<-1>("range", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindStaticMethod<-1>("range", "__new__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
_Range r;
|
_Range r;
|
||||||
@ -148,7 +149,6 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
|
|
||||||
_vm->bindMethod<0>("NoneType", "__repr__", CPP_LAMBDA(vm->PyStr("None")));
|
_vm->bindMethod<0>("NoneType", "__repr__", CPP_LAMBDA(vm->PyStr("None")));
|
||||||
_vm->bindMethod<0>("NoneType", "__json__", CPP_LAMBDA(vm->PyStr("null")));
|
_vm->bindMethod<0>("NoneType", "__json__", CPP_LAMBDA(vm->PyStr("null")));
|
||||||
_vm->bindMethod<1>("NoneType", "__eq__", CPP_LAMBDA(vm->PyBool(args[0] == args[1])));
|
|
||||||
|
|
||||||
_vm->bindMethodMulti<1>({"int", "float"}, "__truediv__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethodMulti<1>({"int", "float"}, "__truediv__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
f64 rhs = vm->num_to_float(args[1]);
|
f64 rhs = vm->num_to_float(args[1]);
|
||||||
@ -292,7 +292,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
_vm->bindMethod<1>("str", "__eq__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("str", "__eq__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
if(args[0]->is_type(vm->_tp_str) && args[1]->is_type(vm->_tp_str))
|
if(args[0]->is_type(vm->_tp_str) && args[1]->is_type(vm->_tp_str))
|
||||||
return vm->PyBool(vm->PyStr_AS_C(args[0]) == vm->PyStr_AS_C(args[1]));
|
return vm->PyBool(vm->PyStr_AS_C(args[0]) == vm->PyStr_AS_C(args[1]));
|
||||||
return vm->PyBool(args[0] == args[1]); // fallback
|
return vm->PyBool(args[0] == args[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod<1>("str", "__getitem__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("str", "__getitem__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
@ -478,10 +478,6 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
return vm->PyStr(val ? "true" : "false");
|
return vm->PyStr(val ? "true" : "false");
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindMethod<1>("bool", "__eq__", [](VM* vm, const pkpy::ArgList& args) {
|
|
||||||
return vm->PyBool(args[0] == args[1]);
|
|
||||||
});
|
|
||||||
|
|
||||||
_vm->bindMethod<1>("bool", "__xor__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod<1>("bool", "__xor__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
bool _self = vm->PyBool_AS_C(args[0]);
|
bool _self = vm->PyBool_AS_C(args[0]);
|
||||||
bool _obj = vm->PyBool_AS_C(args[1]);
|
bool _obj = vm->PyBool_AS_C(args[1]);
|
||||||
|
@ -118,7 +118,7 @@ namespace pkpy {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extended_self(const PyVar& self){
|
void extend_self(const PyVar& self){
|
||||||
static_assert(std::is_standard_layout_v<PyVar>);
|
static_assert(std::is_standard_layout_v<PyVar>);
|
||||||
PyVar* old_args = _args;
|
PyVar* old_args = _args;
|
||||||
uint8_t old_size = _size;
|
uint8_t old_size = _size;
|
||||||
@ -126,8 +126,8 @@ namespace pkpy {
|
|||||||
_args[0] = self;
|
_args[0] = self;
|
||||||
if(old_size == 0) return;
|
if(old_size == 0) return;
|
||||||
|
|
||||||
memcpy(_args+1, old_args, sizeof(PyVar)*old_size);
|
memcpy((void*)(_args+1), (void*)old_args, sizeof(PyVar)*old_size);
|
||||||
memset(old_args, 0, sizeof(PyVar)*old_size);
|
memset((void*)old_args, 0, sizeof(PyVar)*old_size);
|
||||||
if(old_size >= MAX_POOLING_N || _poolArgList[old_size].size() > 32){
|
if(old_size >= MAX_POOLING_N || _poolArgList[old_size].size() > 32){
|
||||||
delete[] old_args;
|
delete[] old_args;
|
||||||
}else{
|
}else{
|
||||||
|
2
src/vm.h
2
src/vm.h
@ -450,7 +450,7 @@ public:
|
|||||||
if((*callable)->is_type(_tp_bounded_method)){
|
if((*callable)->is_type(_tp_bounded_method)){
|
||||||
auto& bm = PyBoundedMethod_AS_C((*callable));
|
auto& bm = PyBoundedMethod_AS_C((*callable));
|
||||||
callable = &bm.method; // get unbound method
|
callable = &bm.method; // get unbound method
|
||||||
args.extended_self(bm.obj);
|
args.extend_self(bm.obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((*callable)->is_type(_tp_native_function)){
|
if((*callable)->is_type(_tp_native_function)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user