Main.c 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "Compiler.h"
  5. #include "Script.h"
  6. #include "Test.h"
  7. #include "tokenizer/Tokenizer.h"
  8. long getNanos() {
  9. struct timespec time;
  10. clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
  11. return time.tv_nsec + time.tv_sec * 1000000000l;
  12. }
  13. int main(int argAmount, const char** args) {
  14. if(argAmount >= 3 && strcmp(args[1], "test") == 0) {
  15. tsStart(args[2]);
  16. } else if(argAmount >= 2) {
  17. if(tTokenize(args[1])) {
  18. puts(tGetError());
  19. return 0;
  20. }
  21. ByteCode* code = cCompile();
  22. if(code == NULL) {
  23. puts(tGetError());
  24. return 0;
  25. }
  26. Script* sc = sInit(code);
  27. long time = -getNanos();
  28. sRun(sc);
  29. time += getNanos();
  30. printf("----------------\n%ld ns\n", time);
  31. sDelete(sc);
  32. }
  33. return 0;
  34. }