add config.h

This commit is contained in:
blueloveTH 2023-06-11 13:57:07 +08:00
parent 7669c67c38
commit 28c8f68d8d
5 changed files with 70 additions and 41 deletions

View File

@ -6,7 +6,7 @@ with open("src/opcodes.h", "rt", encoding='utf-8') as f:
OPCODES_TEXT = f.read() OPCODES_TEXT = f.read()
pipeline = [ pipeline = [
["common.h", "memory.h", "vector.h", "str.h", "tuplelist.h", "namedict.h", "error.h", "lexer.h"], ["config.h", "common.h", "memory.h", "vector.h", "str.h", "tuplelist.h", "namedict.h", "error.h", "lexer.h"],
["obj.h", "dict.h", "codeobject.h", "frame.h"], ["obj.h", "dict.h", "codeobject.h", "frame.h"],
["gc.h", "vm.h", "ceval.h", "expr.h", "compiler.h", "repl.h"], ["gc.h", "vm.h", "ceval.h", "expr.h", "compiler.h", "repl.h"],
["_generated.h", "cffi.h", "iter.h", "base64.h", "re.h", "linalg.h", "easing.h", "requests.h", "io.h"], ["_generated.h", "cffi.h", "iter.h", "base64.h", "re.h", "linalg.h", "easing.h", "requests.h", "io.h"],

View File

@ -29,36 +29,17 @@
#include <variant> #include <variant>
#include <type_traits> #include <type_traits>
#define PK_VERSION "1.0.2" #include "config.h"
// debug macros #define PK_VERSION "1.0.3"
#define DEBUG_NO_BUILTIN_MODULES 0
#define DEBUG_EXTRA_CHECK 0
#define DEBUG_DIS_EXEC 0
#define DEBUG_CEVAL_STEP 0
#define DEBUG_FULL_EXCEPTION 0
#define DEBUG_MEMORY_POOL 0
#define DEBUG_NO_MEMORY_POOL 0
#define DEBUG_NO_AUTO_GC 0
#define DEBUG_GC_STATS 0
// config macros /*******************************************************************************/
#ifndef PK_ENABLE_OS
#ifdef __ANDROID__ #if PK_ENABLE_STD_FUNCTION
#include <android/ndk-version.h> #include <functional>
#if __NDK_MAJOR__ <= 22
#define PK_ENABLE_OS 0
#else
#define PK_ENABLE_OS 1
#endif #endif
#else /*******************************************************************************/
#define PK_ENABLE_OS 1
#endif
#endif
#if PK_ENABLE_THREAD #if PK_ENABLE_THREAD
#define THREAD_LOCAL thread_local #define THREAD_LOCAL thread_local
@ -77,11 +58,6 @@ struct GIL {
#endif #endif
/*******************************************************************************/ /*******************************************************************************/
// This is the maximum number of arguments in a function declaration
// including positional arguments, keyword-only arguments, and varargs
#define PK_MAX_CO_VARNAMES 255
#if _MSC_VER #if _MSC_VER
#define PK_ENABLE_COMPUTED_GOTO 0 #define PK_ENABLE_COMPUTED_GOTO 0
#define UNREACHABLE() __assume(0) #define UNREACHABLE() __assume(0)
@ -95,6 +71,8 @@ struct GIL {
#endif #endif
/*******************************************************************************/
namespace pkpy{ namespace pkpy{
namespace std = ::std; namespace std = ::std;
@ -165,9 +143,6 @@ struct Type {
#define PK_ASSERT(x) if(!(x)) FATAL_ERROR(); #define PK_ASSERT(x) if(!(x)) FATAL_ERROR();
inline const float kInstAttrLoadFactor = 0.67f;
inline const float kTypeAttrLoadFactor = 0.5f;
struct PyObject; struct PyObject;
#define BITS(p) (reinterpret_cast<i64>(p)) #define BITS(p) (reinterpret_cast<i64>(p))
inline bool is_tagged(PyObject* p) noexcept { return (BITS(p) & 0b11) != 0b00; } inline bool is_tagged(PyObject* p) noexcept { return (BITS(p) & 0b11) != 0b00; }
@ -188,10 +163,4 @@ inline PyObject* const PY_NULL = (PyObject*)0b000011; // tagged null
inline PyObject* const PY_OP_CALL = (PyObject*)0b100011; inline PyObject* const PY_OP_CALL = (PyObject*)0b100011;
inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011; inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011;
#ifdef _WIN32
inline const char kPlatformSep = '\\';
#else
inline const char kPlatformSep = '/';
#endif
} // namespace pkpy } // namespace pkpy

55
src/config.h Normal file
View File

@ -0,0 +1,55 @@
#pragma once
#ifdef PK_USER_CONFIG
#include "user_config.h"
#else
/*************** feature settings ***************/
#define PK_ENABLE_OS 1
#define PK_ENABLE_THREAD 0
// Whether to use `std::function` to do bindings
// By default, the function to be binded must be a C function pointer with no capture
// which is fast and simple. However, someone thinks it's not convenient enough.
// By setting this to 1, capturing lambdas can be binded,
// but it's slower and may cause severe "code bloat", also needs more time to compile.
#define PK_ENABLE_STD_FUNCTION 0
/*************** internal settings ***************/
// This is the maximum size of the value stack in void* units, not bytes
// The actual size is `sizeof(void*) * PK_VM_STACK_SIZE`
#define PK_VM_STACK_SIZE 32768
// This is the maximum number of arguments in a function declaration
// including positional arguments, keyword-only arguments, and varargs
#define PK_MAX_CO_VARNAMES 255
// Hash table load factor (smaller ones mean less collision but more memory)
inline const float kInstAttrLoadFactor = 0.67f;
inline const float kTypeAttrLoadFactor = 0.5f;
#ifdef _WIN32
inline const char kPlatformSep = '\\';
#else
inline const char kPlatformSep = '/';
#endif
/*************** debug settings ***************/
// Enable this may help you to find bugs in the VM
#define DEBUG_EXTRA_CHECK 0
// Do not edit the following settings unless you know what you are doing
#define DEBUG_NO_BUILTIN_MODULES 0
#define DEBUG_DIS_EXEC 0
#define DEBUG_CEVAL_STEP 0
#define DEBUG_FULL_EXCEPTION 0
#define DEBUG_MEMORY_POOL 0
#define DEBUG_NO_MEMORY_POOL 0
#define DEBUG_NO_AUTO_GC 0
#define DEBUG_GC_STATS 0
#endif

View File

@ -100,7 +100,7 @@ struct ValueStackImpl {
ValueStackImpl& operator=(ValueStackImpl&&) = delete; ValueStackImpl& operator=(ValueStackImpl&&) = delete;
}; };
using ValueStack = ValueStackImpl<32768>; using ValueStack = ValueStackImpl<PK_VM_STACK_SIZE>;
struct Frame { struct Frame {
int _ip = -1; int _ip = -1;

View File

@ -11,7 +11,12 @@ struct Frame;
struct Function; struct Function;
class VM; class VM;
#if PK_ENABLE_STD_FUNCTION
using NativeFuncC = std::function<PyObject*(VM*, ArgsView)>;
#else
typedef PyObject* (*NativeFuncC)(VM*, ArgsView); typedef PyObject* (*NativeFuncC)(VM*, ArgsView);
#endif
typedef int (*LuaStyleFuncC)(VM*); typedef int (*LuaStyleFuncC)(VM*);
struct NativeFunc { struct NativeFunc {