mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-22 20:40:18 +00:00
...
This commit is contained in:
parent
b1eb38c009
commit
08a8a2f252
@ -13,16 +13,17 @@ class VM;
|
|||||||
|
|
||||||
typedef PyObject* (*NativeFuncC)(VM*, ArgsView);
|
typedef PyObject* (*NativeFuncC)(VM*, ArgsView);
|
||||||
typedef std::function<PyObject*(VM*, ArgsView)> NativeFuncCpp;
|
typedef std::function<PyObject*(VM*, ArgsView)> NativeFuncCpp;
|
||||||
using NativeFuncRaw = std::variant<NativeFuncC, NativeFuncCpp>;
|
|
||||||
|
|
||||||
typedef shared_ptr<CodeObject> CodeObject_;
|
typedef shared_ptr<CodeObject> CodeObject_;
|
||||||
|
|
||||||
struct NativeFunc {
|
struct NativeFunc {
|
||||||
NativeFuncRaw f;
|
NativeFuncC f;
|
||||||
|
NativeFuncCpp f_cpp;
|
||||||
int argc; // DONOT include self
|
int argc; // DONOT include self
|
||||||
bool method;
|
bool method;
|
||||||
|
|
||||||
NativeFunc(NativeFuncRaw f, int argc, bool method) : f(f), argc(argc), method(method) {}
|
NativeFunc(NativeFuncC f, int argc, bool method) : f(f), argc(argc), method(method) {}
|
||||||
|
NativeFunc(NativeFuncCpp f, int argc, bool method) : f(nullptr), f_cpp(f), argc(argc), method(method) {}
|
||||||
PyObject* operator()(VM* vm, ArgsView args) const;
|
PyObject* operator()(VM* vm, ArgsView args) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
7
src/vm.h
7
src/vm.h
@ -395,11 +395,8 @@ inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{
|
|||||||
if(argc != -1 && args_size != argc) {
|
if(argc != -1 && args_size != argc) {
|
||||||
vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size));
|
vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size));
|
||||||
}
|
}
|
||||||
if(std::holds_alternative<NativeFuncC>(f)){
|
if(f != nullptr) return f(vm, args);
|
||||||
return std::get<NativeFuncC>(f)(vm, args);
|
return f_cpp(vm, args);
|
||||||
}else{
|
|
||||||
return std::get<NativeFuncCpp>(f)(vm, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void CodeObject::optimize(VM* vm){
|
inline void CodeObject::optimize(VM* vm){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user