gmByteCode.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. _____ __ ___ __ ____ _ __
  3. / ___/__ ___ _ ___ / |/ /__ ___ / /_____ __ __/ __/_______(_)__ / /_
  4. / (_ / _ `/ ' \/ -_) /|_/ / _ \/ _ \/ '_/ -_) // /\ \/ __/ __/ / _ \/ __/
  5. \___/\_,_/_/_/_/\__/_/ /_/\___/_//_/_/\_\\__/\_, /___/\__/_/ /_/ .__/\__/
  6. /___/ /_/
  7. See Copyright Notice in gmMachine.h
  8. */
  9. #ifndef _GMBYTECODE_H_
  10. #define _GMBYTECODE_H_
  11. #include "gmConfig.h"
  12. /// \enum gmByteCode
  13. /// \brief gmByteCode are the op codes for the game monkey scripting. The first byte codes MUST match the gmOperator
  14. /// enum.
  15. enum gmByteCode
  16. {
  17. // BC_GETDOT to BC_NOP MUST MATCH ENUM GMOPERATOR
  18. BC_GETDOT = 0, // tos '.' opptr, push result
  19. BC_SETDOT, // tos-1 '.' opptr = tos, tos -= 2
  20. BC_GETIND, // tos-1 = tos-1 [tos], --tos
  21. BC_SETIND, // tos-2 [tos-1] = tos, tos -= 3
  22. // math
  23. BC_OP_ADD,
  24. BC_OP_SUB,
  25. BC_OP_MUL,
  26. BC_OP_DIV,
  27. BC_OP_REM,
  28. #if GM_USE_INCDECOPERATORS
  29. BC_OP_INC,
  30. BC_OP_DEC,
  31. #endif //GM_USE_INCDECOPERATORS
  32. // bit
  33. BC_BIT_OR,
  34. BC_BIT_XOR,
  35. BC_BIT_AND,
  36. BC_BIT_SHL,
  37. BC_BIT_SHR,
  38. BC_BIT_INV,
  39. // compare
  40. BC_OP_LT,
  41. BC_OP_GT,
  42. BC_OP_LTE,
  43. BC_OP_GTE,
  44. BC_OP_EQ,
  45. BC_OP_NEQ,
  46. // unary
  47. BC_OP_NEG,
  48. BC_OP_POS,
  49. BC_OP_NOT,
  50. BC_NOP,
  51. BC_LINE, // indicates instruction is on a new code line to the last executed instruction. used in debug mode
  52. // branch
  53. BC_BRA, // branch always
  54. BC_BRZ, // branch tos equal to zero, --tos
  55. BC_BRNZ, // branch tos not equal to zero, --tos
  56. BC_BRZK, // branch tos equal to zero keep value on stack
  57. BC_BRNZK, // branch tos not equal to zero keep value on stack
  58. BC_CALL, // call op16 num parameters
  59. BC_RET, // return null, ++tos
  60. BC_RETV, // return tos
  61. BC_FOREACH, // op16 op16, table, iterator, leave loop complete bool on stack.
  62. // stack
  63. BC_POP, // --tos
  64. BC_POP2, // tos -=2
  65. BC_DUP, // tos + 1 = tos, ++tos
  66. BC_DUP2, // tos + 1 = tos -1, tos + 2 = tos, tos += 2
  67. BC_SWAP, //
  68. BC_PUSHNULL, // push null,
  69. BC_PUSHINT, // push integer gmint
  70. BC_PUSHINT0, // push 0
  71. BC_PUSHINT1, // push 1
  72. BC_PUSHFP, // push floating point gmfloat
  73. BC_PUSHSTR, // push string opptr
  74. BC_PUSHTBL, // push table
  75. BC_PUSHFN, // push function opptr
  76. BC_PUSHTHIS, // push this
  77. // get set
  78. BC_GETLOCAL, // get local op16 (stack offset) ++tos
  79. BC_SETLOCAL, // set local op16 (stack offset) --tos
  80. BC_GETGLOBAL, // get global opptr (symbol id) ++tos
  81. BC_SETGLOBAL, // set global opptr (symbol id) --tos
  82. BC_GETTHIS, // get this opptr (symbol id) ++tos
  83. BC_SETTHIS, // set this opptr (symbol id) --tos
  84. #if GM_USE_FORK
  85. BC_FORK, // Fork
  86. #endif //GM_USE_FORK
  87. };
  88. #if GM_COMPILE_DEBUG
  89. void gmByteCodePrint(FILE * a_fp, const void * a_byteCode, int a_byteCodeLength);
  90. #endif // GM_COMPILE_DEBUG
  91. #endif