Main.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "Code.h"
  5. #include "Compiler.h"
  6. #include "Memory.h"
  7. #include "SystemFunctions.h"
  8. #include "Tokenizer.h"
  9. #include "Window.h"
  10. int main(int argCount, const char** args) {
  11. if(argCount < 2) {
  12. return 0;
  13. } else if(strcmp(args[1], "w") == 0) {
  14. WindowSettings ws = {.width = 400, .height = 300, .title = "Example"};
  15. Error e = windowInit(&ws);
  16. if(hasError(&e)) {
  17. puts(e.text);
  18. return 0;
  19. }
  20. while(!windowShouldClose()) {
  21. windowNextFrame();
  22. }
  23. puts("Stop window");
  24. windowDestroy();
  25. return 0;
  26. }
  27. static char heap[2500];
  28. memoryInit(heap, sizeof(heap));
  29. // memoryDump();
  30. initSystemFunctions();
  31. Tokenizer t;
  32. Error e = tokenizerInit(&t, args[1]);
  33. if(hasError(&e)) {
  34. puts(e.text);
  35. tokenizerDestroy(&t);
  36. return 0;
  37. }
  38. Code code;
  39. codeInit(&code);
  40. e = compileFile(&t, &code);
  41. tokenizerDestroy(&t);
  42. if(hasError(&e)) {
  43. puts(e.text);
  44. } else {
  45. // codeDump(&code);
  46. // return 0;
  47. // memoryDump();
  48. codeRun(&code);
  49. if(codeHasRunError(&code)) {
  50. puts(codeGetRunError(&code));
  51. }
  52. // memoryDump();
  53. }
  54. codeDestroy(&code);
  55. // memoryDump();
  56. return 0;
  57. }