private void String_IndexOf(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
        {
            var str = (string)Stack[0].value;
            var c   = (char)(int)Stack[1].value;

            returnValue = MethodArgStack.Int32(str.IndexOf(c));
        }
Esempio n. 2
0
        public static MethodArgStack OpWithInt64(MethodArgStack arg1, MethodArgStack arg2, Operation op)
        {
            long v1 = (long)arg1.value;
            long v2 = (long)arg2.value;

            switch (op)
            {
            case Operation.Add: return(MethodArgStack.Int64(v1 + v2));

            case Operation.Subtract: return(MethodArgStack.Int64(v1 - v2));

            case Operation.Multiply: return(MethodArgStack.Int64(v1 * v2));

            case Operation.Divide: return(MethodArgStack.Int64(v1 / v2));

            case Operation.Remainder: return(MethodArgStack.Int64(v1 % v2));

            case Operation.Equal: return(MethodArgStack.Int32(v1 == v2 ? 1 : 0));

            case Operation.GreaterThan: return(MethodArgStack.Int32(v1 > v2 ? 1 : 0));

            case Operation.LessThan: return(MethodArgStack.Int32(v1 < v2 ? 1 : 0));

            case Operation.GreaterThanEqual: return(MethodArgStack.Int32(v1 >= v2 ? 1 : 0));

            case Operation.LessThanEqual: return(MethodArgStack.Int32(v1 <= v2 ? 1 : 0));

            case Operation.Negate: return(MethodArgStack.Int64(-v1));

            default: throw new Exception("Invalid operation");
            }
        }
Esempio n. 3
0
        private static MethodArgStack ConvertToInt32(MethodArgStack arg)
        {
            switch (arg.type)
            {
            case StackItemType.Int32: return(arg);

            case StackItemType.Char: return(MethodArgStack.Int32((int)(char)arg.value));

            default: throw new Exception("Unsupported type conversion");
            }
        }
        private void Array_GetLength(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
        {
            var array = Stack[0];

            if (array.type != StackItemType.Array)
            {
                throw new Exception();
            }

            returnValue = MethodArgStack.Int32(Arrays.ArrayRefs[(int)array.value].Length);
        }
Esempio n. 5
0
        private static MethodArgStack OpWithArray(MethodArgStack arg1, MethodArgStack arg2, Operation op)
        {
            object v1 = arg1.value;
            object v2 = arg2.value;

            switch (op)
            {
            case Operation.Equal: return(MethodArgStack.Int32(v1 == v2 ? 1 : 0));

            default: throw new Exception("Invalid operation");
            }
        }
        private void Array_GetLowerBound(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
        {
            var array = Stack[0];
            var bound = Stack[1];

            if (array.type != StackItemType.Array)
            {
                throw new Exception();
            }

            //todo
            returnValue = MethodArgStack.Int32(0);
        }
        private void String_EndsWith(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
        {
            var str = (string)Stack[0].value;
            var cmp = (string)Stack[1].value;

            if (str.EndsWith(cmp))
            {
                returnValue = MethodArgStack.Int32(1);
            }
            else
            {
                returnValue = MethodArgStack.Int32(0);
            }
        }
        private void InternalMethod_String_op_Equality(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
        {
            var    a = Stack[0].value;
            var    b = Stack[1].value;
            string first;
            string second;

            if (a is string)
            {
                first = (string)a;
            }
            else if (a is int)
            {
                first = ((char)(int)a).ToString();
            }
            else
            {
                returnValue = MethodArgStack.Int32(0);
                return;
            }

            if (b is string)
            {
                second = (string)b;
            }
            else if (b is int)
            {
                second = ((char)(int)b).ToString();
            }
            else
            {
                returnValue = MethodArgStack.Int32(0);
                return;
            }

            if (first == second)
            {
                returnValue = MethodArgStack.Int32(1);
            }
            else
            {
                returnValue = MethodArgStack.Int32(0);
            }
        }
 private void Array_GetRank(MethodArgStack[] Stack, ref MethodArgStack returnValue, DotNetMethod method)
 {
     //We only support 1d arrays
     returnValue = MethodArgStack.Int32(1);
 }