common.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <algorithm>
  26. // #include <filesystem>
  27. // namespace fs = std::filesystem;
  28. #ifdef POCKETPY_H
  29. #define UNREACHABLE() throw std::runtime_error( "L" + std::to_string(__LINE__) + " UNREACHABLE()!");
  30. #else
  31. #define UNREACHABLE() throw std::runtime_error( __FILE__ + std::string(":") + std::to_string(__LINE__) + " UNREACHABLE()!");
  32. #endif
  33. #define PK_VERSION "0.9.0"
  34. #if defined(__EMSCRIPTEN__) || defined(__arm__) || defined(__i386__)
  35. typedef int32_t i64;
  36. typedef float f64;
  37. #else
  38. typedef int64_t i64;
  39. typedef double f64;
  40. #endif
  41. struct Dummy { };
  42. struct DummyInstance { };
  43. struct DummyModule { };
  44. #define DUMMY_VAL Dummy()
  45. struct Type {
  46. int index;
  47. Type(): index(-1) {}
  48. Type(int index): index(index) {}
  49. inline bool operator==(Type other) const noexcept {
  50. return this->index == other.index;
  51. }
  52. inline bool operator!=(Type other) const noexcept {
  53. return this->index != other.index;
  54. }
  55. };
  56. //#define THREAD_LOCAL thread_local
  57. #define THREAD_LOCAL
  58. #define RAW(T) std::remove_const_t<std::remove_reference_t<T>>
  59. const float kLocalsLoadFactor = 0.67;
  60. const float kInstAttrLoadFactor = 0.67;
  61. const float kTypeAttrLoadFactor = 0.34;