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.

vm.h 906B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_ARRAY,
  12. L2_VAL_TYPE_BUFFER,
  13. L2_VAL_MARKED = 1 << 7,
  14. L2_VAL_CONST = 1 << 8,
  15. } flags;
  16. union {
  17. int64_t integer;
  18. double real;
  19. void *data;
  20. };
  21. };
  22. struct l2_vm_buffer {
  23. struct l2_vm_value val;
  24. size_t len;
  25. };
  26. struct l2_vm_array {
  27. struct l2_vm_value val;
  28. size_t len;
  29. size_t size;
  30. };
  31. struct l2_vm {
  32. l2_word *ops;
  33. size_t opcount;
  34. struct l2_vm_value *values;
  35. size_t valuessize;
  36. struct l2_bitset valueset;
  37. l2_word stack[1024];
  38. unsigned char stackflags[1024];
  39. l2_word iptr;
  40. l2_word sptr;
  41. };
  42. void l2_vm_init(struct l2_vm *vm, l2_word *ops, size_t opcount);
  43. void l2_vm_step(struct l2_vm *vm);
  44. void l2_vm_run(struct l2_vm *vm);
  45. size_t l2_vm_gc(struct l2_vm *vm);
  46. #endif