Ejemplo n.º 1
0
        public void StateChanged(StackState state)
        {
            this.state = state;

            if (OnStateChanged != null)
                OnStateChanged();
        }
Ejemplo n.º 2
0
        public void Empty()
        {
            var stack = new StackState <DummyValue>();

            Assert.Equal(0, stack.Size);
            Assert.Null(stack.Top);
            Assert.Empty(stack.GetAllStackSlots());
        }
Ejemplo n.º 3
0
        public void Pop()
        {
            var stack = new StackState <DummyValue>();
            var value = new DummyValue();

            stack.Push(value);
            Assert.Equal(value, stack.Pop());
        }
Ejemplo n.º 4
0
        public void FirstIndexShouldReferToTop()
        {
            var stack  = new StackState <DummyValue>();
            var values = CreateDummyValues(3);

            stack.Push(values);
            Assert.Same(stack.Top, stack[0]);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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());
        }
Ejemplo n.º 8
0
        public static void GetTypeOf()
        {
            StackState s = RunEnvironment.Instance.LocalStack;

            ScriptObject arg1 = s.GetStackVar(0);

            ScriptObject resoult = ScriptObject.CreateString(arg1.GetTypeof());

            s.SetReturn(resoult);
        }
Ejemplo n.º 9
0
    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);
        }
    }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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--;
            }
        }
Ejemplo n.º 12
0
        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);
        }
    }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
        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;
        }
    }
Ejemplo n.º 17
0
        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;
        }
Ejemplo n.º 18
0
        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;
    }
Ejemplo n.º 20
0
        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));
        }
Ejemplo n.º 21
0
        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());
        }
Ejemplo n.º 22
0
 void StackState()
 {
     mState = CSUI.StackState.Normal;
 }
Ejemplo n.º 23
0
 void StackState()
 {
     mState = CSUI.StackState.Normal;
 }
Ejemplo n.º 24
0
    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);
        }
    }
Ejemplo n.º 25
0
 private void ReadNext()
 {
     _state = _enumerator.MoveNext() ? StackState.HasItem : StackState.Empty;
 }
Ejemplo n.º 26
0
 /// <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);
 }
Ejemplo n.º 27
0
 /// <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());
 }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 /// <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);
 }