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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_NAMESPACE,
  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_namespace {
  33. struct l2_vm_value *parent;
  34. size_t len;
  35. size_t size;
  36. l2_word mask;
  37. l2_word data[];
  38. };
  39. void l2_vm_namespace_set(struct l2_vm_value *ns, l2_word key, l2_word val);
  40. l2_word l2_vm_namespace_get(struct l2_vm_value *ns, l2_word key);
  41. struct l2_vm {
  42. l2_word *ops;
  43. size_t opcount;
  44. struct l2_vm_value *values;
  45. size_t valuessize;
  46. struct l2_bitset valueset;
  47. l2_word stack[1024];
  48. unsigned char stackflags[1024];
  49. l2_word iptr;
  50. l2_word sptr;
  51. };
  52. void l2_vm_init(struct l2_vm *vm, l2_word *ops, size_t opcount);
  53. void l2_vm_free(struct l2_vm *vm);
  54. void l2_vm_step(struct l2_vm *vm);
  55. void l2_vm_run(struct l2_vm *vm);
  56. size_t l2_vm_gc(struct l2_vm *vm);
  57. #endif