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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. * Return from a function.
  47. * Pop <word>
  48. * Jump to <word>
  49. */
  50. L2_OP_RET,
  51. /*
  52. * Allocate an integer from one word.
  53. * Pop <word>
  54. * Alloc integer <var> from <word>
  55. * Push <var>
  56. */
  57. L2_OP_ALLOC_INTEGER_32,
  58. /*
  59. * Allocate an integer from two words.
  60. * Pop <word1>
  61. * Pop <word2>
  62. * Alloc integer <var> from <word1> << 32 | <word2>
  63. * Push <var>
  64. */
  65. L2_OP_ALLOC_INTEGER_64,
  66. /*
  67. * Allocate a real from one word.
  68. * Pop <word>
  69. * Alloc real <var> from <word>
  70. * Push <var>
  71. */
  72. L2_OP_ALLOC_REAL_32,
  73. /*
  74. * Allocate a real from two words.
  75. * Pop <word1>
  76. * Pop <word2>
  77. * Alloc real <var> from <word1> << 32 | <word2>
  78. * Push <var>
  79. */
  80. L2_OP_ALLOC_REAL_64,
  81. /*
  82. * Allocate a buffer from static data.
  83. * Pop <word1>
  84. * Pop <word2>
  85. * Alloc buffer <var> with length=<word1>, offset=<word2>
  86. * Push <var>
  87. */
  88. L2_OP_ALLOC_BUFFER_STATIC,
  89. /*
  90. * Allocate a zeroed buffer.
  91. * Pop <word>
  92. * Alloc buffer <var> with length=<word>
  93. * Push <var>
  94. */
  95. L2_OP_ALLOC_BUFFER_ZERO,
  96. /*
  97. * Allocate an array.
  98. * Alloc array <var>
  99. * Push <var>
  100. */
  101. L2_OP_ALLOC_ARRAY,
  102. /*
  103. * Allocate an integer->value map.
  104. * Alloc namespace <var>
  105. * Push <var>
  106. */
  107. L2_OP_ALLOC_NAMESPACE,
  108. /*
  109. * Set a namespace's name to a value.
  110. * Pop <key>
  111. * Pop <val>
  112. * Read <ns>
  113. * Assign <val> to <ns[<key>]>
  114. * Push <val>
  115. */
  116. L2_OP_NAMESPACE_SET,
  117. /*
  118. * Halt execution.
  119. */
  120. L2_OP_HALT,
  121. };
  122. #endif