main.cc
来自「一个mips虚拟机非常好代码,使用C++来编写的,希望大家多学学,」· CC 代码 · 共 92 行
CC
92 行
#include <signal.h>#include <stdio.h>#include <exception>#include <new>#include <tcl.h>#include "error.hh"#include "sulima.hh"// Guess what. main() and friends, convoluted by Tcl and exceptions.static int status = TCL_OK;extern "C" { static void cleanup(ClientData dummy) { // Dump the Tcl result to the screen. if (sulima) { try { const char *s = Tcl_GetStringResult(sulima_tcl); if (*s) sulima->msg("%s", s); delete sulima; sulima = 0; } catch (const Error &e) { Tcl_SetResult(sulima_tcl, (char *)e.what(), TCL_VOLATILE); } catch (...) { Tcl_SetResult(sulima_tcl, "ERROR: Bailing out.", TCL_VOLATILE); } } } static void signal_cleanup(int) { signal(SIGINT, SIG_DFL); Tcl_Exit(0); } static int init(Tcl_Interp *interp) { sulima_tcl = interp; Tcl_CreateExitHandler((Tcl_ExitProc *)cleanup, 0); signal(SIGINT, signal_cleanup); Tcl_GlobalEval(sulima_tcl, "namespace eval sim { }"); Tcl_PkgProvide(sulima_tcl, "Sulima", "1.0"); try { sulima = new Sulima(); } catch (const Error &e) { Tcl_SetResult(interp, (char *)e.what(), TCL_VOLATILE); return (status = TCL_ERROR); } catch (...) { Tcl_SetResult(interp, "ERROR: Bailing out.", TCL_VOLATILE); return (status = TCL_ERROR); } return (status = TCL_OK); }}static voidout_of_memory(){ throw OutOfMemory();}static voidbail_out(){ if (sulima) sulima->log("ERROR: Unexpected C++ exception. Bailing out."); fprintf(stderr, "ERROR: Unexpected C++ exception. Bailing out.\n");}intmain(int argc, char **argv){ std::set_new_handler(out_of_memory); std::set_unexpected(bail_out); std::set_terminate(bail_out); Tcl_Main(argc, argv, (Tcl_AppInitProc *)init); Tcl_Exit(status == TCL_OK ? EXIT_SUCCESS : EXIT_FAILURE);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?