From 08a8a2f2524f459001b94593199c29c639c37b94 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 18 Apr 2023 20:31:53 +0800 Subject: [PATCH] ... --- src/obj.h | 7 ++++--- src/vm.h | 7 ++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/obj.h b/src/obj.h index 114f1707..5ad48eb1 100644 --- a/src/obj.h +++ b/src/obj.h @@ -13,16 +13,17 @@ class VM; typedef PyObject* (*NativeFuncC)(VM*, ArgsView); typedef std::function NativeFuncCpp; -using NativeFuncRaw = std::variant; typedef shared_ptr CodeObject_; struct NativeFunc { - NativeFuncRaw f; + NativeFuncC f; + NativeFuncCpp f_cpp; int argc; // DONOT include self 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; }; diff --git a/src/vm.h b/src/vm.h index 074e6bb5..fc861b42 100644 --- a/src/vm.h +++ b/src/vm.h @@ -395,11 +395,8 @@ inline PyObject* NativeFunc::operator()(VM* vm, ArgsView args) const{ if(argc != -1 && args_size != argc) { vm->TypeError(fmt("expected ", argc, " arguments, but got ", args_size)); } - if(std::holds_alternative(f)){ - return std::get(f)(vm, args); - }else{ - return std::get(f)(vm, args); - } + if(f != nullptr) return f(vm, args); + return f_cpp(vm, args); } inline void CodeObject::optimize(VM* vm){