main.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "__virtualmath.h"
  2. jmp_buf ctrlC_ENV;
  3. bool ctrlCUseJmp = false;
  4. void signalStop(int signum);
  5. int main(int argc, char *argv[]) {
  6. Inter *inter = NULL;
  7. memVirtualMathUseJmp = true;
  8. if (setjmp(memVirtualMath_Env) == -1){
  9. fprintf(stderr, "ERROR: Fatal memory error encountered, May be caused by insufficient memory!\n");
  10. return 1;
  11. }
  12. if (getArgs(argc, argv))
  13. goto args_error;
  14. inter = makeInter(args.out_file, args.error_file, NULL);
  15. ctrlCUseJmp = true;
  16. signal(SIGINT, signalStop);
  17. if (setjmp(ctrlC_ENV) == -1) {
  18. freeArgs();
  19. freeInter(inter, true);
  20. return 2;
  21. }
  22. for (ResultType status = not_return; status != error_return && argv[optind] != NULL; optind++)
  23. status = runCodeBlock(argv[optind], inter);
  24. if (args.run_commandLine) {
  25. printf("%s", HelloString);
  26. while (1) {
  27. runCodeStdin(inter);
  28. if (ferror(stdin) || feof(stdin))
  29. break;
  30. }
  31. }
  32. freeInter(inter, true);
  33. args_error: freeArgs();
  34. return 0;
  35. }
  36. void signalStop(int signum) {
  37. if (ctrlCUseJmp)
  38. longjmp(ctrlC_ENV, -1);
  39. else
  40. exit(1);
  41. }
  42. /** TODO-szh List
  43. * 官方函数
  44. * 官方类
  45. */