From 2898fbd5cbeeb6605a1cea98e331939b1aa3682e Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 30 Dec 2023 15:04:17 +0800 Subject: [PATCH] rename some config keys --- examples/abort-the-vm/user_config.h | 22 ++++++++++------------ include/pocketpy/config.h | 22 ++++++++++------------ include/pocketpy/namedict.h | 2 +- include/pocketpy/obj.h | 4 ++-- src/vm.cpp | 4 ++-- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/examples/abort-the-vm/user_config.h b/examples/abort-the-vm/user_config.h index 7c28da6f..22b1e71e 100644 --- a/examples/abort-the-vm/user_config.h +++ b/examples/abort-the-vm/user_config.h @@ -45,19 +45,17 @@ // (not recommended to change this / it should be less than 200) #define PK_MAX_CO_VARNAMES 32 -namespace pkpy{ - // Hash table load factor (smaller ones mean less collision but more memory) - // For class instance - inline const float kInstAttrLoadFactor = 0.67f; - // For class itself - inline const float kTypeAttrLoadFactor = 0.5f; +// Hash table load factor (smaller ones mean less collision but more memory) +// For class instance +#define PK_INST_ATTR_LOAD_FACTOR 0.67 +// For class itself +#define PK_TYPE_ATTR_LOAD_FACTOR 0.5 - #ifdef _WIN32 - inline const char kPlatformSep = '\\'; - #else - inline const char kPlatformSep = '/'; - #endif -} +#ifdef _WIN32 + #define PK_PLATFORM_SEP '\\' +#else + #define PK_PLATFORM_SEP '/' +#endif #ifdef _MSC_VER #pragma warning (disable:4267) diff --git a/include/pocketpy/config.h b/include/pocketpy/config.h index a1ed612d..820c0488 100644 --- a/include/pocketpy/config.h +++ b/include/pocketpy/config.h @@ -57,19 +57,17 @@ // (not recommended to change this / it should be less than 200) #define PK_MAX_CO_VARNAMES 32 -namespace pkpy{ - // Hash table load factor (smaller ones mean less collision but more memory) - // For class instance - inline const float kInstAttrLoadFactor = 0.67f; - // For class itself - inline const float kTypeAttrLoadFactor = 0.5f; +// Hash table load factor (smaller ones mean less collision but more memory) +// For class instance +#define PK_INST_ATTR_LOAD_FACTOR 0.67 +// For class itself +#define PK_TYPE_ATTR_LOAD_FACTOR 0.5 - #ifdef _WIN32 - inline const char kPlatformSep = '\\'; - #else - inline const char kPlatformSep = '/'; - #endif -} +#ifdef _WIN32 + #define PK_PLATFORM_SEP '\\' +#else + #define PK_PLATFORM_SEP '/' +#endif #ifdef _MSC_VER #pragma warning (disable:4267) diff --git a/include/pocketpy/namedict.h b/include/pocketpy/namedict.h index bcab56a9..e5127a91 100644 --- a/include/pocketpy/namedict.h +++ b/include/pocketpy/namedict.h @@ -119,7 +119,7 @@ while(!_items[i].first.empty()) { \ #define HASH_PROBE_0 HASH_PROBE_1 - LargeNameDict(float load_factor=kInstAttrLoadFactor): _is_small(false), _load_factor(load_factor), _size(0) { + LargeNameDict(float load_factor=PK_INST_ATTR_LOAD_FACTOR): _is_small(false), _load_factor(load_factor), _size(0) { _set_capacity_and_alloc_items(kInitialCapacity); } diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h index 442d26d6..8f3d2fa5 100644 --- a/include/pocketpy/obj.h +++ b/include/pocketpy/obj.h @@ -370,7 +370,7 @@ template<> struct Py_ final: PyObject { Type _value; Py_(Type type, Type val): PyObject(type), _value(val) { - _enable_instance_dict(kTypeAttrLoadFactor); + _enable_instance_dict(PK_TYPE_ATTR_LOAD_FACTOR); } void _obj_gc_mark() override {} void* _value_ptr() override { return &_value; } @@ -379,7 +379,7 @@ struct Py_ final: PyObject { template<> struct Py_ final: PyObject { Py_(Type type): PyObject(type) { - _enable_instance_dict(kTypeAttrLoadFactor); + _enable_instance_dict(PK_TYPE_ATTR_LOAD_FACTOR); } void _obj_gc_mark() override {} void* _value_ptr() override { return nullptr; } diff --git a/src/vm.cpp b/src/vm.cpp index fc39be4d..3ad07860 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -329,7 +329,7 @@ namespace pkpy{ } // try import - Str filename = path.replace('.', kPlatformSep) + ".py"; + Str filename = path.replace('.', PK_PLATFORM_SEP) + ".py"; Str source; bool is_init = false; auto it = _lazy_modules.find(name); @@ -337,7 +337,7 @@ namespace pkpy{ int out_size; unsigned char* out = _import_handler(filename.data, filename.size, &out_size); if(out == nullptr){ - filename = path.replace('.', kPlatformSep).str() + kPlatformSep + "__init__.py"; + filename = path.replace('.', PK_PLATFORM_SEP).str() + PK_PLATFORM_SEP + "__init__.py"; is_init = true; out = _import_handler(filename.data, filename.size, &out_size); }