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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * Discard the top element from the stack.
  17. * Pop <word>
  18. */
  19. L2_OP_POP,
  20. /*
  21. * Duplicate the top element on the stack.
  22. * Push <word at <sptr> - 1>
  23. */
  24. L2_OP_DUP,
  25. /*
  26. * Add two words.
  27. * Pop <word1>
  28. * Pop <word2>
  29. * Push <word1> + <word2>
  30. */
  31. L2_OP_ADD,
  32. /*
  33. * Call a function.
  34. * Pop <word>
  35. * Push <iptr> + 1
  36. * Jump to <word>
  37. */
  38. L2_OP_CALL,
  39. /*
  40. * Return from a function.
  41. * Pop <word>
  42. * Jump to <word>
  43. */
  44. L2_OP_RET,
  45. /*
  46. * Allocate an integer from one word.
  47. * Pop <word>
  48. * Alloc integer <var> from <word>
  49. * Push <var>
  50. */
  51. L2_OP_ALLOC_INTEGER_32,
  52. /*
  53. * Allocate an integer from two words.
  54. * Pop <word1>
  55. * Pop <word2>
  56. * Alloc integer <var> from <word1> << 32 | <word2>
  57. * Push <var>
  58. */
  59. L2_OP_ALLOC_INTEGER_64,
  60. /*
  61. * Allocate a real from one word.
  62. * Pop <word>
  63. * Alloc real <var> from <word>
  64. * Push <var>
  65. */
  66. L2_OP_ALLOC_REAL_32,
  67. /*
  68. * Allocate a real from two words.
  69. * Pop <word1>
  70. * Pop <word2>
  71. * Alloc real <var> from <word1> << 32 | <word2>
  72. * Push <var>
  73. */
  74. L2_OP_ALLOC_REAL_64,
  75. /*
  76. * Allocate a buffer from static data.
  77. * Pop <word1>
  78. * Pop <word2>
  79. * Alloc buffer <var> with length=<word1>, offset=<word2>
  80. * Push <var>
  81. */
  82. L2_OP_ALLOC_BUFFER_STATIC,
  83. /*
  84. * Allocate a zeroed buffer.
  85. * Pop <word>
  86. * Alloc buffer <var> with length=<word>
  87. * Push <var>
  88. */
  89. L2_OP_ALLOC_BUFFER_ZERO,
  90. /*
  91. * Allocate an array.
  92. * Alloc array <var>
  93. * Push <var>
  94. */
  95. L2_OP_ALLOC_ARRAY,
  96. /*
  97. * Allocate an integer->value map.
  98. * Alloc namespace <var>
  99. * Push <var>
  100. */
  101. L2_OP_ALLOC_NAMESPACE,
  102. /*
  103. * Halt execution.
  104. */
  105. L2_OP_HALT,
  106. };
  107. #endif