Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #ifndef L2_BYTECODE_H
  2. #define L2_BYTECODE_H
  3. #include <stdint.h>
  4. typedef uint32_t l2_word;
  5. enum l2_opcode {
  6. /*
  7. * Do nothing.
  8. */
  9. L2_OP_NOP,
  10. /*
  11. * Push a value to the stack.
  12. * Push <word>
  13. */
  14. L2_OP_PUSH,
  15. /*
  16. * Push a value to the stack.
  17. * Push <word1>
  18. * Push <word2>
  19. */
  20. L2_OP_PUSH_2,
  21. /*
  22. * Discard the top element from the stack.
  23. * Pop <word>
  24. */
  25. L2_OP_POP,
  26. /*
  27. * Swap the top and second-top elements, then pop the new top element.
  28. * Pop <word1>
  29. * Pop <word2>
  30. * Push <word1>
  31. */
  32. L2_OP_SWAP_POP,
  33. /*
  34. * Duplicate the top element on the stack.
  35. * Push <word at <sptr> - 1>
  36. */
  37. L2_OP_DUP,
  38. /*
  39. * Add two words.
  40. * Pop <word1>
  41. * Pop <word2>
  42. * Push <word1> + <word2>
  43. */
  44. L2_OP_ADD,
  45. /*
  46. * Call a function.
  47. * Pop <argc>
  48. * Pop argc times
  49. * Pop <func>
  50. * Push <iptr> + 1
  51. * Push array with args
  52. * Call <func>
  53. */
  54. L2_OP_FUNC_CALL,
  55. /*
  56. * Jump relative.
  57. * Pop <word>
  58. * Jump <word> words forwards
  59. */
  60. L2_OP_RJMP,
  61. /*
  62. * Look up a value from the current stack frame.
  63. * Pop <word>
  64. * Find <val> in stack frame using <word>
  65. * Push <val>
  66. */
  67. L2_OP_STACK_FRAME_LOOKUP,
  68. /*
  69. * Set a value in the current stack frame.
  70. * Pop <key>
  71. * Read <val>
  72. * Assign <val> to stack frame
  73. */
  74. L2_OP_STACK_FRAME_SET,
  75. /*
  76. * Replace a value on the stack.
  77. * Pop <key>
  78. * Read <val>
  79. * Assign <val> to stack frame
  80. */
  81. L2_OP_STACK_FRAME_REPLACE,
  82. /*
  83. * Return from a function.
  84. * NSPop
  85. * Pop (discard args array)
  86. * Pop <word>
  87. * Jump to <word>
  88. */
  89. L2_OP_RET,
  90. /*
  91. * Allocate an atom from one word.
  92. * Pop <word>
  93. * Alloc integer <var> from <word>
  94. * Push <var>
  95. */
  96. L2_OP_ALLOC_ATOM,
  97. /*
  98. * Allocate a real from two words.
  99. * Pop <high>
  100. * Pop <low>
  101. * Alloc real <var> from <high> << 32 | <low>
  102. * Push <var>
  103. */
  104. L2_OP_ALLOC_REAL,
  105. /*
  106. * Allocate a buffer from static data.
  107. * Pop <word1>
  108. * Pop <word2>
  109. * Alloc buffer <var> with length=<word1>, offset=<word2>
  110. * Push <var>
  111. */
  112. L2_OP_ALLOC_BUFFER_STATIC,
  113. /*
  114. * Allocate a zeroed buffer.
  115. * Pop <word>
  116. * Alloc buffer <var> with length=<word>
  117. * Push <var>
  118. */
  119. L2_OP_ALLOC_BUFFER_ZERO,
  120. /*
  121. * Allocate an array.
  122. * Pop <count>
  123. * Pop count times
  124. * Alloc array <var>
  125. * Push <var>
  126. */
  127. L2_OP_ALLOC_ARRAY,
  128. /*
  129. * Allocate an integer->value map.
  130. * Alloc namespace <var>
  131. * Push <var>
  132. */
  133. L2_OP_ALLOC_NAMESPACE,
  134. /*
  135. * Allocate a function.
  136. * Pop <word>
  137. * Alloc function <var> pointing to location <word>
  138. * Push <var>
  139. */
  140. L2_OP_ALLOC_FUNCTION,
  141. /*
  142. * Set a namespace's name to a value.
  143. * Pop <key>
  144. * Read <val>
  145. * Read <ns>
  146. * Assign <val> to <ns[<key>]>
  147. */
  148. L2_OP_NAMESPACE_SET,
  149. /*
  150. * Lookup a value from a namespace.
  151. * Pop <key>
  152. * Pop <ns>
  153. * Push <ns[<key>]>
  154. */
  155. L2_OP_NAMESPACE_LOOKUP,
  156. /*
  157. * Look up a value from an array.
  158. * Pop <key>
  159. * Read <val>
  160. * Read <arr>
  161. * Assign <val> to <arr[<key>]>
  162. */
  163. L2_OP_DIRECT_ARRAY_LOOKUP,
  164. /*
  165. * Set a value in an array.
  166. * Pop <key>
  167. * Read <arr>
  168. * Push <arr[<key>]>
  169. */
  170. L2_OP_DIRECT_ARRAY_SET,
  171. /*
  172. * Halt execution.
  173. */
  174. L2_OP_HALT,
  175. };
  176. #endif