/// <summary> /// Executes a program via the graphical client. returns true if there were no errors /// </summary> /// <param name="exe">the code to execute</param> private static int RunGraphical(Executable exe, string[] args, bool fsf) { // create the computer using (GraphicalComputer computer = new GraphicalComputer()) { try { // initialize program computer.Initialize(exe, args); } catch (MemoryAllocException ex) { Console.Error.WriteLine(ex.Message); return((int)AsmLnkErrorExt.MemoryAllocError); } // set private flags computer.FSF = fsf; // this usage is just going for raw speed, so enable OTRF computer.OTRF = true; // create the console client using (GraphicalClient graphics = new GraphicalClient(computer)) { // begin execution graphics.ShowDialog(); // if there was an error if (computer.Error != ErrorCode.None) { // print error message Console.Error.WriteLine($"\n\nError Encountered: ({computer.Error}) {ErrorCodeToString.Get(computer.Error)}"); // return execution error code return(ExecErrorReturnCode); } // otherwise use return value else { return(computer.ReturnValue); } } } }
// --------------- // // -- execution -- // // --------------- // /// <summary> /// Executes a console program. Return value is either program exit code or a csx64 execution error code (delineated in stderr). /// </summary> /// <param name="exe">the client program to execute</param> /// <param name="args">command line args for the client program</param> /// <param name="fsf">value of FSF (file system flag) furing client program execution</param> /// <param name="time">marks if the execution time should be measured</param> private static int RunConsole(Executable exe, string[] args, bool fsf, bool time) { // create the computer using (Computer computer = new Computer()) { // for this usage, remove max memory restrictions (C# limits array size to intmax) computer.MaxMemory = int.MaxValue; try { // initialize program computer.Initialize(exe, args); } catch (MemoryAllocException ex) { Console.Error.WriteLine(ex.Message); return((int)AsmLnkErrorExt.MemoryAllocError); } // set private flags computer.FSF = fsf; // this usage is just going for raw speed, so enable OTRF computer.OTRF = true; // tie standard streams - stdin is non-interactive because we don't control it computer.OpenFileWrapper(0, new BasicFileWrapper(Console.OpenStandardInput(), false, false, true, false, false)); computer.OpenFileWrapper(1, new BasicFileWrapper(Console.OpenStandardOutput(), false, false, false, true, false)); computer.OpenFileWrapper(2, new BasicFileWrapper(Console.OpenStandardError(), false, false, false, true, false)); // begin execution DateTime start = DateTime.Now; while (computer.Running) { computer.Tick(UInt64.MaxValue - 1); } DateTime stop = DateTime.Now; // if there was an error if (computer.Error != ErrorCode.None) { Console.Error.WriteLine($"\n\nError Encountered: ({computer.Error}) {ErrorCodeToString.Get(computer.Error)}"); return(ExecErrorReturnCode); } // otherwise no error else { if (time) { Console.WriteLine($"\n\nElapsed Time: {stop - start}"); } return(computer.ReturnValue); } } }