Main.c 1.2 KB

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