config.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef PK_USER_CONFIG_H
  3. #include "user_config.h"
  4. #else
  5. /*************** feature settings ***************/
  6. // Whether to compile os-related modules or not
  7. #ifndef PK_ENABLE_OS // can be overrided by cmake
  8. #define PK_ENABLE_OS 1
  9. #endif
  10. // Enable this if you are working with multi-threading (experimental)
  11. // This triggers necessary locks to make the VM thread-safe
  12. #ifndef PK_ENABLE_THREAD // can be overrided by cmake
  13. #define PK_ENABLE_THREAD 0
  14. #endif
  15. // Enable this for `vm->_ceval_on_step`
  16. #ifndef PK_ENABLE_CEVAL_CALLBACK // can be overrided by cmake
  17. #define PK_ENABLE_CEVAL_CALLBACK 0
  18. #endif
  19. // Whether to use `std::function` to do bindings or not
  20. // By default, functions to be binded must be a C function pointer without capture
  21. // However, someone thinks it's not convenient.
  22. // By setting this to 1, capturing lambdas can be binded,
  23. // but it's slower and may cause severe "code bloat", also needs more time to compile.
  24. #define PK_ENABLE_STD_FUNCTION 0
  25. /*************** debug settings ***************/
  26. // Enable this may help you find bugs
  27. #define PK_DEBUG_EXTRA_CHECK 0
  28. // Do not edit the following settings unless you know what you are doing
  29. #define PK_DEBUG_NO_BUILTINS 0
  30. #define PK_DEBUG_DIS_EXEC 0
  31. #define PK_DEBUG_CEVAL_STEP 0
  32. #define PK_DEBUG_FULL_EXCEPTION 0
  33. #define PK_DEBUG_MEMORY_POOL 0
  34. #define PK_DEBUG_NO_MEMORY_POOL 0
  35. #define PK_DEBUG_NO_AUTO_GC 0
  36. #define PK_DEBUG_GC_STATS 0
  37. /*************** internal settings ***************/
  38. // This is the maximum size of the value stack in void* units
  39. // The actual size in bytes equals `sizeof(void*) * PK_VM_STACK_SIZE`
  40. #define PK_VM_STACK_SIZE 32768
  41. // This is the maximum number of arguments in a function declaration
  42. // including positional arguments, keyword-only arguments, and varargs
  43. // (not recommended to change this / it should be less than 200)
  44. #define PK_MAX_CO_VARNAMES 32
  45. namespace pkpy{
  46. // Hash table load factor (smaller ones mean less collision but more memory)
  47. // For class instance
  48. inline const float kInstAttrLoadFactor = 0.67f;
  49. // For class itself
  50. inline const float kTypeAttrLoadFactor = 0.5f;
  51. #ifdef _WIN32
  52. inline const char kPlatformSep = '\\';
  53. #else
  54. inline const char kPlatformSep = '/';
  55. #endif
  56. }
  57. #ifdef _MSC_VER
  58. #pragma warning (disable:4267)
  59. #pragma warning (disable:4100)
  60. #pragma warning (disable:4244)
  61. #pragma warning (disable:4996)
  62. #endif
  63. #ifdef _MSC_VER
  64. #define PK_ENABLE_COMPUTED_GOTO 0
  65. #define UNREACHABLE() __assume(0)
  66. #else
  67. #define PK_ENABLE_COMPUTED_GOTO 1
  68. #define UNREACHABLE() __builtin_unreachable()
  69. #endif
  70. #if PK_DEBUG_CEVAL_STEP && defined(PK_ENABLE_COMPUTED_GOTO)
  71. #undef PK_ENABLE_COMPUTED_GOTO
  72. #endif
  73. #endif