Main.c 1.3 KB

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