Exemplo n.º 1
0
        private AType Process(AType shape, AType input, ref int pos, int shapePos)
        {
            if (!shape.IsArray)
            {
                return(ProcessToVector(shape, input, ref pos));
            }

            AType result    = AArray.Create(input.Type);
            int   itemCount = shape[shapePos].asInteger;

            for (int i = 0; i < itemCount; i++)
            {
                if (shapePos + 1 >= shape.Length)
                {
                    return(ProcessToVector(shape[shapePos], input, ref pos));
                }
                else
                {
                    result.AddWithNoUpdate(Process(shape, input, ref pos, shapePos + 1));
                }
            }

            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="indexers">List containing all of the indexes</param>
        /// <param name="indexpos"></param>
        /// <param name="currentIdx">Array containing the current indexes</param>
        /// <returns></returns>
        public static AType VectorIndexing(this AType input, List <AType> indexers, int indexpos, AType currentIdx, bool isAssign, bool isMemoryMapped)
        {
            if (currentIdx.Length == 0)
            {
                // A Null item found!, select all of the current items
                for (int i = 0; i < input.Length; i++)
                {
                    currentIdx.Add(AInteger.Create(i));
                }
            }

            // Create an array for the results
            AType result = AArray.Create(input.Type);

            // Iterate over the indexes
            foreach (AType index in currentIdx)
            {
                AType item =
                    index.IsArray ?
                    input.VectorIndexing(indexers, indexpos, index, isAssign, isMemoryMapped) :
                    input.SimpleIndex(indexers, indexpos, index, isAssign, isMemoryMapped);

                result.AddWithNoUpdate(item);
            }

            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute padding on all items and make the result character array.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="arguments">Instead of class variables.</param>
        /// <returns></returns>
        private AType FormatArray(List <int> shape, FormatInformation arguments)
        {
            AType result = AArray.Create(ATypes.AChar);
            int   rank   = shape.Count;

            if (rank > 0)
            {
                for (int i = 0; i < shape[0]; i++)
                {
                    if (rank > 1)
                    {
                        result.AddWithNoUpdate(FormatArray(shape.GetRange(1, rank - 1), arguments));
                    }
                    else
                    {
                        result.AddRangeWithNoUpdate(FormatScalar(arguments));
                    }
                }

                result.UpdateInfo();
            }
            else
            {
                result.AddRange(FormatScalar(arguments));
            }

            return(result);
        }
Exemplo n.º 4
0
        private AType GenerateVector(int itemCount)
        {
            AType vector = AArray.Create(ATypes.AInteger);

            for (int i = 0; i < itemCount; i++)
            {
                vector.AddWithNoUpdate(AInteger.Create(i));
            }
            vector.UpdateInfo();
            return(vector);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an AArray from the input arguments.
        /// </summary>
        /// <param name="arguments">The array containing the ATypes, in REVERSE order!</param>
        /// <returns></returns>
        public static AType BuildArray(AType[] arguments)
        {
            AType result = AArray.Create(ATypes.AArray);

            for (int i = arguments.Length - 1; i >= 0; i--)
            {
                result.AddWithNoUpdate(arguments[i]);
            }
            result.UpdateInfo();

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an AArray with type AInteger from the input list of integers
        /// </summary>
        /// <param name="list">List of Integers</param>
        /// <returns></returns>
        public static AType ToAArray(this IEnumerable <int> list)
        {
            AType array = AArray.Create(ATypes.AInteger);

            foreach (int item in list)
            {
                array.AddWithNoUpdate(AInteger.Create(item));
            }
            array.UpdateInfo();

            return(array);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a strand from the input arguments. Boxes each element.
        /// </summary>
        /// <param name="arguments">The array containing the strand arguments, in REVERSE order!</param>
        /// <returns>AArray with ABox elements</returns>
        public static AType BuildStrand(AType[] arguments)
        {
            AType result = AArray.Create(ATypes.ABox);

            for (int i = arguments.Length - 1; i >= 0; i--)
            {
                //There is no environment now!
                result.AddWithNoUpdate(MonadicFunctionInstance.Enclose.Execute(arguments[i]));
            }
            result.UpdateInfo();

            return(result);
        }
Exemplo n.º 8
0
        public static AType Export(Aplus environment, AType argument)
        {
            byte[] exportedMessage = SysExp.Instance.Format(argument);
            AType  result          = AArray.Create(ATypes.AChar);

            foreach (byte charcter in exportedMessage)
            {
                result.AddWithNoUpdate(AChar.Create((char)charcter));
            }

            result.UpdateInfo();

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an AArray from the input string with AChar type or
        /// a simple AChar if the input is of length 1
        /// </summary>
        /// <param name="text">input string</param>
        /// <returns>AArray of AChars or a single AChar</returns>
        public static AType BuildString(string text)
        {
            if (text.Length == 1)
            {
                return(AChar.Create(text[0]));
            }

            AType characterArray = AArray.Create(ATypes.AChar);

            foreach (char ch in text)
            {
                characterArray.Add(AChar.Create(ch));
            }
            characterArray.UpdateInfo();

            return(characterArray);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate a vector with the length of the specified shape
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="input">Vector of input elements</param>
        /// <param name="pos"></param>
        /// <returns></returns>
        private AType ProcessToVector(AType shape, AType input, ref int pos)
        {
            AType result    = AArray.Create(input.Type);
            int   itemCount = shape.asInteger;

            for (int i = 0; i < itemCount; i++)
            {
                result.AddWithNoUpdate(input[pos++].Clone());
                if (pos >= input.Length)
                {
                    pos = 0;
                }
            }

            result.UpdateInfo();
            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argument"></param>
        /// <param name="formaters"></param>
        /// <returns></returns>
        private static AType FormatArray(AType argument, List <FormatInfo> formaters)
        {
            AType result = AArray.Create(ATypes.AChar);

            AType[] formatted;

            if (argument.IsArray)
            {
                for (int i = 0; i < argument.Length; i++)
                {
                    if (argument.Rank > 1)
                    {
                        result.AddWithNoUpdate(FormatArray(argument[i], formaters));
                    }
                    else
                    {
                        FormatInfo format = formaters[formaters.Count > 1 ? i : 0];
                        formatted = argument.IsNumber
                            ? FormatNumber(argument[i], format)
                            : FormatSymbol(argument[i], format);

                        if (formatted != null)
                        {
                            result.AddRangeWithNoUpdate(formatted);
                        }
                    }
                }

                result.UpdateInfo();
            }
            else
            {
                FormatInfo format = formaters[0];
                formatted = argument.IsNumber
                    ? FormatNumber(argument, format)
                    : FormatSymbol(argument, format);

                if (formatted != null)
                {
                    result.AddRange(formatted);
                }
            }

            return(result);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Convert items to integers.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        private static AType ConvertToInteger(AType argument)
        {
            if (argument.Rank > 0)
            {
                AType result = AArray.Create(ATypes.AArray);

                foreach (AType item in argument)
                {
                    result.AddWithNoUpdate(ConvertToInteger(item));
                }

                result.UpdateInfo();
                result.Type = ATypes.AInteger;

                return(result);
            }
            else
            {
                return(AInteger.Create(argument.asInteger));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// If the cell rank > 1, first step is check the shape of actual cell equal to determined cell shape.
        /// If different we throw Length error. The second step is classify the cell.
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="arguments">Instead of class variables.</param>
        /// <returns></returns>
        private AType MultipleItemsWalking(AType cell, FindArguments arguments)
        {
            if (arguments.CellShape.Count == cell.Shape.Count)
            {
                if (!arguments.CellShape.SequenceEqual(cell.Shape))
                {
                    throw new Error.Length(LengthErrorText);
                }
                return(Classify(cell, arguments));
            }
            else
            {
                AType result = AArray.Create(ATypes.AInteger);

                foreach (AType item in cell)
                {
                    result.AddWithNoUpdate(MultipleItemsWalking(item, arguments));
                }
                result.UpdateInfo();

                return(result);
            }
        }