public void StateChanged(StackState state) { this.state = state; if (OnStateChanged != null) OnStateChanged(); }
public void Empty() { var stack = new StackState <DummyValue>(); Assert.Equal(0, stack.Size); Assert.Null(stack.Top); Assert.Empty(stack.GetAllStackSlots()); }
public void Pop() { var stack = new StackState <DummyValue>(); var value = new DummyValue(); stack.Push(value); Assert.Equal(value, stack.Pop()); }
public void FirstIndexShouldReferToTop() { var stack = new StackState <DummyValue>(); var values = CreateDummyValues(3); stack.Push(values); Assert.Same(stack.Top, stack[0]); }
private Expression GetStackValue(int offset, DataType accessDataType) { Expression value; if (StackState.TryGetValue(offset, out value)) { if (value == Constant.Invalid) { return(value); } int excess = accessDataType.Size - value.DataType.Size; if (excess == 0) { return(value); } if (excess > 0) { // Example: word32 fetch from SP+04, where SP+04 is a word16 and SP+06 is a word16 int remainder = offset + value.DataType.Size; Expression v2; if (StackState.TryGetValue(remainder, out v2)) { if (v2 == Constant.Invalid || value == Constant.Invalid) { return(Constant.Invalid); } if (v2.DataType.Size + value.DataType.Size != accessDataType.Size) { return(Constant.Invalid); } //$BUGBUG: should evaluate the MkSequence, possibly creating a longer constant if v2 and value are // constant. //$BUGBUG: the sequence below is little-endian!!! return(new MkSequence(accessDataType, v2, value)); } } else { // Example: fetching a byte from SP+04, which previously was assigned an int32. return(new Cast(accessDataType, value)); } } else { int offset2; if (StackState.TryGetLowerBoundKey(offset, out offset2)) { var value2 = StackState[offset2]; if (offset2 + value2.DataType.Size > offset) { return(new Slice(accessDataType, StackState[offset2], ((offset - offset2) * 8))); } } } return(Constant.Invalid); }
public void Push() { var stack = new StackState <DummyValue>(); var value = new DummyValue(); stack.Push(value); Assert.Equal(1, stack.Size); Assert.Equal(value, stack.Top); Assert.Single(stack.GetAllStackSlots()); }
public void PushManyReversed() { var stack = new StackState <DummyValue>(); var values = CreateDummyValues(3); stack.Push(values, reversed: true); Assert.Equal(3, stack.Size); Assert.Equal(values.First(), stack.Top); Assert.Equal(values, stack.GetAllStackSlots()); }
public static void GetTypeOf() { StackState s = RunEnvironment.Instance.LocalStack; ScriptObject arg1 = s.GetStackVar(0); ScriptObject resoult = ScriptObject.CreateString(arg1.GetTypeof()); s.SetReturn(resoult); }
public override void Init(Vector2 position) { Init(position, new NodeWindow_EnumState(), title: "State"); stackState = new StackState(StateEnums.GetInitialState()); foreach (string key in stackState.state.Keys) { AddInput(stackState.state[key].GetType(), key); } }
public void Copy() { var stack = new StackState <DummyValue>(); stack.Push(CreateDummyValues(3)); var copy = stack.Copy(); Assert.Equal(stack.Top, copy.Top); Assert.Equal(stack.Size, copy.Size); Assert.Equal(stack.GetAllStackSlots(), copy.GetAllStackSlots()); }
public void MergeMultiple() { var sources = new[] { new[] { CreateDummyNode(0), CreateDummyNode(1) }, new[] { CreateDummyNode(2), CreateDummyNode(3), }, new[] { CreateDummyNode(4), CreateDummyNode(5), } }; var stack1 = new StackState <SymbolicValue <DummyInstruction> >(); var values1 = new[] { new SymbolicValue <DummyInstruction>(sources[0][0]), new SymbolicValue <DummyInstruction>(sources[1][0]), new SymbolicValue <DummyInstruction>(sources[2][0]), }; stack1.Push(values1); var stack2 = new StackState <SymbolicValue <DummyInstruction> >(); var values2 = new[] { new SymbolicValue <DummyInstruction>(sources[0][1]), new SymbolicValue <DummyInstruction>(sources[1][1]), new SymbolicValue <DummyInstruction>(sources[2][1]), }; stack2.Push(values2); Assert.True(stack1.MergeWith(stack2)); int index = sources.Length - 1; foreach (var slot in stack1.GetAllStackSlots()) { Assert.Equal(new HashSet <DataFlowNode <DummyInstruction> >(sources[index]), slot.GetNodes()); index--; } }
public override bool GetReq(Character character) { StatusEffect status; if (character.StatusEffects.TryGetValue(StatBoostStatus, out status)) { StackState state = status.StatusStates.Get <StackState>(); if (state.Stack > 0) { return(true); } } return(false); }
public override void Init(Vector2 position) { Init(position, new NodeWindow_EnumStateModifier(), title: "Modifier"); AddInput(typeof(bool), "trigger"); AddOutput(typeof(void), "detector"); modifierStackState = new StackState(StateEnums.GetInitialState()); foreach (string key in modifierStackState.state.Keys) { AddOutput(modifierStackState.state[key].GetType(), key); } }
public static void Error() { StackState s = RunEnvironment.Instance.LocalStack; ScriptObject arg1 = s.GetStackVar(0); if (arg1.Type == ScriptInterpreter.RunTime.ValueType.STRING) { string message = arg1.GetString(); throw new ScriptRunTimeException(message); } s.SetReturnVoid(); }
public static void OutPut() { StackState s = RunEnvironment.Instance.LocalStack; //获得第一个参数 ScriptObject arg1 = s.GetStackVar(0); TablePart tablePart = arg1.Value.RefPartHandle.ConverToTablePart(); for (int i = 0; i < tablePart.Count; i++) { Console.Write(tablePart.ArrayPart[i].GetString() + " "); } s.SetReturnVoid(); }
void Update() { if (nodeEditorGO == null) { nodeEditorGO = GameObject.Find(nodeEditorName); } NodeEditor nodeEditor = nodeEditorGO.GetComponent <NodeEditor> (); Node_EnumState nodeEnumState = (Node_EnumState)nodeEditor.nodeLogic.nodes .Find((x) => x.GetType() == typeof(Node_EnumState)); if (nodeEnumState != null) { stackState = nodeEnumState.stackState; } }
public static void SetMetatable() { StackState s = RunEnvironment.Instance.LocalStack; ScriptObject arg1 = s.GetStackVar(0); ScriptObject arg2 = s.GetStackVar(1); if (arg1.Type != ScriptInterpreter.RunTime.ValueType.TABLE || arg2.Type != ScriptInterpreter.RunTime.ValueType.TABLE) { return; } TablePart table = arg1.Value.RefPartHandle.ConverToTablePart(); table.MetaTable = arg2; }
public static void GetMetatable() { StackState s = RunEnvironment.Instance.LocalStack; ScriptObject arg1 = s.GetStackVar(0); if (arg1.Type == ScriptInterpreter.RunTime.ValueType.TABLE) { ScriptObject metaTable = arg1.Value.RefPartHandle.ConverToTablePart().MetaTable; if (metaTable != null) { s.SetReturn(metaTable); } } s.SetReturnVoid(); }
void Update() { TextMesh textMesh = GetComponent <TextMesh> (); string text = ""; StackState stackState = GetComponent <GetEnumStateData> ().stackState; if (stackState != null) { textMesh.color = GetComponent <GetColorData> ().color; foreach (string enumKey in stackState.state.Keys) { Enum e = (Enum)stackState.state [enumKey]; text += e.ToString() + "\n"; } } textMesh.text = text; }
public void MergeStackImbalance() { var stack1 = new StackState <SymbolicValue <DummyInstruction> >(); stack1.Push(new[] { new SymbolicValue <DummyInstruction>(), new SymbolicValue <DummyInstruction>(), }); var stack2 = new StackState <SymbolicValue <DummyInstruction> >(); stack2.Push(new[] { new SymbolicValue <DummyInstruction>(), }); Assert.Throws <StackImbalanceException>(() => stack1.MergeWith(stack2)); }
public void MergeSingle() { var sources = new[] { CreateDummyNode(0), CreateDummyNode(1), }; var stack1 = new StackState <SymbolicValue <DummyInstruction> >(); var value1 = new SymbolicValue <DummyInstruction>(sources[0]); stack1.Push(value1); var stack2 = new StackState <SymbolicValue <DummyInstruction> >(); var value2 = new SymbolicValue <DummyInstruction>(sources[1]); stack2.Push(value2); Assert.True(stack1.MergeWith(stack2)); Assert.Equal(new HashSet <DataFlowNode <DummyInstruction> >(sources), stack1.Top.GetNodes()); }
void StackState() { mState = CSUI.StackState.Normal; }
private static bool CheckMethod(MethodDefinition method) { var branchStates = new Dictionary <Instruction, StackState>(ReferenceEqualityComparer <Instruction> .Instance); if (method.Body.HasExceptionHandlers) { foreach (var handler in method.Body.ExceptionHandlers) { branchStates[handler.TryStart] = StackState.StartOfProtectedBlockStackState; branchStates[handler.HandlerStart] = handler.HandlerType switch { ExceptionHandlerType.Catch => StackState.ExceptionHandlerStackState, ExceptionHandlerType.Filter => StackState.ExceptionHandlerStackState, ExceptionHandlerType.Finally => StackState.FinallyOrFaultHandlerStackState, ExceptionHandlerType.Fault => StackState.FinallyOrFaultHandlerStackState, _ => throw new ArgumentOutOfRangeException() }; if (handler.HandlerType == ExceptionHandlerType.Filter) { branchStates[handler.FilterStart] = StackState.ExceptionHandlerStackState; } } } var state = StackState.InitialStackState; foreach (var instruction in method.Body.Instructions) { if (branchStates.TryGetValue(instruction, out var forwardBranchState)) { if (forwardBranchState.Priority == StackStatePriority.Forced || state.Priority == StackStatePriority.IgnoreWhenFollowedByTargetOfForwardBranch) { state = forwardBranchState; } else { if (state.StackSize != forwardBranchState.StackSize) { return(false); } } } var stackSize = state.StackSize; PushPreProcessor.PopStack(instruction, ref stackSize); if (stackSize < 0) { return(false); } PushPreProcessor.PushStack(instruction, ref stackSize); state = new StackState(stackSize, StackStatePriority.Normal); switch (instruction.OpCode.OperandType) { case OperandType.InlineBrTarget: case OperandType.ShortInlineBrTarget: { if (instruction.Operand is not Instruction operand) { return(false); } if (!UpdateBranchState(operand, state)) { return(false); } break; } case OperandType.InlineSwitch: { if (instruction.Operand is not Instruction[] operands) { return(false); } foreach (var operand in operands) { if (!UpdateBranchState(operand, state)) { return(false); } } break; } } switch (instruction.OpCode.FlowControl) { case FlowControl.Branch: case FlowControl.Throw: case FlowControl.Return: state = StackState.PostUnconditionalBranchStackState; break; } } return(true); bool UpdateBranchState(Instruction targetInstruction, StackState branchState) { if (branchStates.TryGetValue(targetInstruction, out var existingState)) { if (existingState.StackSize != branchState.StackSize) { return(false); } } else { branchStates[targetInstruction] = branchState; } return(true); } }
private void ReadNext() { _state = _enumerator.MoveNext() ? StackState.HasItem : StackState.Empty; }
/// <summary> /// Creates a new empty instance of the <see cref="CilProgramState"/> class. /// </summary> public CilProgramState(IValueFactory valueFactory) { Stack = new StackState<ICliValue>(); Variables = new CilVariableState(valueFactory); }
/// <summary> /// Creates a new empty instance of the <see cref="CilProgramState"/> class. /// </summary> public CilProgramState() { Stack = new StackState <IConcreteValue>(); Variables = new VariableState <IConcreteValue>(new UnknownValue()); }
public StatusMenu(int teamSlot) { int menuWidth = 168; List <MenuChoice> flatChoices = new List <MenuChoice>(); mapIndices = new List <int>(); foreach (int status in ZoneManager.Instance.CurrentMap.Status.Keys) { MapStatus statusInstance = ZoneManager.Instance.CurrentMap.Status[status]; if (!statusInstance.Hidden) { Data.MapStatusData statusData = Data.DataManager.Instance.GetMapStatus(status); mapIndices.Add(status); MenuText statusName = statusName = new MenuText(statusData.GetColoredName(), new Loc(2, 1)); MapCountDownState countDown = statusInstance.StatusStates.GetWithDefault <MapCountDownState>(); if (countDown != null && countDown.Counter > 0) { flatChoices.Add(new MenuElementChoice(() => { }, true, statusName, new MenuText("[" + countDown.Counter + "]", new Loc(menuWidth - 8 * 4, 1), DirH.Right))); } else { flatChoices.Add(new MenuElementChoice(() => { }, true, statusName)); } } } indices = new List <int>(); foreach (int status in DungeonScene.Instance.ActiveTeam.Players[teamSlot].StatusEffects.Keys) { if (Data.DataManager.Instance.GetStatus(status).MenuName) { indices.Add(status); MenuText statusName = null; StackState stack = DungeonScene.Instance.ActiveTeam.Players[teamSlot].StatusEffects[status].StatusStates.GetWithDefault <StackState>(); if (stack != null) { statusName = new MenuText(Data.DataManager.Instance.GetStatus(status).GetColoredName() + (stack.Stack < 0 ? " " : " +") + stack.Stack, new Loc(2, 1)); } else { statusName = new MenuText(Data.DataManager.Instance.GetStatus(status).GetColoredName(), new Loc(2, 1)); } CountDownState countDown = DungeonScene.Instance.ActiveTeam.Players[teamSlot].StatusEffects[status].StatusStates.GetWithDefault <CountDownState>(); if (countDown != null && countDown.Counter > 0) { flatChoices.Add(new MenuElementChoice(() => { }, true, statusName, new MenuText("[" + countDown.Counter + "]", new Loc(menuWidth - 8 * 4, 1), DirH.Right))); } else { flatChoices.Add(new MenuElementChoice(() => { }, true, statusName)); } } } List <MenuChoice[]> statuses = SortIntoPages(flatChoices, SLOTS_PER_PAGE); summaryMenu = new SummaryMenu(Rect.FromPoints(new Loc(16, GraphicsManager.ScreenHeight - 8 - 4 * VERT_SPACE - GraphicsManager.MenuBG.TileHeight * 2), new Loc(GraphicsManager.ScreenWidth - 16, GraphicsManager.ScreenHeight - 8))); Description = new DialogueText("", summaryMenu.Bounds.Start + new Loc(GraphicsManager.MenuBG.TileWidth * 2, GraphicsManager.MenuBG.TileHeight), summaryMenu.Bounds.End.X - GraphicsManager.MenuBG.TileWidth * 4 - summaryMenu.Bounds.X, LINE_SPACE, false); summaryMenu.Elements.Add(Description); Initialize(new Loc(16, 16), menuWidth, Text.FormatKey("MENU_TEAM_STATUS_TITLE"), statuses.ToArray(), 0, 0, SLOTS_PER_PAGE); }
/// <summary> /// Creates a new empty instance of the <see cref="CilProgramState"/> class. /// </summary> public CilProgramState(IValueFactory valueFactory) { _valueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory)); Stack = new StackState <IConcreteValue>(); Variables = new CilVariableState(valueFactory); }