You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bytecode.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * Duplicate the top element on the stack.
  28. * Push <word at <sptr> - 1>
  29. */
  30. L2_OP_DUP,
  31. /*
  32. * Add two words.
  33. * Pop <word1>
  34. * Pop <word2>
  35. * Push <word1> + <word2>
  36. */
  37. L2_OP_ADD,
  38. /*
  39. * Call a function.
  40. * Pop <word>
  41. * Push <iptr> + 1
  42. * Jump to <word>
  43. */
  44. L2_OP_CALL,
  45. /*
  46. * Generate a stack frame.
  47. * Alloc namespace <var>
  48. * NSPush <var>
  49. */
  50. L2_OP_GEN_STACK_FRAME,
  51. /*
  52. * Look up a value from the current stack frame.
  53. * Pop <word>
  54. * Find <val> in stack frame using <word>
  55. * Push <val>
  56. */
  57. L2_OP_STACK_FRAME_LOOKUP,
  58. /*
  59. * Set a value in the current stack frame.
  60. * Pop <key>
  61. * Read <val>
  62. * Assign <val> to stack frame
  63. */
  64. L2_OP_STACK_FRAME_SET,
  65. /*
  66. * Return from a function.
  67. * NSPop
  68. * Pop <word>
  69. * Jump to <word>
  70. */
  71. L2_OP_RET,
  72. /*
  73. * Allocate an integer from one word.
  74. * Pop <word>
  75. * Alloc integer <var> from <word>
  76. * Push <var>
  77. */
  78. L2_OP_ALLOC_INTEGER_32,
  79. /*
  80. * Allocate an integer from two words.
  81. * Pop <word1>
  82. * Pop <word2>
  83. * Alloc integer <var> from <word1> << 32 | <word2>
  84. * Push <var>
  85. */
  86. L2_OP_ALLOC_INTEGER_64,
  87. /*
  88. * Allocate a real from one word.
  89. * Pop <word>
  90. * Alloc real <var> from <word>
  91. * Push <var>
  92. */
  93. L2_OP_ALLOC_REAL_32,
  94. /*
  95. * Allocate a real from two words.
  96. * Pop <high>
  97. * Pop <low>
  98. * Alloc real <var> from <high> << 32 | <low>
  99. * Push <var>
  100. */
  101. L2_OP_ALLOC_REAL_64,
  102. /*
  103. * Allocate a buffer from static data.
  104. * Pop <word1>
  105. * Pop <word2>
  106. * Alloc buffer <var> with length=<word1>, offset=<word2>
  107. * Push <var>
  108. */
  109. L2_OP_ALLOC_BUFFER_STATIC,
  110. /*
  111. * Allocate a zeroed buffer.
  112. * Pop <word>
  113. * Alloc buffer <var> with length=<word>
  114. * Push <var>
  115. */
  116. L2_OP_ALLOC_BUFFER_ZERO,
  117. /*
  118. * Allocate an array.
  119. * Alloc array <var>
  120. * Push <var>
  121. */
  122. L2_OP_ALLOC_ARRAY,
  123. /*
  124. * Allocate an integer->value map.
  125. * Alloc namespace <var>
  126. * Push <var>
  127. */
  128. L2_OP_ALLOC_NAMESPACE,
  129. /*
  130. * Set a namespace's name to a value.
  131. * Pop <key>
  132. * Read <val>
  133. * Read <ns>
  134. * Assign <val> to <ns[<key>]>
  135. */
  136. L2_OP_NAMESPACE_SET,
  137. /*
  138. * Halt execution.
  139. */
  140. L2_OP_HALT,
  141. };
  142. #endif