chalkp.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*++
  2. Copyright (c) 2016 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. chalkp.h
  9. Abstract:
  10. This header contains internal definitions for the Chalk interpreter. It
  11. should not be included outside the interpreter core itself.
  12. Author:
  13. Evan Green 28-May-2016
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // Chalk API functions are all exported from the library.
  20. //
  21. #define CK_API __DLLEXPORT
  22. //
  23. // The parser library is statically linked in.
  24. //
  25. #define YY_API
  26. #include <minoca/lib/types.h>
  27. #include <minoca/lib/chalk.h>
  28. #include <assert.h>
  29. #include <stdarg.h>
  30. #include <string.h>
  31. #include "value.h"
  32. #include "core.h"
  33. #include "utils.h"
  34. #include "gc.h"
  35. #include "vm.h"
  36. //
  37. // --------------------------------------------------------------------- Macros
  38. //
  39. //
  40. // These macros allocate, reallocate, and free memory through the Chalk
  41. // memory manager.
  42. //
  43. #define CkAllocate(_Vm, _Size) CkpReallocate((_Vm), NULL, 0, (_Size))
  44. #define CkFree(_Vm, _Memory) CkpReallocate((_Vm), (_Memory), 0, 0)
  45. //
  46. // These macros allocate, reallocate, and free memory directly using the Chalk
  47. // system function. Most allocations go through the Chalk functions for memory
  48. // management and garbage collection.
  49. //
  50. #define CkRawAllocate(_Vm, _Size) \
  51. (_Vm)->Configuration.Reallocate(NULL, (_Size))
  52. #define CkRawReallocate(_Vm, _Memory, _NewSize) \
  53. (_Vm)->Configuration.Reallocate((_Memory), (_NewSize))
  54. #define CkRawFree(_Vm, _Memory) (_Vm)->Configuration.Reallocate((_Memory), 0)
  55. //
  56. // These macros perform basic memory manipulations.
  57. //
  58. #define CkZero(_Memory, _Size) memset((_Memory), 0, (_Size))
  59. #define CkCopy(_Destination, _Source, _Size) \
  60. memcpy((_Destination), (_Source), (_Size))
  61. #define CkCompareMemory(_Left, _Right, _Size) memcmp(_Left, _Right, _Size)
  62. //
  63. // This macro determines if a configuration flag is set.
  64. //
  65. #define CK_VM_FLAG_SET(_Vm, _Flag) \
  66. (((_Vm)->Configuration.Flags & (_Flag)) != 0)
  67. //
  68. // These macros manipulate the stack.
  69. //
  70. #define CK_PUSH(_Fiber, _Value) \
  71. *((_Fiber)->StackTop) = (_Value); \
  72. (_Fiber)->StackTop += 1
  73. #define CK_POP(_Fiber) ((_Fiber)->StackTop -= 1, *((_Fiber)->StackTop))
  74. //
  75. // ---------------------------------------------------------------- Definitions
  76. //
  77. //
  78. // The lex/parse library is statically linked into this library, so define
  79. // away the API decorator.
  80. //
  81. #define YY_API
  82. //
  83. // Define the maximum number of module-level variables, as limited by the
  84. // bytecode op size.
  85. //
  86. #define CK_MAX_MODULE_VARIABLES 0xFFFF
  87. //
  88. // Define the arbitrary maximum length of a method or variable.
  89. //
  90. #define CK_MAX_NAME 64
  91. //
  92. // Define the maximum number of fields a class can have. This limitation
  93. // exists in the bytecode as well in the form of operand size.
  94. //
  95. #define CK_MAX_FIELDS 255
  96. //
  97. // Define the maximum number of nested functions.
  98. //
  99. #define CK_MAX_NESTED_FUNCTIONS 32
  100. //
  101. // Define the initial number of call frames to allocate for any new fiber. This
  102. // should ideally by a power of two.
  103. //
  104. #define CK_INITIAL_CALL_FRAMES 8
  105. //
  106. // Define the initial size of the stack, in elements.
  107. //
  108. #define CK_INITIAL_STACK 8
  109. //
  110. // Define the minimum number of try frames to allocate. These are allocated
  111. // upon executing the first try block.
  112. //
  113. #define CK_MIN_TRY_STACK 8
  114. //
  115. // Define the maximum size of a method signature string.
  116. //
  117. #define CK_MAX_METHOD_SIGNATURE (CK_MAX_NAME + 8)
  118. //
  119. // Define the maximum value for an integer.
  120. //
  121. #define CK_INT_MAX 0x7FFFFFFFFFFFFFFFLL
  122. //
  123. // ------------------------------------------------------ Data Type Definitions
  124. //
  125. //
  126. // -------------------------------------------------------------------- Globals
  127. //
  128. //
  129. // -------------------------------------------------------- Function Prototypes
  130. //