Main.c 1.2 KB

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