mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
710748f58d
commit
4c4a7fb471
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "pocketpy.h"
|
#include "pocketpy.h"
|
||||||
|
|
||||||
#define PK_DEBUG_TIME
|
//#define PK_DEBUG_TIME
|
||||||
|
|
||||||
struct Timer{
|
struct Timer{
|
||||||
const char* title;
|
const char* title;
|
||||||
|
@ -554,6 +554,17 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
_vm->bindMethod("ellipsis", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
_vm->bindMethod("ellipsis", "__repr__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
return vm->PyStr("Ellipsis");
|
return vm->PyStr("Ellipsis");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_vm->bindMethod("_native_function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
|
vm->__checkType(args[0], vm->_tp_native_function);
|
||||||
|
const _CppFunc& _self = vm->PyNativeFunction_AS_C(args[0]);
|
||||||
|
return _self(vm, args.subList(1));
|
||||||
|
});
|
||||||
|
|
||||||
|
_vm->bindMethod("function", "__call__", [](VM* vm, const pkpy::ArgList& args) {
|
||||||
|
vm->__checkType(args[0], vm->_tp_function);
|
||||||
|
return vm->call(args[0], args.subList(1));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "builtins.h"
|
#include "builtins.h"
|
||||||
|
@ -86,19 +86,19 @@ namespace pkpy {
|
|||||||
if(_size >= MAX_POOLING_N || _poolArgList[_size].size() > 32){
|
if(_size >= MAX_POOLING_N || _poolArgList[_size].size() > 32){
|
||||||
delete[] _args;
|
delete[] _args;
|
||||||
}else{
|
}else{
|
||||||
for(int i = 0; i < _size; i++) _args[i].reset();
|
for(uint8_t i = 0; i < _size; i++) _args[i].reset();
|
||||||
_poolArgList[_size].push_back(_args);
|
_poolArgList[_size].push_back(_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ArgList(int n){
|
ArgList(uint8_t n){
|
||||||
__tryAlloc(n);
|
if(n != 0) __tryAlloc(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgList(const ArgList& other){
|
ArgList(const ArgList& other){
|
||||||
__tryAlloc(other._size);
|
__tryAlloc(other._size);
|
||||||
for(int i=0; i<_size; i++){
|
for(uint8_t i=0; i<_size; i++){
|
||||||
_args[i] = other._args[i];
|
_args[i] = other._args[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ namespace pkpy {
|
|||||||
|
|
||||||
ArgList(PyVarList&& other){
|
ArgList(PyVarList&& other){
|
||||||
__tryAlloc(other.size());
|
__tryAlloc(other.size());
|
||||||
for(int i=0; i<_size; i++){
|
for(uint8_t i=0; i<_size; i++){
|
||||||
_args[i] = std::move(other[i]);
|
_args[i] = std::move(other[i]);
|
||||||
}
|
}
|
||||||
other.clear();
|
other.clear();
|
||||||
@ -121,7 +121,7 @@ namespace pkpy {
|
|||||||
// deprecated, this is very slow, do not use it!!!
|
// deprecated, this is very slow, do not use it!!!
|
||||||
ArgList(std::initializer_list<PyVar> args){
|
ArgList(std::initializer_list<PyVar> args){
|
||||||
__tryAlloc(args.size());
|
__tryAlloc(args.size());
|
||||||
int i = 0;
|
uint8_t i = 0;
|
||||||
for(auto& arg: args) this->_args[i++] = arg;
|
for(auto& arg: args) this->_args[i++] = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +151,15 @@ namespace pkpy {
|
|||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArgList subList(uint8_t start) const {
|
||||||
|
if(start >= _size) return ArgList(0);
|
||||||
|
ArgList ret(_size - start);
|
||||||
|
for(uint8_t i=start; i<_size; i++){
|
||||||
|
ret[i-start] = _args[i];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
~ArgList(){
|
~ArgList(){
|
||||||
__tryRelease();
|
__tryRelease();
|
||||||
}
|
}
|
||||||
|
@ -22,3 +22,13 @@ a = [1, 2, 3]
|
|||||||
b = &a
|
b = &a
|
||||||
b->append(4)
|
b->append(4)
|
||||||
assert a == [1, 2, 3, 4]
|
assert a == [1, 2, 3, 4]
|
||||||
|
|
||||||
|
def add(a, b):
|
||||||
|
return a+b
|
||||||
|
|
||||||
|
p = &add
|
||||||
|
assert p->__call__(1, 2) == 3
|
||||||
|
|
||||||
|
fun = lambda :6
|
||||||
|
p = &fun
|
||||||
|
assert p->__call__() == 6
|
Loading…
x
Reference in New Issue
Block a user