common.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #ifdef _MSC_VER
  3. #pragma warning (disable:4267)
  4. #pragma warning (disable:4101)
  5. #define _CRT_NONSTDC_NO_DEPRECATE
  6. #define strdup _strdup
  7. #endif
  8. #include <sstream>
  9. #include <regex>
  10. #include <stack>
  11. #include <cmath>
  12. #include <cstdlib>
  13. #include <stdexcept>
  14. #include <vector>
  15. #include <string>
  16. #include <cstring>
  17. #include <chrono>
  18. #include <string_view>
  19. #include <queue>
  20. #include <iomanip>
  21. #include <memory>
  22. #include <functional>
  23. #include <iostream>
  24. #include <map>
  25. #include <set>
  26. #include <algorithm>
  27. // #include <filesystem>
  28. // namespace fs = std::filesystem;
  29. #ifdef POCKETPY_H
  30. #define UNREACHABLE() throw std::runtime_error( "L" + std::to_string(__LINE__) + " UNREACHABLE()!");
  31. #else
  32. #define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!");
  33. #endif
  34. #define PK_VERSION "0.9.1"
  35. #if defined(__EMSCRIPTEN__) || defined(__arm__) || defined(__i386__)
  36. typedef int32_t i64;
  37. typedef float f64;
  38. #define S_TO_INT std::stoi
  39. #define S_TO_FLOAT std::stof
  40. #else
  41. typedef int64_t i64;
  42. typedef double f64;
  43. #define S_TO_INT std::stoll
  44. #define S_TO_FLOAT std::stod
  45. #endif
  46. struct Dummy { };
  47. struct DummyInstance { };
  48. struct DummyProperty { };
  49. struct DummyModule { };
  50. #define DUMMY_VAL Dummy()
  51. struct Type {
  52. int index;
  53. Type(): index(-1) {}
  54. Type(int index): index(index) {}
  55. inline bool operator==(Type other) const noexcept {
  56. return this->index == other.index;
  57. }
  58. inline bool operator!=(Type other) const noexcept {
  59. return this->index != other.index;
  60. }
  61. };
  62. //#define THREAD_LOCAL thread_local
  63. #define THREAD_LOCAL
  64. #define RAW(T) std::remove_const_t<std::remove_reference_t<T>>
  65. const float kLocalsLoadFactor = 0.67;
  66. const float kInstAttrLoadFactor = 0.67;
  67. const float kTypeAttrLoadFactor = 0.5;
  68. // do extra check for debug
  69. // #define PK_EXTRA_CHECK