Main.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "Compiler.h"
  5. #include "Test.h"
  6. #include "libraries/Math.h"
  7. #include "libraries/Time.h"
  8. #include "tokenizer/Tokenizer.h"
  9. #include "utils/Functions.h"
  10. #include "vm/Script.h"
  11. long getNanos() {
  12. struct timespec time;
  13. clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
  14. return time.tv_nsec + time.tv_sec * 1000000000l;
  15. }
  16. static void start(int argAmount, const char** args) {
  17. if(argAmount >= 3 && strcmp(args[1], "test") == 0) {
  18. tsStart(args[2]);
  19. } else if(argAmount >= 2) {
  20. Error e;
  21. tTokenize(args[1], &e);
  22. if(eHasError(&e)) {
  23. puts(e.message);
  24. printf("line: %d\n", e.line);
  25. printf("path: %s\n", e.paths);
  26. return;
  27. }
  28. ByteCode* code = cCompile();
  29. if(code == NULL) {
  30. puts(cGetError());
  31. printf("line: %d\n", cGetLine());
  32. printf("path: %s\n", e.paths);
  33. return;
  34. }
  35. Script* sc = sInit(code);
  36. long time = -getNanos();
  37. sRun(sc);
  38. time += getNanos();
  39. printf("----------------\n%ld ns\n", time);
  40. sDelete(sc);
  41. }
  42. }
  43. int main(int argAmount, const char** args) {
  44. gfsInit();
  45. gstsInit();
  46. lTimeRegister();
  47. lMathRegister();
  48. start(argAmount, args);
  49. gstsDelete();
  50. gfsDelete();
  51. return 0;
  52. }