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.

main.c 685B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "vm/vm.h"
  2. #include "vm/print.h"
  3. #include "bitset.h"
  4. #include <stdio.h>
  5. #include <string.h>
  6. int main() {
  7. l2_word ops[] = {
  8. L2_OP_PUSH, 100,
  9. L2_OP_PUSH, 100,
  10. L2_OP_ADD,
  11. L2_OP_ALLOC_INTEGER_32,
  12. L2_OP_PUSH, 21 /* offset */,
  13. L2_OP_PUSH, 5 /* length */,
  14. L2_OP_ALLOC_BUFFER_STATIC,
  15. L2_OP_POP,
  16. L2_OP_PUSH, 16,
  17. L2_OP_CALL,
  18. L2_OP_HALT,
  19. L2_OP_PUSH, 53,
  20. L2_OP_ALLOC_INTEGER_32,
  21. L2_OP_ALLOC_NAMESPACE,
  22. L2_OP_HALT,
  23. 0, 0,
  24. };
  25. memcpy(&ops[21], "Hello", 5);
  26. struct l2_vm vm;
  27. l2_vm_init(&vm, ops, sizeof(ops) / sizeof(*ops));
  28. l2_vm_run(&vm);
  29. l2_vm_print_state(&vm);
  30. l2_vm_gc(&vm);
  31. printf("Heap:\n");
  32. l2_vm_print_stack(&vm);
  33. l2_vm_free(&vm);
  34. }