hw-simple.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include "sans.h"
  7. #include "symboltable.h"
  8. #include "stack.h"
  9. #include "garbagecollector.h"
  10. #include "runtime.h"
  11. sdata sans_glo[2];
  12. sdata ret_reg;
  13. sdata env_reg;
  14. int main(void) {
  15. sdata n;
  16. u label = 6;
  17. while (1) {
  18. switch (label) {
  19. case 0:
  20. ret_reg = (sdata){.tag = tsymb, .data.value = intern("hello-world")};
  21. env_reg = stack_pop();
  22. n = stack_pop();
  23. assert(n.tag == tlabl);
  24. label = n.data.value;
  25. break;
  26. case 3:
  27. ret_reg = builtin_print(TODO);
  28. env_reg = stack_pop();
  29. n = stack_pop();
  30. assert(n.tag == tlabl);
  31. label = n.data.value;
  32. break;
  33. case 6:
  34. stack_push((sdata){.tag = tlabl, .data.ivalue = 10});
  35. stack_push(env_reg);
  36. label = 0;
  37. break;
  38. case 10:
  39. sans_glo[0] = ret_reg;
  40. stack_push((sdata){.tag = tlabl, .data.ivalue = 15});
  41. stack_push(env_reg);
  42. label = 3;
  43. break;
  44. case 15:
  45. sans_glo[1] = ret_reg;
  46. exit(0);
  47. }
  48. }
  49. }