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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef L2_VM_H
  2. #define L2_VM_H
  3. #include <stdlib.h>
  4. #include "bytecode.h"
  5. #include "bitset.h"
  6. struct l2_vm_value {
  7. enum l2_value_flags {
  8. L2_VAL_TYPE_NONE,
  9. L2_VAL_TYPE_INTEGER,
  10. L2_VAL_TYPE_REAL,
  11. L2_VAL_TYPE_BUFFER,
  12. L2_VAL_TYPE_ARRAY,
  13. L2_VAL_TYPE_MAP,
  14. L2_VAL_MARKED = 1 << 7,
  15. L2_VAL_CONST = 1 << 8,
  16. } flags;
  17. union {
  18. int64_t integer;
  19. double real;
  20. void *data;
  21. };
  22. };
  23. struct l2_vm_buffer {
  24. size_t len;
  25. char data[];
  26. };
  27. struct l2_vm_array {
  28. size_t len;
  29. size_t size;
  30. l2_word data[];
  31. };
  32. struct l2_vm_map {
  33. size_t len;
  34. size_t size;
  35. l2_word data[];
  36. };
  37. struct l2_vm {
  38. l2_word *ops;
  39. size_t opcount;
  40. struct l2_vm_value *values;
  41. size_t valuessize;
  42. struct l2_bitset valueset;
  43. l2_word stack[1024];
  44. unsigned char stackflags[1024];
  45. l2_word iptr;
  46. l2_word sptr;
  47. };
  48. void l2_vm_init(struct l2_vm *vm, l2_word *ops, size_t opcount);
  49. void l2_vm_free(struct l2_vm *vm);
  50. void l2_vm_step(struct l2_vm *vm);
  51. void l2_vm_run(struct l2_vm *vm);
  52. size_t l2_vm_gc(struct l2_vm *vm);
  53. #endif