Beispiel #1
0
        public static void InStrReverse(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopStr();
            var item1 = data.RuntimeStack.PopStr();

            data.RuntimeStack.Push(item1.LastIndexOf(item2));
        }
Beispiel #2
0
        public static void Concatenate(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopStr();
            var item1 = data.RuntimeStack.PopStr();

            data.RuntimeStack.Push(String.Concat(item1, item2));
        }
Beispiel #3
0
 public static void ArrayAppendItem(OpCodeData data)
 {
     var array = data.RuntimeStack.PopArray();
     var item = data.RuntimeStack.Pop();
     array.Add(item);
     data.RuntimeStack.Push(array);
 }
Beispiel #4
0
        public static void StackItemLReverse(OpCodeData data)
        {
            var count = data.RuntimeStack.PopInt();
            if (count == 0) return;
            if (count < 0)
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);

            // Take n items
            var popped = new List<MuftecStackItem>();

            for (var i = 0; i < count; i++)
            {
                var item = data.RuntimeStack.Pop();
                popped.Add(item);
            }

            // Push in reverse order
            foreach (var item in popped)
            {
                data.RuntimeStack.Push(item);
            }

            // Re-add count
            data.RuntimeStack.Push(count);
        }
Beispiel #5
0
        public static void ArrayCompare(OpCodeData data)
        {
            var array2 = data.RuntimeStack.PopArray();
            var array1 = data.RuntimeStack.PopArray();

            data.RuntimeStack.Push(array1.SequenceEqual(array2));
        }
Beispiel #6
0
        public static void Atangent2(OpCodeData data)
        {
            var fx = data.RuntimeStack.PopFloat();
            var fy = data.RuntimeStack.PopFloat();

            data.RuntimeStack.Push(System.Math.Atan2(fy, fx));
        }
Beispiel #7
0
        public static void ArrayDeleteItem(OpCodeData data)
        {
            var index = data.RuntimeStack.PopInt();
            var array = data.RuntimeStack.PopArray();

            array.RemoveAt(index);
            data.RuntimeStack.Push(array);
        }
Beispiel #8
0
        public static void ArrayDeleteRange(OpCodeData data)
        {
            var index2 = data.RuntimeStack.PopInt();
            var index1 = data.RuntimeStack.PopInt();
            var array = data.RuntimeStack.PopArray().ToList();

            array.RemoveRange(index1, index2 - index1 + 1);
            data.RuntimeStack.Push(array);
        }
