Main.c 944 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "Compiler.h"
  5. #include "Test.h"
  6. #include "tokenizer/Tokenizer.h"
  7. #include "vm/Script.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(cGetError());
  24. printf("line: %d\n", cGetLine());
  25. return 0;
  26. }
  27. Script* sc = sInit(code);
  28. long time = -getNanos();
  29. sRun(sc);
  30. time += getNanos();
  31. printf("----------------\n%ld ns\n", time);
  32. sDelete(sc);
  33. }
  34. return 0;
  35. }