public override object Run(RuntimeState state) { object returned = expression.Get(state); state.Returning = state.Scope; return returned; }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new WhileNode( Source, condition.BuildCodeTree(state), body.BuildCodeTree(state)); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new AssignNode( Source, from.BuildCodeTree(state), to.BuildCodeTree(state)); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new OperationNode( Source, Operation.Not, a.BuildCodeTree(state)); }
public override object Get(RuntimeState state, object[] parametersHint) { // when you get a user defined expression, goes here and then into expression.get which builds the code tree then and there, which passes a null method object getMethod = MemberNode.GetMember(obj, "Get", true); return CallNode.Call(state, getMethod, null); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new ConvertNode( Source, obj.BuildCodeTree(state), type.BuildCodeTree(state)); }
public void Parsed(RuntimeState state) { statement.Run(state); if (state.Returning != null) throw new Exception("Top level statement returned"); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new OperationNode( Source, Operation.Is, obj.BuildCodeTree(state), type.BuildCodeTree(state)); }
public void Define(RuntimeState state) { Type type = (Type) ((Expression) expression).Get(state); Pattern pattern = Pattern.PatternForType(type); state.Runtime.Grammar.RootPattern = pattern; state.Runtime.CurrentLexer.RootChanged(); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new OperationNode( Source, Operation.CompareGreater, a.BuildCodeTree(state), b.BuildCodeTree(state)); }
public override object Run(RuntimeState state) { if ((bool) condition.Get(state, null)) return trueBody.Run(state); else if (falseBody != null) return falseBody.Run(state); else return null; }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { ParseGraphNode parseGraph = body.BuildParseGraph(state); if (options.Count == 0) return parseGraph; OptionsNode optionsNode = new OptionsNode(Source, parseGraph); foreach (Option option in options) { string optionKey = option.optionKey.name; object optionValue; if (option.optionValue == null) optionValue = true; else optionValue = option.optionValue.Get(state); switch (optionKey) { case "buildTextNodes": optionsNode.BuildTextNodes.Value = ConvertNode.ToBool(optionValue); break; case "dropPrecedence": optionsNode.DropPrecedence.Value = ConvertNode.ToBool(optionValue); break; case "recursive": { if (ConvertNode.ToBool(optionValue)) optionsNode.RecursionBehaviour.Value = RecursionBehaviour.Recursive; else optionsNode.RecursionBehaviour.Value = RecursionBehaviour.None; } break; case "leftRecursive": optionsNode.RecursionBehaviour.Value = RecursionBehaviour.LeftRecursive; break; case "rightRecursive": optionsNode.RecursionBehaviour.Value = RecursionBehaviour.RightRecursive; break; case "whitespace": optionsNode.Whitespace.Value = Pattern.PatternForType((Type) optionValue); break; case "exclude": optionsNode.Exclude.Value = Pattern.PatternForType((Type) optionValue); break; } } return optionsNode; }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { CodeTreeNode node = obj.BuildCodeTree(state); string name = member.name; node = new MemberNode(Source, node, name); return node; }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { Type type = (Type) name.Get(state); Pattern pattern = Pattern.PatternForType(type); if (pattern != null) return new PatternNode(Source, pattern, false); else return new UserDefinedNode(Source, type); }
public void Define(RuntimeState state) { Pattern a = Pattern.PatternForType((Type) this.a.Get(state)); Pattern b = Pattern.PatternForType((Type) this.b.Get(state)); Precedence.SetPrecedence(a.Precedence, b.Precedence, RelationFromString(relation)); state.Runtime.Grammar.PatternChanged(a); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new TryNode( Source, tryBody.BuildCodeTree(state), catchVariable != null ? catchVariable.BuildCodeTree(state) : null, catchBody.BuildCodeTree(state)); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { return new IfNode( Source, condition.BuildCodeTree(state), trueBody.BuildCodeTree(state), falseBody == null ? null : falseBody.BuildCodeTree(state)); }
private void SendStateChangeEvent(RuntimeState state) { if (OnStateChanged != null) { OnStateChanged(this, new ResourceInstanceEventArgs() { InstanceId = Id, State = state }); } }
private static RuntimeState GetState(Chat chat, int nextEventTime) { RuntimeState state = RuntimeState.Waiting; if (chat != null) { state = nextEventTime > -1 ? RuntimeState.Running : RuntimeState.Suspended; } return(state); }
public override object Get(RuntimeState state, object[] parametersHint) { object child = this.child.Get(state, null); Type type = (Type) this.type.Get(state, null); state.RunningSource = Source; return Convert( child, type); }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { PatternExpression body = (PatternExpression)this.body; string reps = (string)this.reps; return(new RepNode( Source, body.BuildParseGraph(state), Reps.ForName(reps))); }
public override object Run(RuntimeState state) { object exception = this.exception.Get(state); state.RunningSource = Source; if (exception is Exception) throw (Exception) exception; throw new Exception(exception.ToString()); }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { PatternExpression body = (PatternExpression) this.body; string reps = (string) this.reps; return new RepNode( Source, body.BuildParseGraph(state), Reps.ForName(reps)); }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { string text = (string) ((String) this.text).text; text = TextEscape.Unquote(text); if (text.Length == 1) return new CharNode(Source, text[0]); else return new TextNode(Source, text); }
private void FillFinalExceptionReportInfo(Exception ex, out StatusReportType finalReportType, out StepResult lastStepResult, out FailedInfo failedInfo) { if (ex is TaskFailedException) { TaskFailedException failedException = (TaskFailedException)ex; FailedType failedType = failedException.FailedType; this.State = ModuleUtils.GetRuntimeState(failedType); finalReportType = ModuleUtils.GetReportType(failedType); lastStepResult = ModuleUtils.GetStepResult(failedType); failedInfo = new FailedInfo(ex, failedType); _context.LogSession.Print(LogLevel.Info, Index, "Step force failed."); } else if (ex is TestflowAssertException) { this.State = RuntimeState.Failed; finalReportType = StatusReportType.Failed; lastStepResult = StepResult.Failed; failedInfo = new FailedInfo(ex, FailedType.AssertionFailed); _context.LogSession.Print(LogLevel.Error, Index, "Assert exception catched."); } else if (ex is ThreadAbortException) { this.State = RuntimeState.Abort; finalReportType = StatusReportType.Error; lastStepResult = StepResult.Abort; failedInfo = new FailedInfo(ex, FailedType.Abort); _context.LogSession.Print(LogLevel.Warn, Index, $"Sequence {Index} execution aborted"); } else if (ex is TestflowException) { this.State = RuntimeState.Error; finalReportType = StatusReportType.Error; lastStepResult = StepResult.Error; failedInfo = new FailedInfo(ex, FailedType.RuntimeError); _context.LogSession.Print(LogLevel.Error, Index, ex, "Inner exception catched."); } else { this.State = RuntimeState.Error; finalReportType = StatusReportType.Error; lastStepResult = StepResult.Error; failedInfo = new FailedInfo(ex, FailedType.RuntimeError); _context.LogSession.Print(LogLevel.Error, Index, ex, "Runtime exception catched."); } // else if (ex is TargetInvocationException) // { // this.State = RuntimeState.Failed; // finalReportType = StatusReportType.Failed; // lastStepResult = StepResult.Failed; // failedInfo = new FailedInfo(ex.InnerException, FailedType.TargetError); // _context.LogSession.Print(LogLevel.Error, Index, ex, "Invocation exception catched."); // } }
public override object Run(RuntimeState state) { while ((bool) condition.Get(state)) { object returned = body.Run(state); if (state.Returning != null) return returned; } return null; }
public override void Set(RuntimeState state, object v) { object obj = this.obj.Get(state, null); state.RunningSource = Source; SetMember( obj, member, v, true); }
public RuntimeObject Parse(Lexer lexer, RuntimeState runtimeState) { runtimeState.Runtime.ParseTrace.Enter(this, null, lexer.FileName); while (true) { ParserState state = new ParserState(runtimeState); ParseTree tree; if (runtimeState.Runtime.CompileParser) { tree = RootPattern.ParseUsingCompiler(lexer, state); } else { tree = RootPattern.Parse(lexer, state); } RuntimeObject obj = (RuntimeObject)tree.Value; if (!lexer.Finished) { string got; if (lexer.MaxPosition < lexer.Text.Length) { got = TextEscape.Quote(lexer.Text[lexer.MaxPosition]); } else { got = "end of source code"; } throw new ParseException( lexer.SourceAt(lexer.MaxPosition), lexer.ErrorStrings[lexer.MaxPosition], got); } runtimeState.Runtime.ParseTrace.Parsed(lexer.FileName, obj); if (lexer.ChangingRoots) { lexer.Restart(); continue; } runtimeState.Runtime.ParseTrace.Yes(this, null); return(obj); } }
public override object Run(RuntimeState state) { foreach (CodeTreeNode child in children) { object returned = child.Run(state); if (state.Returning != null) return returned; } return null; }
public StatusMessage(string name, RuntimeState state, int id) : base(name, id, MessageType.Status) { this.State = state; this.InterestedSequence = new List <int>(CoreConstants.DefaultRuntimeSize); this.Stacks = new List <CallStack>(CoreConstants.DefaultRuntimeSize); this.SequenceStates = new List <RuntimeState>(CoreConstants.DefaultRuntimeSize); this.Results = new List <StepResult>(CoreConstants.DefaultRuntimeSize); this.FailedInfo = new Dictionary <int, string>(CoreConstants.DefaultRuntimeSize); this.ExecutionTicks = new List <long>(CoreConstants.DefaultRuntimeSize); this.ExecutionTimes = new List <DateTime>(CoreConstants.DefaultRuntimeSize); this.Coroutines = new List <int>(CoreConstants.DefaultRuntimeSize); }
public void RunStateChanged(RuntimeState state) { switch (state) { case RuntimeState.Compiling: cmbOutputSourceType.SelectedIndex = 0; break; case RuntimeState.Running: cmbOutputSourceType.SelectedIndex = 1; break; } }
public override object Run(RuntimeState state) { object exception = this.exception.Get(state); state.RunningSource = Source; if (exception is Exception) { throw (Exception)exception; } throw new Exception(exception.ToString()); }
public override object Get(RuntimeState state, object[] parametersHint) { Type type = (Type) this.type.Get(state, null); object[] parameterValues = new object[parameters.Length]; for (int n = 0; n < parameters.Length; n++) parameterValues[n] = parameters[n].Get(state, null); state.RunningSource = Source; return New(state, type, parameterValues); }
public override object Get(RuntimeState state, object[] parametersHint) { object obj = this.obj.Get(state, null); state.RunningSource = Source; return(GetMember( obj, member, parametersHint, true)); }
public override object Get(RuntimeState state, object[] parametersHint) { object obj = this.obj.Get(state, null); state.RunningSource = Source; return GetMember( obj, member, parametersHint, true); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { CodeTreeNode[] parameterNodes = new CodeTreeNode[parameters.Count]; for (int n = 0; n < parameters.Count; n++) parameterNodes[n] = ((Expression) parameters[n]).BuildCodeTree(state); return new CallNode( Source, callable.BuildCodeTree(state), parameterNodes); }
public override object Get(RuntimeState state, object[] parametersHint) { object[] parameterValues = new object[parameters.Length]; for (int n = 0; n < parameters.Length; n++) parameterValues[n] = parameters[n].Get(state, null); object callable = this.callable.Get(state, parameterValues); state.RunningSource = Source; // For call in parent scope, move into the parent scope // now - reset in finally IScope currentScope = state.Scope; if (parentScope) state.Scope = state.Scope.Parent; object returnValue; bool[] refParams = null; try { returnValue = Call( state, callable, parameterValues, true, out refParams); } finally { // If we didn't return, don't move back into the child scope if (state.Returning == null) state.Scope = currentScope; } if (refParams != null) { for (int n = 0; n < parameters.Length; n++) { if (refParams[n]) parameters[n].Set(state, parameterValues[n]); } } return returnValue; }
public void Define(RuntimeState state) { Module parent = (Module) state.Scope; Module module = new Module(parent, name.name); state.Scope.SetName(name.name, module); state.Scope = module; body.Run(state); state.Scope = parent; if (state.Returning != null) throw new Exception("Statement within a module block returned"); }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { Type type = (Type)name.Get(state); Pattern pattern = Pattern.PatternForType(type); if (pattern != null) { return(new PatternNode(Source, pattern, false)); } else { return(new UserDefinedNode(Source, type)); } }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { List <CodeTreeNode> children = new List <CodeTreeNode>(); foreach (Statement statement in body) { CodeTreeNode tree = statement.BuildCodeTree(state); children.Add(tree); } return(new CodeTree.SeqNode( Source, children)); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { List<CodeTreeNode> children = new List<CodeTreeNode>(); foreach (Statement statement in body) { CodeTreeNode tree = statement.BuildCodeTree(state); children.Add(tree); } return new CodeTree.SeqNode( Source, children); }
public override object Run(RuntimeState state) { while ((bool)condition.Get(state)) { object returned = body.Run(state); if (state.Returning != null) { return(returned); } } return(null); }
public override object Run(RuntimeState state) { foreach (CodeTreeNode child in children) { object returned = child.Run(state); if (state.Returning != null) { return(returned); } } return(null); }
static void RunProgram(string code, decimal input, StringBuilder stringBuilder) { var program = Parser.Parser.Parse(Tokenizer.Tokenizer.Tokenize(code)); var runTimeState = new RuntimeState(1); runTimeState.Inputs[0] = input; int pc = 0; var callTree = new CallTree(program, ref pc); while (!callTree.Tick(runTimeState, program.Constants, stringBuilder)) { } }
protected virtual void ChangeState(RuntimeState state, bool copyLogs = false) { var instanceId = GlobalDataStore.ResourceInstanceId; TraceFactory.Logger.Debug("{0} - change state to: {1}".FormatWith(instanceId, state)); TraceFactory.Logger.Debug("Machine: {0}".FormatWith(GlobalDataStore.Manifest.HostMachine)); SessionProxyBackendConnection.ChangeResourceState(state); if (WorkerStateChanged != null) { WorkerStateChanged(this, new ResourceEventArgs(instanceId, state, copyLogs)); } }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { string text = (string)((String)this.text).text; text = TextEscape.Unquote(text); if (text.Length == 1) { return(new CharNode(Source, text[0])); } else { return(new TextNode(Source, text)); } }
public override object Get(RuntimeState state, object[] parametersHint) { Type type = (Type)this.type.Get(state, null); object[] parameterValues = new object[parameters.Length]; for (int n = 0; n < parameters.Length; n++) { parameterValues[n] = parameters[n].Get(state, null); } state.RunningSource = Source; return(New(state, type, parameterValues)); }
public override CodeTreeNode BuildCodeTree(RuntimeState state) { CodeTreeNode[] parameterNodes = new CodeTreeNode[parameters.Count]; for (int n = 0; n < parameters.Count; n++) { parameterNodes[n] = ((Expression)parameters[n]).BuildCodeTree(state); } return(new NewNode( Source, type.BuildCodeTree(state), parameterNodes)); }
public override object Run(RuntimeState state) { if ((bool)condition.Get(state, null)) { return(trueBody.Run(state)); } else if (falseBody != null) { return(falseBody.Run(state)); } else { return(null); } }
private void CompileWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { currentWorker = null; state = RuntimeState.Stop; RunStateChanged?.Invoke(state); BackgroundWorker runWorker = new BackgroundWorker(); runWorker.DoWork += RunWorker_DoWork; runWorker.RunWorkerCompleted += RunWorker_RunWorkerCompleted; runWorker.RunWorkerAsync(); currentWorker = runWorker; state = RuntimeState.Running; RunStateChanged?.Invoke(state); }
public override IAstNode VisitTopLevelExpression(TopLevelExpressionContext context) { BeginFunctionDefinition( ); var sig = new Prototype(context.GetSourceSpan( ), RuntimeState.GenerateAnonymousName( ), true); var body = ( IExpression )context.expression( ).Accept(this); var retVal = new FunctionDefinition(context.GetSourceSpan( ), sig, body, true); // only add valid definitions to the runtime state. var errors = retVal.CollectErrors( ); if (errors.Count == 0) { RuntimeState.FunctionDefinitions.AddOrReplaceItem(retVal); } return(retVal); }
public override ParseGraphNode BuildParseGraph(RuntimeState state) { string min = (string)((Base.String) this.min).text; string max = (string)((Base.String) this.max).text; min = TextEscape.Unquote(min); max = TextEscape.Unquote(max); if ((min.Length != 1) || (max.Length != 1)) { throw new Exception(); } CharRange range = new CharRange(min[0], max[0]); return(new CharNode(Source, range)); }
// upon successful parse of a function definition check if it is a user defined operator // and update the RuntimeState accordingly, if it is. public override void ExitFunctionDefinition([NotNull] KaleidoscopeParser.FunctionDefinitionContext context) { switch (context.Signature) { case KaleidoscopeParser.UnaryPrototypeContext unaryProto: RuntimeState.TryAddOperator(unaryProto.OpToken, OperatorKind.PreFix, 0); break; case KaleidoscopeParser.BinaryPrototypeContext binaryProto: RuntimeState.TryAddOperator(binaryProto.OpToken, OperatorKind.InfixLeftAssociative, binaryProto.Precedence); break; default: base.ExitFunctionDefinition(context); break; } }
public void Define(RuntimeState state) { Module parent = (Module)state.Scope; Module module = new Module(parent, name.name); state.Scope.SetName(name.name, module); state.Scope = module; body.Run(state); state.Scope = parent; if (state.Returning != null) { throw new Exception("Statement within a module block returned"); } }
private void SetState(RuntimeState newState) { var isMainThread = mainThread.Equals(Thread.CurrentThread); if (!isMainThread) { stateChanges.Add(newState); return; } switch (newState) { case RuntimeState.Disconnected: setDisconnectedMaterial(); break; case RuntimeState.Disconnecting: setDisconnectedMaterial(); break; case RuntimeState.Connected: break; case RuntimeState.WaitFirstBuffer: setDisconnectedMaterial(); break; case RuntimeState.Connecting: setDisconnectedMaterial(); break; case RuntimeState.Error: setDisconnectedMaterial(); break; default: break; } state = newState; if (onStateChanged_event != null) { onStateChanged_event(state); } }
public override object Run(RuntimeState state) { try { return(tryBody.Run(state)); } catch (Exception e) { state.RunningSource = Source; /* * If you use reflection to invoke a method, any exceptions * thrown inside the invoke will be wrapped in a * TargetInvocationException. This is a problem because then * you might filter for certain types of exception and miss * the wrapped instances. Also, the user doesn't care and * shouldn't know that reflection was used to invoke a * method. Might cause problems with expected behaviour if * a user explicitly uses invoke or throws a * TargetInvocationException. * * Unwrap TargetInvocationException instances in all user * type blocks. */ while (true) { TargetInvocationException wrapper = e as TargetInvocationException; if (wrapper == null) { break; } e = wrapper.InnerException; } if (catchVariable != null) { catchVariable.Set(state, e); } return(catchBody.Run(state)); } }
public void StopStateHandle(DateTime time, RuntimeState state, string failedInfo) { this.CurrentTime = time; this.EndTime = time; if (DateTime.MaxValue != _blockedStart) { BlockedTime += time - _blockedStart; _blockedStart = DateTime.MaxValue; } this.ElapsedTime = EndTime - StartTime - BlockedTime; this.State = state; _sequenceTestResult.ElapsedTime = ElapsedTime.TotalMilliseconds; _sequenceTestResult.ResultState = State; _sequenceTestResult.EndTime = EndTime; _sequenceTestResult.FailedInfo.Message = failedInfo; }
public void StopStateHandle(DateTime time, RuntimeState state, string failedInfo) { this.CurrentTime = time; this.EndTime = time; if (DateTime.MaxValue != _blockedStart) { BlockedTime += time - _blockedStart; _blockedStart = DateTime.MaxValue; } this.ElapsedTime = EndTime - StartTime - BlockedTime; this.State = state; _sequenceTestResult.ElapsedTime = ElapsedTime.TotalMilliseconds; _sequenceTestResult.ResultState = State; _sequenceTestResult.EndTime = EndTime; _sequenceTestResult.FailedInfo = new FailedInfo(failedInfo); _stateManageContext.DatabaseProxy.UpdateData(_sequenceResultData); }
public void ParseRuntimeSettings() { Assert.AreEqual(RuntimeStateSetting.Enabled, RuntimeState.Parse("")); Assert.AreEqual(RuntimeStateSetting.Enabled, RuntimeState.Parse(null)); Assert.AreEqual(RuntimeStateSetting.Enabled, RuntimeState.Parse("true")); Assert.AreEqual(RuntimeStateSetting.Enabled, RuntimeState.Parse("True")); Assert.AreEqual(RuntimeStateSetting.Enabled, RuntimeState.Parse("TRUE")); Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("false")); Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("False")); Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("FALSE")); Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("Disabled")); Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("Gplf")); // This is "True" on qwerty using colemak Assert.AreEqual(RuntimeStateSetting.Disabled, RuntimeState.Parse("Tairf")); // This is "False" on qwerty using colemak Assert.AreEqual(RuntimeStateSetting.Read, RuntimeState.Parse("Read")); Assert.AreEqual(RuntimeStateSetting.ReadWrite, RuntimeState.Parse("ReadWrite")); }