main.c 908 B

12345678910111213141516171819202122232425262728293031
  1. #include "hellovm.h"
  2. int main(int argc, char *argv[]) {
  3. Inter *inter = NULL;
  4. #ifdef DEBUG
  5. setbuf(stdout, NULL); // debug模式下关闭缓冲区以尽快输出信息便于debug
  6. setbuf(stderr, NULL);
  7. setbuf(stdin, NULL);
  8. #endif
  9. atexit(freeArgs);
  10. signal(SIGINT, SIG_IGN);
  11. if (setjmp(memVirtualMath_Env) == -1){
  12. fprintf(stderr, "ERROR: Fatal memory error encountered, May be caused by insufficient memory!\n");
  13. return 1;
  14. }
  15. memVirtualMathUseJmp = true;
  16. if (getArgs(argc, argv) == -1) // 命令行参数设定
  17. return 2;
  18. initVirtualMath(args.locale);
  19. inter = makeInter(args.out_file, args.error_file, args.in_file, NULL);
  20. runCodeFile(inter, argv + optind); // 从文件中运行代码
  21. if (args.run_commandLine)
  22. runCodeStdin(inter, HelloString); // 从stdin中运行代码
  23. freeInter(inter, true);
  24. return 0;
  25. }