/// <summary> /// Starts the interpreter in release mode. The program will be compiled (emitted) and run quickly. Breakpoint statements will be ignored. /// </summary> /// <param name="callback">The cross-AppDomain task proxy.</param> /// <param name="verbose">Defines if the verbose mode must be enabled or not.</param> /// <param name="args">The arguments to pass to the entry point.</param> /// <returns>Returns an awaitable task that can wait the end of the program execution</returns> internal void StartRelease(MarshaledResultSetter callback, bool verbose, params object[] args) { Requires.NotNull(_middleware, nameof(_middleware)); _releaseModeForced = true; _forceStop = false; DebugMode = false; var action = new Action(() => { if (_releaseModeRuntime == null || _compilerResult == null || _compilerResult.BuildErrors != null) { if (State == BaZicInterpreterState.Preparing) { _compilerResult = Build(BaZicCompilerOutputType.DynamicallyLinkedLibrary, string.Empty, string.Empty, string.Empty, false); if (_compilerResult.BuildErrors != null) { ChangeState(this, new UnexpectedException(_compilerResult.BuildErrors)); } else { _assemblySandbox.LoadAssembly(_compilerResult.Assembly, false); _compilerResult.Dispose(); } } } if (State == BaZicInterpreterState.Preparing) { RunningStateManager.SetIsRunningMainFunction(true); _releaseModeRuntime.Run(_programArguments); if (State == BaZicInterpreterState.Running || State == BaZicInterpreterState.Idle) { ProgramResult = _releaseModeRuntime.ProgramResult; RunningStateManager.UpdateState(); } } }); callback.ContinueWith(() => { RunningStateManager.SetIsRunningMainFunction(false); }, () => { RunningStateManager.UpdateState(); }); Start(callback, action, verbose, args); }
/// <summary> /// Starts the interpreter in debug mode. The program will be interpreted and support the beakpoint and step by step debugging. /// </summary> /// <param name="callback">The cross-AppDomain task proxy.</param> /// <param name="verbose">Defines if the verbose mode must be enabled or not.</param> /// <param name="args">The arguments to pass to the entry point.</param> /// <returns>Returns an awaitable task that can wait the end of the program execution</returns> internal void StartDebug(MarshaledResultSetter callback, bool verbose, params object[] args) { Requires.NotNull(_middleware, nameof(_middleware)); if (_releaseModeForced) { throw new UnexpectedException(new Exception(L.BaZic.Runtime.BaZicInterpreter.CannotStartDebugAfterBuild)); } _forceStop = false; DebugMode = true; var action = new Action(() => { LoadAssemblies(); if (State == BaZicInterpreterState.Preparing) { if (ProgramInterpreter == null) { var executionFlowId = RunningStateManager.AddCallStackForUnwaitedMethodInvocation(); RunningStateManager.SetIsRunningMainFunction(true); ProgramInterpreter = new ProgramInterpreter(this, Program, executionFlowId); } ProgramInterpreter.Start(_programArguments); RunningStateManager.WaitUnwaitedMethodInvocation(ProgramInterpreter.ExecutionFlowId); if (State == BaZicInterpreterState.Running || State == BaZicInterpreterState.Idle) { ProgramResult = ProgramInterpreter.ProgramResult; FreePauseModeWaiter(); } } }); callback.ContinueWith(() => { RunningStateManager.SetIsRunningMainFunction(false); RunningStateManager.UpdateState(); }, null); Start(callback, action, verbose, args); }