Beispiel #9
0
        public void ReadLineTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            InputOutput.ReadLine(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(MuftecStackItem.Null);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #10
0
        public void PrintTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push("Sample string");
            InputOutput.Print(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #11
0
        public static void StackItemDupN(OpCodeData data)
        {
            var count = data.RuntimeStack.PopInt();
            if (count == 0) return;
            if (count < 0)
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);

            var topItems = data.RuntimeStack.Take(count).Reverse().ToList();
            foreach (var item in topItems)
            {
                data.RuntimeStack.Push(item);
            }
        }
Beispiel #12
0
        public static void Explode(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopStr();
            var item1 = data.RuntimeStack.PopStr();
            var exploded = item1.Split(new[] { item2 }, StringSplitOptions.None);

            data.RuntimeStack.Push(exploded.Length);

            foreach (var s in exploded)
            {
                data.RuntimeStack.Push(s);
            }
        }
Beispiel #13
0
        public void ConcatenateTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push("test");
            runtimeStack.Push("string");
            Strings.Concatenate(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push("teststring");

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #14
0
        public void StackDepthTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push("Alfredo");
            runtimeStack.Push(1.99);
            StackOperations.StackDepth(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push("Alfredo");
            runtimeStackExpected.Push(1.99);
            runtimeStackExpected.Push(2);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #15
0
        public void ArrayAppendItemTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(6);
            Arrays.ArrayStart(data);
            runtimeStack.Push(5);
            Arrays.ArrayEnd(data);
            Arrays.ArrayMake(data);
            Arrays.ArrayAppendItem(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(new MuftecList { 5, 6 });

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #16
0
        public void EqualToTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(5);
            runtimeStack.Push(10);
            Logic.EqualTo(data);
            runtimeStack.Push(5);
            runtimeStack.Push(5);
            Logic.EqualTo(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(0);
            runtimeStackExpected.Push(1);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #17
0
        public void FloatToIntTruncateTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(2f);
            Conversion.FloatToIntTruncate(data);
            runtimeStack.Push(2.5);
            Conversion.FloatToIntTruncate(data);
            runtimeStack.Push(-10.5);
            Conversion.FloatToIntTruncate(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(2);
            runtimeStackExpected.Push(2);
            runtimeStackExpected.Push(-10);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #18
0
        public static void AbsoluteVal(OpCodeData data)
        {
            var item1 = data.RuntimeStack.PopNumber();
            MuftecStackItem result;

            if (item1.Type == MuftecType.Float)
            {
                result = System.Math.Abs(item1.AsDouble());
            }
            else if (item1.Type == MuftecType.Integer)
            {
                result = System.Math.Abs((int)item1.Item);
            }
            else
            {
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);
            }

            data.RuntimeStack.Push(result);
        }
Beispiel #19
0
        public void AsineTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(-5d);
            Float.Acosine(data);
            runtimeStack.Push(0d);
            Float.Acosine(data);
            runtimeStack.Push(0.5d);
            Float.Acosine(data);
            runtimeStack.Push(5d);
            Float.Acosine(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(System.Math.Acos(-5d));
            runtimeStackExpected.Push(System.Math.Acos(0d));
            runtimeStackExpected.Push(System.Math.Acos(0.5d));
            runtimeStackExpected.Push(System.Math.Acos(5d));

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #20
0
        public void AbsoluteValTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(-2);
            Math.AbsoluteVal(data);
            runtimeStack.Push(5);
            Math.AbsoluteVal(data);
            runtimeStack.Push(5f);
            Math.AbsoluteVal(data);
            runtimeStack.Push(-5.8);
            Math.AbsoluteVal(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(2);
            runtimeStackExpected.Push(5);
            runtimeStackExpected.Push(5f);
            runtimeStackExpected.Push(5.8);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #21
0
        public void AddTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(3);
            runtimeStack.Push(9);
            Math.Add(data);
            runtimeStack.Push(3.1);
            runtimeStack.Push(9);
            Math.Add(data);
            runtimeStack.Push(3.25);
            runtimeStack.Push(9.25);
            Math.Add(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(12);
            runtimeStackExpected.Push(12.1);
            runtimeStackExpected.Push(12.5);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #22
0
        public static void EqualTo(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopNumber();
            var item1 = data.RuntimeStack.PopNumber();
            MuftecStackItem result;

            if ((item1.Type == MuftecType.Float) || (item2.Type == MuftecType.Float))
            {
                result = System.Math.Abs(item1.AsDouble() - item2.AsDouble()) < 0.00000001;
            }
            else if ((item1.Type == MuftecType.Integer) && (item2.Type == MuftecType.Integer))
            {
                result = (int)item1.Item == (int)item2.Item;
            }
            else
            {
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);
            }

            data.RuntimeStack.Push(result);
        }
Beispiel #23
0
        public void ArrayCompareTest()
        {
            var runtimeStack = new Stack<MuftecStackItem>();
            var data = new OpCodeData(runtimeStack);
            runtimeStack.Push(new MuftecList { 5, "test", 0.3 });
            runtimeStack.Push(new MuftecList { 5, "test", 0.3 });
            Arrays.ArrayCompare(data);
            runtimeStack.Push(new MuftecList { 5, "test" });
            runtimeStack.Push(new MuftecList { 3 });
            Arrays.ArrayCompare(data);
            runtimeStack.Push(new MuftecList { 3.3 });
            runtimeStack.Push(new MuftecList { 3.30003 });
            Arrays.ArrayCompare(data);

            var runtimeStackExpected = new Stack<MuftecStackItem>();
            runtimeStackExpected.Push(true);
            runtimeStackExpected.Push(false);
            runtimeStackExpected.Push(false);

            TestShared.CompareStacks(runtimeStack, runtimeStackExpected);
        }
Beispiel #24
0
        public static void GreaterThanOrEqualTo(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopNumber();
            var item1 = data.RuntimeStack.PopNumber();
            MuftecStackItem result;

            if ((item1.Type == MuftecType.Float) || (item2.Type == MuftecType.Float))
            {
                result = item1.AsDouble() >= item2.AsDouble();
            }
            else if ((item1.Type == MuftecType.Integer) && (item2.Type == MuftecType.Integer))
            {
                result = (int)item1.Item >= (int)item2.Item;
            }
            else
            {
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);
            }

            data.RuntimeStack.Push(result);
        }
Beispiel #25
0
        public static void ArrayCut(OpCodeData data)
        {
            var index = data.RuntimeStack.PopInt();
            var array = data.RuntimeStack.Pop(MuftecType.List, MuftecType.Dictionary);

            if (array.Type == MuftecType.List)
            {
                var list = (MuftecList)array.Item;
                data.RuntimeStack.Push(list.Take(index).ToList());
                data.RuntimeStack.Push(list.Skip(index).ToList());
            }
            else if (array.Type == MuftecType.Dictionary)
            {
                var list = (MuftecDict)array.Item;
                data.RuntimeStack.Push(list.Take(index).ToDictionary(p => p.Key, p => p.Value));
                data.RuntimeStack.Push(list.Skip(index).ToDictionary(p => p.Key, p => p.Value));
            }
            else
            {
                throw new MuftecInvalidStackItemTypeException(data.RuntimeStack);
            }
        }
Beispiel #26
0
        public static void Split(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopStr();
            var item1 = data.RuntimeStack.PopStr();

            var splitPos = item1.IndexOf(item2);

            data.RuntimeStack.Push(item1.Substring(0, splitPos));
            data.RuntimeStack.Push(item1.Substring(splitPos));
        }
Beispiel #27
0
        public static void StrMid(OpCodeData data)
        {
            var item3 = data.RuntimeStack.PopInt();
            var item2 = data.RuntimeStack.PopInt();
            var item1 = data.RuntimeStack.PopStr();

            data.RuntimeStack.Push(item1.Substring(item2 + 1, item3));
        }
Beispiel #28
0
        public static void Substitute(OpCodeData data)
        {
            var item3 = data.RuntimeStack.PopStr();
            var item2 = data.RuntimeStack.PopStr();
            var item1 = data.RuntimeStack.PopStr();

            data.RuntimeStack.Push(item1.Replace(item3, item2));
        }
Beispiel #29
0
 public static void StrToUpper(OpCodeData data)
 {
     var item1 = data.RuntimeStack.PopStr();
     data.RuntimeStack.Push(item1.ToUpper());
 }
Beispiel #30
0
        public static void StrRight(OpCodeData data)
        {
            var item2 = data.RuntimeStack.PopInt();
            var item1 = data.RuntimeStack.PopStr();

            data.RuntimeStack.Push(item1.Substring(item1.Length - item2, item2));
        }