Main.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. return;
  22. }
  23. ByteCode* code = cCompile();
  24. if(code == NULL) {
  25. puts(cGetError());
  26. printf("line: %d\n", cGetLine());
  27. return;
  28. }
  29. Script* sc = sInit(code);
  30. long time = -getNanos();
  31. sRun(sc);
  32. time += getNanos();
  33. printf("----------------\n%ld ns\n", time);
  34. sDelete(sc);
  35. }
  36. }
  37. int main(int argAmount, const char** args) {
  38. gfsInit();
  39. lTimeRegister();
  40. start(argAmount, args);
  41. gfsDelete();
  42. return 0;
  43. }