/// <summary>
        /// Partition count.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        private AType Compute(AType argument, byte[] vector)
        {
            AType result = AArray.Create(ATypes.AArray);

            // If argument is () than result is ().
            result.Type = (argument.Type == ATypes.ANull) ? ATypes.ANull : ATypes.AInteger;

            if (vector.Length > 0)
            {
                int length = 1;
                int counter = 0;

                for (int i = 1; i < vector.Length; i++)
                {
                    counter++;

                    if (vector[i] == 1)
                    {
                        length++;
                        result.AddWithNoUpdate(AInteger.Create(counter));
                        counter = 0;
                    }
                }

                counter++;
                result.AddWithNoUpdate(AInteger.Create(counter));

                result.Length = length;
                result.Shape = new List<int>() { length };
                result.Rank = 1;
            }

            return result;
        }
Exemple #2
0
        /// <summary>
        /// Prepare the left side and determine the cellshape.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        private CalculationArguments PrepareVariables(AType left, AType right)
        {
            // Error if the arguments:
            //  - are boxes
            //  - or not of the same type and:
            //    - not numbers
            //    - or one of them is a Null
            if (left.IsBox || right.IsBox ||
                (left.Type != right.Type &&
                !(Utils.DifferentNumberType(left, right) || left.Type == ATypes.ANull || right.Type == ATypes.ANull)
            ))
            {
                throw new Error.Type(TypeErrorText);
            }

            CalculationArguments arguments = new CalculationArguments()
            {
                Interval = left,
                CellShape = (left.Rank > 1 && left.Length > 0) ? left[0].Shape : new List<int>()
            };

            if (right.Rank < arguments.CellShape.Count)
            {
                throw new Error.Rank(RankErrorText);
            }

            return arguments;
        }
Exemple #3
0
        private List<AType> GetIndexes(AType left, AType right)
        {
            List<AType> indexes = new List<AType>();

            if (left.IsBox)
            {
                //Ravel left side box array, if rank > 1.
                AType raveled = left.Rank > 1 ? MonadicFunctionInstance.Ravel.Execute(left) : left;

                //length of the left argument greater than the rank of the right argument, raise Rank error.
                if (raveled.Length > right.Rank)
                {
                    throw new Error.Rank(RankErrorText);
                }

                //Nested case: x[0 pick y; 1 pick y; ...; (-1 + #y) pick y]
                for (int i = 0; i < raveled.Length; i++)
                {
                    indexes.Add(DyadicFunctionInstance.Pick.Execute(raveled, AInteger.Create(i)));
                }
            }
            else
            {
                //Simple case: x[y;...;]
                indexes.Add(left);
            }

            return indexes;
        }
Exemple #4
0
        public override AType Execute(AType argument, Aplus environment = null)
        {
            SetVariables(argument);

            AType result;

            //First dimension equal with zero case (as Null).
            if (argument.Length == 0)
            {
                result = argument.Clone();
                result.Type = this.type;
            }
            else
            {
                //Accepted types are float and integer.
                if (argument.Type != ATypes.AFloat && argument.Type != ATypes.AInteger)
                {
                    throw new Error.Type(TypeErrorText);
                }

                result = argument.IsArray ? ScanAlgorithm(argument) : PreProcess(argument);
            }

            return result;
        }
Exemple #5
0
 /// <summary>
 /// Checks if the division's arguments are 0
 /// </summary>
 private void CheckZeroPerZero(AType right, AType left)
 {
     if (right.asFloat == 0.0 && left.asFloat == 0.0)
     {
         throw new Error.Domain(DomainErrorText);
     }
 }
Exemple #6
0
        private int GetDropCounter(AType element)
        {
            if (element.Type == ATypes.AFloat || element.Type == ATypes.AInteger)
            {
                AType scalar;

                // Get the first scalar value with length check on
                if (!element.TryFirstScalar(out scalar, true))
                {
                    throw new Error.Nonce(this.NonceErrorText);
                }

                int dropCounter;
                // Check if the scalar is a whole number and set the drop counter
                if (!scalar.ConvertToRestrictedWholeNumber(out dropCounter))
                {
                    throw new Error.Type(this.TypeErrorText);
                }

                return dropCounter;
            }
            else if (element.Type == ATypes.ANull)
            {
                throw new Error.Nonce(this.NonceErrorText);
            }
            else
            {
                throw new Error.Type(this.TypeErrorText);
            }
        }
Exemple #7
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            // First we check if one side is an ANull
            if (right.Type == ATypes.ANull)
            {
                return AArray.Create(left.Type, left.Clone());
            }
            else if (left.Type == ATypes.ANull)
            {
                return AArray.Create(right.Type, right.Clone());
            }

            // Type check
            if(!Utils.IsSameGeneralType(left, right))
            {
                throw new Error.Type(this.TypeErrorText);
            }

            AType result = CreateResult(right, left);

            // Convert to float if one of the arguments is an AFloat and the other is an AInteger
            if (Utils.DifferentNumberType(left, right))
            {
                result.ConvertToFloat();
            }

            return result;
        }
Exemple #8
0
        /// <summary>
        /// Convert Character constant array to symbol array.
        /// </summary>
        /// <param name="argument"></param>
        /// <returns></returns>
        private AType Compute(AType argument)
        {
            //If argument is character constant or character constant vector then we convert it symbol,
            //and cut blanks from end.
            if (argument.Rank <= 1)
            {
                return ASymbol.Create(argument.ToString().TrimEnd());
            }
            else
            {
                AType result = AArray.Create(ATypes.ASymbol);

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

                result.Length = argument.Length;
                result.Shape = new List<int>();
                result.Shape.AddRange(argument.Shape.GetRange(0, argument.Shape.Count - 1));
                result.Rank = argument.Rank - 1;

                return result;
            }
        }
        internal static AType StringSearchandReplace(Aplus environment, AType replaceWith, AType replaceWhat, AType replaceIn)
        {
            if (replaceIn.Type != ATypes.AChar || replaceWhat.Type != ATypes.AChar || replaceWith.Type != ATypes.AChar)
            {
                throw new Error.Type("_ssr");
            }

            string withString = Monadic.MonadicFunctionInstance.Ravel.Execute(replaceWith, environment).ToString();
            string whatString = Monadic.MonadicFunctionInstance.Ravel.Execute(replaceWhat, environment).ToString();
            AType argument = (withString.Length == whatString.Length)
                ? replaceIn.Clone() : Monadic.MonadicFunctionInstance.Ravel.Execute(replaceIn, environment);

            Queue<string> rows = new Queue<string>();
            ExtractRows(argument, rows);

            Queue<string> replacedRows = new Queue<string>();

            foreach (string item in rows)
            {
                string replaced = item.Replace(whatString, withString);
                replacedRows.Enqueue(replaced);
            }

            AType result = BuildAType(replacedRows, argument.Shape);
            return result;

        }
        /// <summary>
        /// Create a memory-mapped file with the given path and argument.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="argument"></param>
        public void CreateMemmoryMappedFile(string path, AType argument)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            string memoryMappedFileName = EncodeName(path);
            MemoryMappedFile memoryMappedFile;

            try
            {
                memoryMappedFile = MemoryMappedFile.CreateFromFile(
                    new FileStream(path, FileMode.Create),
                    memoryMappedFileName,
                    MappedFile.ComputeSize(argument),
                    MemoryMappedFileAccess.ReadWrite,
                    new MemoryMappedFileSecurity(),
                    HandleInheritability.Inheritable,
                    false
                );

            }
            catch (Exception)
            {
                throw new Error.Invalid("MemoryMappedFile");
            }

            MappedFile mappedFile = new MappedFile(memoryMappedFile);

            mappedFile.Create(argument);
            mappedFile.Dispose();
        }
Exemple #11
0
        public override AType Execute(AType rightArgument, AType leftArgument, Aplus environment = null)
        {
            if (leftArgument.Type != ATypes.AInteger)
            {
                throw new Error.Type(this.TypeErrorText);
            }

            AType left = Function.Monadic.MonadicFunctionInstance.Ravel.Execute(leftArgument);
            AType right = Function.Monadic.MonadicFunctionInstance.Ravel.Execute(rightArgument);

            AType result;

            switch (CheckVector(left))
            {
                case State.NullFound:
                    // Found a zero in the list, create an emtpy list with correct shape
                    result = CreateResult(left, right);
                    result.Shape = new List<int>(left.Select(item => { return item.asInteger; }));
                    result.Rank = result.Shape.Count;
                    result.Length = result.Shape[0];
                    break;
                case State.DomainError:
                    throw new Error.Domain(this.DomainErrorText);
                case State.MaxRankError:
                    throw new Error.MaxRank(this.MaxRankErrorText);

                default:
                case State.OK:
                    result = CreateResult(left, right);
                    break;
            }

            return result;
        }
Exemple #12
0
        private AType CalculateResidue(AType right, AType left)
        {
            double result;
            double x = right.asFloat;
            double y = left.asFloat;

            if (y == 0)
            {
                result = x;
            }
            else if (y == Double.PositiveInfinity || y == Double.NegativeInfinity)
            {
                result = 0;
            }
            else
            {
                double roundedx;
                if (Utils.TryComprasionTolarence(x, out roundedx))
                {
                    result = ModularArithmetic(roundedx,y);
                }
                else
                {
                    result = ModularArithmetic(x, y); ;
                }
            }
            return AFloat.Create(result);
        }
Exemple #13
0
        internal static AType Items(Aplus environment, AType memoryMappedFileName, AType number)
        {
            string resultPath = Util.GetPath(environment, memoryMappedFileName, ".m");

            if (resultPath == null)
            {
                throw new Error.Domain("Items");
            }

            int newLeadingAxesLength = GetLeadingAxesLength(number);

            if (newLeadingAxesLength == -1)
            {
                return environment.MemoryMappedFileManager.GetLeadingAxesLength(resultPath);
            }
            else
            {
                if (environment.MemoryMappedFileManager.ExistMemoryMappedFile(resultPath))
                {
                    throw new Error.Invalid("Items");
                }

                return environment.MemoryMappedFileManager.ExpandOrDecrease(resultPath, newLeadingAxesLength);
            }
        }
Exemple #14
0
        private AType GenerateMultiDimension(AType arguments)
        {
            int itemCount = 1;
            int number;
            for (int i = 0; i < arguments.Length; i++)
            {
                // Try to convert number to integer
                if (!Utils.TryComprasionTolarence(arguments[i].asFloat, out number))
                {
                    // Failed to convert to integer
                    throw new Error.Type(this.TypeErrorText);
                }

                if (number < 0)
                {
                    // Negative numbers are invalid
                    throw new Error.Domain(this.DomainErrorText);
                }

                // Count how many numbers we need to generate
                itemCount *= number;
            }

            // Generate the numbers
            AType range = GenerateVector(itemCount);

            // Restructure to correct shape
            return Function.Dyadic.DyadicFunctionInstance.Reshape.Execute(range, arguments);
        }
Exemple #15
0
        private static int GetLeadingAxesLength(AType argument)
        {
            if (!argument.IsNumber)
            {
                throw new Error.Type("Items");
            }

            AType result;
            if (!argument.TryFirstScalar(out result, true))
            {
                throw new Error.Length("Items");
            }


            int number;
            if (!result.ConvertToRestrictedWholeNumber(out number))
            {
                throw new Error.Type("Items");
            }

            if (number != -1 && number < 0)
            {
                throw new Error.Domain("Items");
            }

            return number;
        }
Exemple #16
0
        public AType Execute(AType functionScalar, AType argument, Aplus environment = null)
        {
            //'Disclose' the function from functionscalar.
            AFunc function = (AFunc)functionScalar.NestedItem.Data;

            //Convert method to the correspond function format.
            if (function.IsBuiltin)
            {
                Func<Aplus, AType, AType, AType> primitiveFunction =
                    (Func<Aplus, AType, AType, AType>)function.Method;

                return primitiveFunction(environment, argument, null);
            }
            else
            {
                //If function is user defined, we check the valance.
                if (function.Valence - 1 != 1)
                {
                    throw new Error.Valence("Apply");
                }

                //Convert method to the correspond function format.
                Func<Aplus, AType, AType> userDefinedFunction =
                    (Func<Aplus, AType, AType>)function.Method;

                return userDefinedFunction(environment, argument);
            }
        }
Exemple #17
0
        public override AType Execute(AType argument, Aplus environment)
        {
            AType result;

            if (argument.SimpleArray())
            {
                result = argument.IsMemoryMappedFile ? argument : argument.Clone();
            }
            else
            {
                if (!argument.NestedArray())
                {
                    throw new Error.Domain(DomainErrorText);
                }

                switch (argument.Rank)
                {
                    case 0:
                        result = MonadicFunctionInstance.Disclose.Execute(argument);
                        break;
                    case 1:
                        result = NestedVector(argument);
                        break;
                    default:
                        throw new Error.Rank(RankErrorText);
                }
            }

            return result;
        }
Exemple #18
0
        public PickAssignmentTarget AssignExecute(AType right, AType left, Aplus environment = null)
        {
            bool resultFromBox;

            AType result = Compute(environment, right, left, out resultFromBox);
            return new PickAssignmentTarget(result, resultFromBox);
        }
Exemple #19
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;
        }
Exemple #20
0
        /// <summary>
        /// Gets the absolute path for the supplied <see cref="pathArgument"/>.
        /// </summary>
        /// <remarks>
        /// The search for the file relies on the APATH environment variable.
        /// </remarks>
        /// <param name="environment"></param>
        /// <param name="pathArgument">Must be a Char or Symbol type.</param>
        /// <param name="expectedExtension"></param>
        /// <returns>The absolute path for the file or if not found null.</returns>
        internal static string GetPath(Aplus environment, AType pathArgument, string expectedExtension)
        {
            string path = GetFullPathOrValue(pathArgument, environment);
            string resultPath = null;

            if (path != null && !Path.IsPathRooted(path))
            {
                string apath = Environment.GetEnvironmentVariable("APATH", EnvironmentVariableTarget.User);
                string absolutePath;

                foreach (string item in apath.Split(';'))
                {
                    absolutePath = Path.Combine(item, path);

                    if (!Path.IsPathRooted(absolutePath))
                    {
                        absolutePath = Path.GetFullPath(absolutePath);
                    }

                    if (FileSearch(absolutePath, expectedExtension, out resultPath))
                    {
                        break;
                    }
                }
            }
            else
            {
                FileSearch(path, expectedExtension, out resultPath);
            }

            return resultPath;
        }
Exemple #21
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            bool resultFromBox;

            AType result = Compute(environment, right, left, out resultFromBox);
            return result;
        }
Exemple #22
0
        private int GetNumber(AType argument, AType n, Aplus environment)
        {
            if (n.Type != ATypes.AInteger)
            {
                throw new Error.Type("Rank");
            }

            int length = n.Shape.Product();

            if (length > 3)
            {
                throw new Error.Length("Rank");
            }

            AType raveledArray = MonadicFunctionInstance.Ravel.Execute(n, environment);
            int result = raveledArray[0].asInteger;

            if (result < 0)
            {
                result = Math.Max(0, argument.Rank - Math.Abs(result));
            }
            else
            {
                result = Math.Min(result, argument.Rank);
            }

            return result;
        }
Exemple #23
0
        public AType Execute(AType function, AType n, AType right, AType left, Aplus environment = null)
        {
            if (!(function.Data is AFunc))
            {
                throw new Error.NonFunction("Rank");
            }

            AFunc func = (AFunc)function.Data;

            if (!func.IsBuiltin)
            {
                if (func.Valence - 1 != 2)
                {
                    throw new Error.Valence("Rank");
                }
            }

            int[] rankSpecifier = GetRankSpecifier(n, left, right, environment);
            RankJobInfo rankInfo = new RankJobInfo(rankSpecifier, func);

            AType result = Walker(left, right, environment, rankInfo);

            if (rankInfo.FloatConvert && result.IsArray)
            {
                result.ConvertToFloat();
            }

            return result;
        }
Exemple #24
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            int desiredCount = PrepareDesiredCount(left);
            AType items = PrepareInputItems(right);

            return Compute(items, desiredCount);
        }
        private static AType PermissiveIndexingSubIndex(
            AType index, AType array, AType defaultItem, Aplus environment)
        {
            AType result = AArray.Create(array.Type);

            if (index.IsArray)
            {
                for (int i = 0; i < index.Length; i++)
                {
                    result.Add(PermissiveIndexingSubIndex(index[i], array, defaultItem, environment));
                }
            }
            else if (index.asInteger > array.Length - 1 || index.asInteger < 0)
            {
                if (defaultItem.Rank == 0 && array[0].Rank != 0)
                {
                    result = DyadicFunctionInstance.Reshape.Execute(defaultItem, array[0].Shape.ToAArray(), environment);
                }
                else
                {
                    result = defaultItem;
                }
            }
            else
            {
                result = array[index];
            }

            return result;
        }
        public static AType Import(Aplus environment, AType argument)
        {
            if (argument.Type != ATypes.AChar)
            {
                throw new Error.Type("sys.imp");
            }

            if (argument.Rank > 1)
            {
                throw new Error.Rank("sys.imp");
            }

            List<byte> toConvert = new List<byte>();

            if (argument.Rank == 0)
            {
                throw new Error.Domain("sys.imp"); // One character can't be a valid message.
            }

            foreach (AType item in argument)
            {
                toConvert.Add((byte)item.asChar);
            }

            return SysImp.Instance.Import(toConvert.ToArray());
        }
Exemple #27
0
        private byte[] PrepareExpandVector(AType left)
        {
            // if the left side is User defined function, we throw Valence error.
            // this part belongs to Scan.
            if (left.Type == ATypes.AFunc)
            {
                throw new Error.Valence(ValenceErrorText);
            }

            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                throw new Error.Type(TypeErrorText);
            }

            if (left.Rank > 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            //int element;
            AType scalar;

            byte[] expandVector;

            if (left.TryFirstScalar(out scalar, true))
            {
                expandVector = new byte[] { ExtractExpandArgument(scalar) };
            }
            else
            {
                expandVector = left.Select(item => ExtractExpandArgument(item)).ToArray();
            }

            return expandVector;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="env"></param>
        private AType WalkItems(AType left, AType right, Aplus env)
        {
            AType result;
            if (left.Rank > 1)
            {
                result = AArray.Create(ATypes.AArray);
                foreach (AType a in left)
                {
                    result.Add(WalkItems(a, right, env));
                }
            }
            else if (right.Rank > 1)
            {
                result = AArray.Create(ATypes.AArray);
                foreach (AType b in right)
                {
                    result.Add(WalkItems(left, b, env));
                }
            }
            else
            {
                result = Calculate(left, right, env);
            }

            return result;
        }
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            if (left.Rank < 1 || right.Rank < 1)
            {
                throw new Error.Rank(this.RankErrorText);
            }

            if (left.Shape[left.Shape.Count - 1] != right.Shape[0])
            {
                throw new Error.Length(this.LengthErrorText);
            }

            // Calculate the axes for the right argument: (-1 rot iota rho rho right)
            AType targetAxes = DyadicFunctionInstance.Rotate.Execute(
                Enumerable.Range(0, right.Rank).ToAArray(), AInteger.Create(-1), environment);

            AType transposedRight = DyadicFunctionInstance.TransposeAxis.Execute(right, targetAxes, environment);

            AType result = WalkItems(left, transposedRight, environment);

            // by observation it seems that the reference implementation always returns float
            // we behave the same
            result.ConvertToFloat();

            if (result.Length == 0)
            {
                result.Shape = new List<int>(left.Shape.GetRange(0, left.Shape.Count - 1));
                if (right.Shape.Count > 1)
                {
                    result.Shape.AddRange(right.Shape.GetRange(1, right.Shape.Count - 1));
                }
            }
            
            return result;
        }
        private int GetCutNumber(AType right, AType left)
        {
            if (!(left.Type == ATypes.AFloat || left.Type == ATypes.AInteger || left.Type == ATypes.ANull))
            {
                throw new Error.Type(this.TypeErrorText);
            }
            
            AType scalar;
            int cutValue;

            // get the first scalar value with length check on
            if (!left.TryFirstScalar(out scalar, true))
            {
                throw new Error.Nonce(this.NonceErrorText);
            }

            // check if the scalar is a whole number and set the desired count of items
            if (!left.ConvertToRestrictedWholeNumber(out cutValue))
            {
                throw new Error.Type(this.TypeErrorText);
            }

            if (right.Rank > 8)
            {
                throw new Error.MaxRank(MaxRankErrorText);
            }

            if (right.Rank == 0 && cutValue != 1)
            {
                throw new Error.Rank(RankErrorText);
            }

            return cutValue;
        }
Exemple #31
0
        /// <summary>
        /// CASE 6: Nested right argument and nested left argument.
        /// </summary>
        /// <param name="pathBox"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        private AType NestedPathNumber2NestedArray(AType pathBox, AType items, Aplus environment)
        {
            AType path = MonadicFunctionInstance.Disclose.Execute(pathBox, environment);

            if (path.IsFunctionScalar)
            {
                throw new Error.Domain(DomainErrorText);
            }

            //Nested scalar or vector whose items are simple scalar or vector of integers.
            if (path.IsBox)
            {
                throw new Error.Type(TypeErrorText);
            }

            //Right argument is ().
            if (items.Type == ATypes.ANull)
            {
                throw new Error.Index(IndexErrorText);
            }

            if (path.Type == ATypes.ANull)
            {
                if (!items.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                AType result;

                if (!items.TryFirstScalar(out result, true))
                {
                    throw new Error.Domain(DomainErrorText);
                }

                return(MonadicFunctionInstance.Disclose.Execute(result, environment));
            }
            else if (path.Type == ATypes.AInteger)
            {
                if (path.Rank > 1)
                {
                    throw new Error.Rank(RankErrorText);
                }

                if (path.Length == 1)
                {
                    // Case 5
                    return(PathNumber2NestedVector(path.IsArray ? path[0] : path, items));
                }

                // The 'path' variable must be an AArray after this point.
                // so we treat it like that

                if (!items.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                //Length: 0
                if (path.Length != items.Rank || path.Length == 0)
                {
                    throw new Error.Rank(RankErrorText);
                }

                List <int> shape = items.Shape;
                int        index;

                for (int i = 0; i < path.Length; i++)
                {
                    index = path[i].asInteger;

                    if (index < 0 || index >= shape[i])
                    {
                        throw new Error.Index(IndexErrorText);
                    }

                    items = items[index];
                }

                return(MonadicFunctionInstance.Disclose.Execute(items, environment));
            }
            else if (path.Type == ATypes.ASymbol)
            {
                // Case 3
                return(ItemSelectWalker(SymbolConstant2SlotFillerDelegate, path, items, environment));
            }
            else if (path.Type == ATypes.AChar)
            {
                throw new Error.Domain(DomainErrorText);
            }
            else
            {
                throw new Error.Type(TypeErrorText);
            }
        }
Exemple #32
0
        /// <summary>
        /// CASE 3: Slotfiller right argument and simple symbol left argument.
        /// </summary>
        /// <param name="symbol">Symbol to use for selecting from a slotfiller</param>
        /// <param name="items">Slotfiller</param>
        /// <returns></returns>
        private AType SimpleSymbolConstant2SlotFiller(AType symbol, AType items, Aplus environment)
        {
            if (!items.IsSlotFiller(true))
            {
                throw new Error.Domain(DomainErrorText);
            }

            AType result;
            AType keys   = MonadicFunctionInstance.Disclose.Execute(items[0], environment);
            AType values = MonadicFunctionInstance.Disclose.Execute(items[1], environment);

            if (keys.IsArray)
            {
                if (keys.Rank > 1)
                {
                    keys = MonadicFunctionInstance.Ravel.Execute(keys);
                }

                if (values.Rank > 1)
                {
                    values = MonadicFunctionInstance.Ravel.Execute(values);
                }

                int index = -1;

                // TODO: refactor, remove 'i' use the 'index' variable
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].IsBox)
                    {
                        throw new Error.Domain(DomainErrorText);
                    }

                    if (keys[i].CompareTo(symbol) == 0)
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1)
                {
                    //y is a symbol and is not a member of the vector of symbol s in x.
                    throw new Error.Index(IndexErrorText);
                }

                if (values[index].IsPrimitiveFunction() || !values[index].IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                result = MonadicFunctionInstance.Disclose.Execute(values[index], environment);
            }
            else
            {
                // We have only one item in the keys list
                if (symbol.CompareTo(keys) != 0)
                {
                    throw new Error.Index(IndexErrorText);
                }

                if (values.IsPrimitiveFunction() || !values.IsBox)
                {
                    throw new Error.Domain(DomainErrorText);
                }

                result = MonadicFunctionInstance.Disclose.Execute(values, environment);
            }

            return(result);
        }
Exemple #33
0
 static void Sample3(int val1, int val2, AType type1, BType type2)
 {
     Console.WriteLine($"{val1} * {val2} = {val1 * val2} : ({type1},{type2})");
 }
Exemple #34
0
 protected MovableArgument(Expression expr, AType modifier)
     : base(expr, modifier)
 {
 }
Exemple #35
0
 public NamedArgument(string name, Location loc, Expression expr, AType modifier)
     : base(expr, modifier)
 {
     this.Name = name;
     this.loc  = loc;
 }
Exemple #36
0
 /// <summary>
 /// Returns the shape of the argument
 /// </summary>
 /// <remarks>
 /// The shape of a scalar is Null (scalar does not have axes).
 /// For a nonscalar the i-th element of the result is the i-th dimension of the argument.
 /// </remarks>
 public override AType Execute(AType argument, Aplus environment = null)
 {
     return(argument.Shape.ToAArray());
 }
Exemple #37
0
        public static Statement Add(Statement statement1, Statement statement2)
        {
            var TYPE1      = statement1.PropositionType;
            var TYPE2      = statement2.PropositionType;
            var STATEMENT1 = statement1.StatementName;
            var STATEMENT2 = statement2.StatementName;
            var result     = string.Empty;

            if (!(IAERule.CheckStatementsCanBeAligned(statement1, statement2)))
            {
                return(null);                                                             //==>if the statements to be added cannot be aligned then it should retun null [for safety];
            }
            if (TYPE1 == "A" && TYPE2 == "A")
            {
                //return "A";

                result = AType.GetPropositionBySubjectAndPredicate(statement1.Subject,
                                                                   statement2.Predicate);
                return(new Statement(result));
            }
            else if (TYPE1 == "A" && TYPE2 == "E")
            {
                //return "E";
                result = EType.GetPropositionBySubjectAndPredicate(statement1.Subject,
                                                                   statement2.Predicate);

                return(new Statement(result));
            }
            else if (TYPE1 == "E" && TYPE2 == "A")
            {
                //return "O*";
                result = OType.GetStatementBySubjectAndPredicate(statement2.Predicate,
                                                                 statement1.Subject);
                return(new Statement(result));
            }
            else if (TYPE1 == "E" && TYPE2 == "I")
            {
                //return "O*";
                result = OType.GetStatementBySubjectAndPredicate(statement2.Predicate,
                                                                 statement1.Subject);

                return(new Statement(result));
            }
            else if (TYPE1 == "I" && TYPE2 == "A")
            {
                // return "I";
                result = IType.GetStatementBySubjectAndPredicate(statement1.Subject,
                                                                 statement2.Predicate);

                return(new Statement(result));
            }
            else if (TYPE1 == "I" && TYPE2 == "E")
            {
                // return "O";
                result = OType.GetStatementBySubjectAndPredicate(statement1.Subject,
                                                                 statement2.Predicate);

                return(new Statement(result));
            }
            else if (TYPE1 == "A" && TYPE2 == "I")
            {
                return(null);
                //Convert "I" + "A";
                // return "I";
                //result = IType.GetStatementBySubjectAndPredicate(statement2.Subject,
                // statement1.Predicate);

                //  return new Statement(result);

                //Had to implement rearranging order
            }

            return(null);
        }
Exemple #38
0
 public override int CompareTo(AType other)
 {
     return(this.symbolName.CompareTo(other.asString));
 }
Exemple #39
0
 /// <summary>
 /// <see cref="MonadicTypeAlternate"/>
 /// </summary>
 public static AType DyadicTypeAlternate(Aplus env, AType number, AType ignored)
 {
     return(MonadicTypeAlternate(env, number));
 }
Exemple #40
0
        private AType FloatLTE(AType right, AType left)
        {
            int number = (Utils.ComparisonTolerance(left.asFloat, right.asFloat) || left.asFloat < right.asFloat) ? 1 : 0;

            return(AInteger.Create(number));
        }
Exemple #41
0
 public override AType Execute(AType right, AType left, Aplus environment = null)
 {
     return(AInteger.Create(left.Equals(right) ? 1 : 0));
 }
        protected override void ParseClassMember(
            TokenStream tokens,
            FileScope fileScope,
            ClassDefinition classDef,
            IList <FunctionDefinition> methodsOut,
            IList <FieldDefinition> fieldsOut,
            IList <PropertyDefinition> propertiesOut)
        {
            AnnotationCollection annotations = this.parser.AnnotationParser.ParseAnnotations(tokens);
            ModifierCollection   modifiers   = ModifierCollection.Parse(tokens);

            if (tokens.IsNext(this.parser.Keywords.CONSTRUCTOR))
            {
                if (modifiers.HasStatic)
                {
                    if (classDef.StaticConstructor != null)
                    {
                        throw new ParserException(tokens.Pop(), "Multiple static constructors are not allowed.");
                    }
                    classDef.StaticConstructor = this.ParseConstructor(tokens, classDef, modifiers, annotations);
                }
                else
                {
                    if (classDef.Constructor != null)
                    {
                        throw this.parser.GenerateParseError(
                                  ErrorMessages.CLASS_CANNOT_HAVE_MULTIPLE_CONSTRUCTORS,
                                  tokens.Pop());
                    }
                    classDef.Constructor = this.ParseConstructor(tokens, classDef, modifiers, annotations);
                }
            }
            else if (tokens.IsNext(this.parser.Keywords.CLASS))
            {
                throw new ParserException(tokens.Pop(), "Nested classes are not currently supported.");
            }
            else
            {
                // Parsing the type and then throwing it away is a little wasteful, but feels less weird than parsing
                // the type here and passing it into ParseFunction()/ParseField(). ParseX() should ParseX from the start.
                TokenStream.StreamState fieldOrFunctionStart = tokens.RecordState();
                AType fieldOrFunctionType = this.parser.TypeParser.TryParse(tokens);
                Token tokenAfterName      = fieldOrFunctionType != null?tokens.PeekAhead(1) : null;

                tokens.RestoreState(fieldOrFunctionStart);

                if (tokenAfterName == null)
                {
                    tokens.PopExpected("}");                         // intentionally induce error
                }
                switch (tokenAfterName.Value)
                {
                case "=":
                case ";":
                    fieldsOut.Add(this.ParseField(tokens, classDef, modifiers, annotations));
                    break;

                case "(":
                    methodsOut.Add(this.ParseFunction(tokens, classDef, fileScope, modifiers, annotations));
                    break;

                case "{":
                    // TODO(acrylic): properties should be implemented in Acrylic, just not yet.
                    tokens.PopExpected("}");     // intentionally induce error
                    break;

                default:
                    tokens.PopExpected("}");     // intentionally induce error
                    break;
                }
            }

            // TODO: check for annotations that aren't used.
            // https://github.com/blakeohare/crayon/issues/305
        }
Exemple #43
0
        private AType Walker(AType left, AType right, Aplus environment, RankJobInfo rankInfo)
        {
            int tx = Math.Min(rankInfo.RankSpecifier[2], right.Rank - rankInfo.RankSpecifier[1]);
            int ty = Math.Min(rankInfo.RankSpecifier[2], left.Rank - rankInfo.RankSpecifier[0]);

            int lx = Math.Max(0, right.Rank - (rankInfo.RankSpecifier[1] + tx));
            int ly = Math.Max(0, left.Rank - (rankInfo.RankSpecifier[0] + ty));

            AType result;

            if (ly > 0)
            {
                result = LeftSideWalk(left, right, environment, rankInfo);
                result.UpdateInfo();
            }
            else if (lx > 0)
            {
                result = RightSideWalk(left, right, environment, rankInfo);
                result.UpdateInfo();
            }
            else if (ty != tx)
            {
                result = (ty > tx)
                    ? LeftSideWalk(left, right, environment, rankInfo)
                    : RightSideWalk(left, right, environment, rankInfo);

                result.UpdateInfo();
            }
            else
            {
                if (ty > 0)
                {
                    List <int> tyShape = left.Shape.GetRange(0, ty);
                    List <int> txShape = right.Shape.GetRange(0, tx);

                    if (!tyShape.SequenceEqual(txShape))
                    {
                        throw new Error.Mismatch("Rank");
                    }
                }

                if (ty != 0)
                {
                    result = AArray.Create(ATypes.ANull);
                    AType temp;

                    for (int i = 0; i < left.Length; i++)
                    {
                        temp = Walker(left[i], right[i], environment, rankInfo);
                        TypeCheck(temp.Type, rankInfo);
                        result.AddWithNoUpdate(temp);
                    }

                    result.UpdateInfo();
                }
                else
                {
                    result = rankInfo.Method(environment, right, left);
                }
            }

            return(result);
        }
Exemple #44
0
 public TypeTokenPair(AType type, Token token)
 {
     this.Type  = type;
     this.Token = token;
 }
Exemple #45
0
 public Argument(Expression expr, AType type)
 {
     this.Expr    = expr;
     this.ArgType = type;
 }
Exemple #46
0
 public void PickDomainError13()
 {
     AType result = this.engine.Execute <AType>("(<{+}) pick (3;4)");
 }
Exemple #47
0
 public AType ExecuteDefault(AType rightArgument, AType leftArgument)
 {
     return(AInteger.Create(0));
 }
Exemple #48
0
 static void Sample1(AType type1, BType type2, CType type3)
 {
     Console.WriteLine($"{type1} , {type2} , {type3} ");
 }
Exemple #49
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            LaminateJobInfo arguments = CreateLaminateJob(right, left);

            return(Compute(arguments));
        }
Exemple #50
0
        /// <summary>
        /// Register an itemwise dependency.
        /// </summary>
        /// <param name="variableName"></param>
        /// <param name="dependentItems"></param>
        /// <param name="function"></param>
        /// <returns>Returns the registerd dependency information.</returns>
        public DependencyItem RegisterItemwise(string variableName, HashSet <string> dependentItems, AType function)
        {
            // Invalidate any dependencies using the variable
            InvalidateDependencies(variableName);

            DependencyItem item = new DependencyItem(variableName, dependentItems, function, true);

            this.mapping[variableName] = item;
            return(item);
        }
Exemple #51
0
 public override void AddWithNoUpdate(AType item)
 {
     this.items.Add(item);
 }
Exemple #52
0
 public void DropDomainError2()
 {
     AType result = this.engine.Execute <AType>("1 3 drop 6 72");
 }
Exemple #53
0
        private AType Compute(AType right, int dropCounter)
        {
            if (right.IsArray && dropCounter == 0)
            {
                return(right.Clone());
            }

            AType result = AArray.Create(ATypes.AType);

            if (right.IsArray)
            {
                if (right.Length - Math.Abs(dropCounter) > 0)
                {
                    if (dropCounter > 0)
                    {
                        for (int i = dropCounter; i < right.Length; i++)
                        {
                            result.AddWithNoUpdate(right[i].Clone());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < right.Length + dropCounter; i++)
                        {
                            result.AddWithNoUpdate(right[i].Clone());
                        }
                    }
                    result.Length = right.Length - Math.Abs(dropCounter);
                    result.Shape  = new List <int>()
                    {
                        result.Length
                    };

                    if (right.Rank > 1)
                    {
                        result.Shape.AddRange(right.Shape.GetRange(1, right.Shape.Count - 1));
                    }

                    result.Rank = right.Rank;
                    result.Type = result[0].Type;
                }
                else
                {
                    result.Type = right.MixedType() ? ATypes.ANull : right.Type;
                }
            }
            else
            {
                if (dropCounter == 0)
                {
                    result.Add(right.Clone());
                    result.Length = 1;
                    result.Shape  = new List <int>()
                    {
                        1
                    };
                    result.Type = right.Type;
                }
                else
                {
                    result.Type = right.MixedType() ? ATypes.ANull : right.Type;
                }
            }
            return(result);
        }
Exemple #54
0
 public override void Add(AType item)
 {
     this.items.Add(item);
     UpdateInfo();
 }
Exemple #55
0
 public void ReduceOrTypeError()
 {
     AType result = this.engine.Execute <AType>("?/ 5.4");
 }
Exemple #56
0
        public override AType Execute(AType right, AType left, Aplus environment = null)
        {
            int dropCounter = GetDropCounter(left);

            return(Compute(right, dropCounter));
        }
Exemple #57
0
        /// <inheritdoc />
        public bool Equals([AllowNull] ContourCarpet other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                     ) &&
                 (
                     Visible == other.Visible ||
                     Visible != null &&
                     Visible.Equals(other.Visible)
                 ) &&
                 (
                     ShowLegend == other.ShowLegend ||
                     ShowLegend != null &&
                     ShowLegend.Equals(other.ShowLegend)
                 ) &&
                 (
                     LegendGroup == other.LegendGroup ||
                     LegendGroup != null &&
                     LegendGroup.Equals(other.LegendGroup)
                 ) &&
                 (
                     Opacity == other.Opacity ||
                     Opacity != null &&
                     Opacity.Equals(other.Opacity)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     UId == other.UId ||
                     UId != null &&
                     UId.Equals(other.UId)
                 ) &&
                 (
                     Equals(Ids, other.Ids) ||
                     Ids != null && other.Ids != null &&
                     Ids.SequenceEqual(other.Ids)
                 ) &&
                 (
                     Equals(CustomData, other.CustomData) ||
                     CustomData != null && other.CustomData != null &&
                     CustomData.SequenceEqual(other.CustomData)
                 ) &&
                 (
                     Meta == other.Meta ||
                     Meta != null &&
                     Meta.Equals(other.Meta)
                 ) &&
                 (
                     Equals(MetaArray, other.MetaArray) ||
                     MetaArray != null && other.MetaArray != null &&
                     MetaArray.SequenceEqual(other.MetaArray)
                 ) &&
                 (
                     Stream == other.Stream ||
                     Stream != null &&
                     Stream.Equals(other.Stream)
                 ) &&
                 (
                     UiRevision == other.UiRevision ||
                     UiRevision != null &&
                     UiRevision.Equals(other.UiRevision)
                 ) &&
                 (
                     Carpet == other.Carpet ||
                     Carpet != null &&
                     Carpet.Equals(other.Carpet)
                 ) &&
                 (
                     Equals(Z, other.Z) ||
                     Z != null && other.Z != null &&
                     Z.SequenceEqual(other.Z)
                 ) &&
                 (
                     Equals(A, other.A) ||
                     A != null && other.A != null &&
                     A.SequenceEqual(other.A)
                 ) &&
                 (
                     A0 == other.A0 ||
                     A0 != null &&
                     A0.Equals(other.A0)
                 ) &&
                 (
                     DA == other.DA ||
                     DA != null &&
                     DA.Equals(other.DA)
                 ) &&
                 (
                     Equals(B, other.B) ||
                     B != null && other.B != null &&
                     B.SequenceEqual(other.B)
                 ) &&
                 (
                     B0 == other.B0 ||
                     B0 != null &&
                     B0.Equals(other.B0)
                 ) &&
                 (
                     Db == other.Db ||
                     Db != null &&
                     Db.Equals(other.Db)
                 ) &&
                 (
                     Equals(Text, other.Text) ||
                     Text != null && other.Text != null &&
                     Text.SequenceEqual(other.Text)
                 ) &&
                 (
                     Equals(HoverText, other.HoverText) ||
                     HoverText != null && other.HoverText != null &&
                     HoverText.SequenceEqual(other.HoverText)
                 ) &&
                 (
                     Transpose == other.Transpose ||
                     Transpose != null &&
                     Transpose.Equals(other.Transpose)
                 ) &&
                 (
                     AType == other.AType ||
                     AType != null &&
                     AType.Equals(other.AType)
                 ) &&
                 (
                     BType == other.BType ||
                     BType != null &&
                     BType.Equals(other.BType)
                 ) &&
                 (
                     FillColor == other.FillColor ||
                     FillColor != null &&
                     FillColor.Equals(other.FillColor)
                 ) &&
                 (
                     AutoContour == other.AutoContour ||
                     AutoContour != null &&
                     AutoContour.Equals(other.AutoContour)
                 ) &&
                 (
                     NContours == other.NContours ||
                     NContours != null &&
                     NContours.Equals(other.NContours)
                 ) &&
                 (
                     Contours == other.Contours ||
                     Contours != null &&
                     Contours.Equals(other.Contours)
                 ) &&
                 (
                     Line == other.Line ||
                     Line != null &&
                     Line.Equals(other.Line)
                 ) &&
                 (
                     ZAuto == other.ZAuto ||
                     ZAuto != null &&
                     ZAuto.Equals(other.ZAuto)
                 ) &&
                 (
                     ZMin == other.ZMin ||
                     ZMin != null &&
                     ZMin.Equals(other.ZMin)
                 ) &&
                 (
                     ZMax == other.ZMax ||
                     ZMax != null &&
                     ZMax.Equals(other.ZMax)
                 ) &&
                 (
                     ZMid == other.ZMid ||
                     ZMid != null &&
                     ZMid.Equals(other.ZMid)
                 ) &&
                 (
                     ColorScale == other.ColorScale ||
                     ColorScale != null &&
                     ColorScale.Equals(other.ColorScale)
                 ) &&
                 (
                     AutoColorScale == other.AutoColorScale ||
                     AutoColorScale != null &&
                     AutoColorScale.Equals(other.AutoColorScale)
                 ) &&
                 (
                     ReverseScale == other.ReverseScale ||
                     ReverseScale != null &&
                     ReverseScale.Equals(other.ReverseScale)
                 ) &&
                 (
                     ShowScale == other.ShowScale ||
                     ShowScale != null &&
                     ShowScale.Equals(other.ShowScale)
                 ) &&
                 (
                     ColorBar == other.ColorBar ||
                     ColorBar != null &&
                     ColorBar.Equals(other.ColorBar)
                 ) &&
                 (
                     ColorAxis == other.ColorAxis ||
                     ColorAxis != null &&
                     ColorAxis.Equals(other.ColorAxis)
                 ) &&
                 (
                     XAxis == other.XAxis ||
                     XAxis != null &&
                     XAxis.Equals(other.XAxis)
                 ) &&
                 (
                     YAxis == other.YAxis ||
                     YAxis != null &&
                     YAxis.Equals(other.YAxis)
                 ) &&
                 (
                     IdsSrc == other.IdsSrc ||
                     IdsSrc != null &&
                     IdsSrc.Equals(other.IdsSrc)
                 ) &&
                 (
                     CustomDataSrc == other.CustomDataSrc ||
                     CustomDataSrc != null &&
                     CustomDataSrc.Equals(other.CustomDataSrc)
                 ) &&
                 (
                     MetaSrc == other.MetaSrc ||
                     MetaSrc != null &&
                     MetaSrc.Equals(other.MetaSrc)
                 ) &&
                 (
                     ZSrc == other.ZSrc ||
                     ZSrc != null &&
                     ZSrc.Equals(other.ZSrc)
                 ) &&
                 (
                     ASrc == other.ASrc ||
                     ASrc != null &&
                     ASrc.Equals(other.ASrc)
                 ) &&
                 (
                     BSrc == other.BSrc ||
                     BSrc != null &&
                     BSrc.Equals(other.BSrc)
                 ) &&
                 (
                     TextSrc == other.TextSrc ||
                     TextSrc != null &&
                     TextSrc.Equals(other.TextSrc)
                 ) &&
                 (
                     HoverTextSrc == other.HoverTextSrc ||
                     HoverTextSrc != null &&
                     HoverTextSrc.Equals(other.HoverTextSrc)
                 ));
        }
Exemple #58
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (Visible != null)
         {
             hashCode = hashCode * 59 + Visible.GetHashCode();
         }
         if (ShowLegend != null)
         {
             hashCode = hashCode * 59 + ShowLegend.GetHashCode();
         }
         if (LegendGroup != null)
         {
             hashCode = hashCode * 59 + LegendGroup.GetHashCode();
         }
         if (Opacity != null)
         {
             hashCode = hashCode * 59 + Opacity.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (UId != null)
         {
             hashCode = hashCode * 59 + UId.GetHashCode();
         }
         if (Ids != null)
         {
             hashCode = hashCode * 59 + Ids.GetHashCode();
         }
         if (CustomData != null)
         {
             hashCode = hashCode * 59 + CustomData.GetHashCode();
         }
         if (Meta != null)
         {
             hashCode = hashCode * 59 + Meta.GetHashCode();
         }
         if (MetaArray != null)
         {
             hashCode = hashCode * 59 + MetaArray.GetHashCode();
         }
         if (Stream != null)
         {
             hashCode = hashCode * 59 + Stream.GetHashCode();
         }
         if (UiRevision != null)
         {
             hashCode = hashCode * 59 + UiRevision.GetHashCode();
         }
         if (Carpet != null)
         {
             hashCode = hashCode * 59 + Carpet.GetHashCode();
         }
         if (Z != null)
         {
             hashCode = hashCode * 59 + Z.GetHashCode();
         }
         if (A != null)
         {
             hashCode = hashCode * 59 + A.GetHashCode();
         }
         if (A0 != null)
         {
             hashCode = hashCode * 59 + A0.GetHashCode();
         }
         if (DA != null)
         {
             hashCode = hashCode * 59 + DA.GetHashCode();
         }
         if (B != null)
         {
             hashCode = hashCode * 59 + B.GetHashCode();
         }
         if (B0 != null)
         {
             hashCode = hashCode * 59 + B0.GetHashCode();
         }
         if (Db != null)
         {
             hashCode = hashCode * 59 + Db.GetHashCode();
         }
         if (Text != null)
         {
             hashCode = hashCode * 59 + Text.GetHashCode();
         }
         if (HoverText != null)
         {
             hashCode = hashCode * 59 + HoverText.GetHashCode();
         }
         if (Transpose != null)
         {
             hashCode = hashCode * 59 + Transpose.GetHashCode();
         }
         if (AType != null)
         {
             hashCode = hashCode * 59 + AType.GetHashCode();
         }
         if (BType != null)
         {
             hashCode = hashCode * 59 + BType.GetHashCode();
         }
         if (FillColor != null)
         {
             hashCode = hashCode * 59 + FillColor.GetHashCode();
         }
         if (AutoContour != null)
         {
             hashCode = hashCode * 59 + AutoContour.GetHashCode();
         }
         if (NContours != null)
         {
             hashCode = hashCode * 59 + NContours.GetHashCode();
         }
         if (Contours != null)
         {
             hashCode = hashCode * 59 + Contours.GetHashCode();
         }
         if (Line != null)
         {
             hashCode = hashCode * 59 + Line.GetHashCode();
         }
         if (ZAuto != null)
         {
             hashCode = hashCode * 59 + ZAuto.GetHashCode();
         }
         if (ZMin != null)
         {
             hashCode = hashCode * 59 + ZMin.GetHashCode();
         }
         if (ZMax != null)
         {
             hashCode = hashCode * 59 + ZMax.GetHashCode();
         }
         if (ZMid != null)
         {
             hashCode = hashCode * 59 + ZMid.GetHashCode();
         }
         if (ColorScale != null)
         {
             hashCode = hashCode * 59 + ColorScale.GetHashCode();
         }
         if (AutoColorScale != null)
         {
             hashCode = hashCode * 59 + AutoColorScale.GetHashCode();
         }
         if (ReverseScale != null)
         {
             hashCode = hashCode * 59 + ReverseScale.GetHashCode();
         }
         if (ShowScale != null)
         {
             hashCode = hashCode * 59 + ShowScale.GetHashCode();
         }
         if (ColorBar != null)
         {
             hashCode = hashCode * 59 + ColorBar.GetHashCode();
         }
         if (ColorAxis != null)
         {
             hashCode = hashCode * 59 + ColorAxis.GetHashCode();
         }
         if (XAxis != null)
         {
             hashCode = hashCode * 59 + XAxis.GetHashCode();
         }
         if (YAxis != null)
         {
             hashCode = hashCode * 59 + YAxis.GetHashCode();
         }
         if (IdsSrc != null)
         {
             hashCode = hashCode * 59 + IdsSrc.GetHashCode();
         }
         if (CustomDataSrc != null)
         {
             hashCode = hashCode * 59 + CustomDataSrc.GetHashCode();
         }
         if (MetaSrc != null)
         {
             hashCode = hashCode * 59 + MetaSrc.GetHashCode();
         }
         if (ZSrc != null)
         {
             hashCode = hashCode * 59 + ZSrc.GetHashCode();
         }
         if (ASrc != null)
         {
             hashCode = hashCode * 59 + ASrc.GetHashCode();
         }
         if (BSrc != null)
         {
             hashCode = hashCode * 59 + BSrc.GetHashCode();
         }
         if (TextSrc != null)
         {
             hashCode = hashCode * 59 + TextSrc.GetHashCode();
         }
         if (HoverTextSrc != null)
         {
             hashCode = hashCode * 59 + HoverTextSrc.GetHashCode();
         }
         return(hashCode);
     }
 }
        protected override Expression ParseInstantiate(TokenStream tokens, Node owner)
        {
            Token newToken = tokens.PopExpected(this.parser.Keywords.NEW);

            AType             className           = this.ParseTypeForInstantiation(tokens);
            Expression        arrayAllocationSize = null;
            List <Expression> arrayMembers        = null;
            bool isArray = tokens.IsNext("[") ||      // the type is anything but there's an array size declaration next
                           className.RootType == "["; // the type is an array itself. There's probably inline elements defined.

            if (isArray)
            {
                if (tokens.IsNext("["))
                {
                    Token bracketToken = tokens.PopExpected("[");
                    if (!tokens.IsNext("]"))
                    {
                        arrayAllocationSize = this.Parse(tokens, owner);
                    }
                    tokens.PopExpected("]");
                    className = new AType(new Token[] { bracketToken }, new AType[] { className });
                    while (tokens.IsNext("["))
                    {
                        bracketToken = tokens.PopExpected("[");
                        className    = new AType(new Token[] { bracketToken }, new AType[] { className });
                        tokens.PopExpected("]");
                    }
                }

                if (arrayAllocationSize == null)
                {
                    arrayMembers = new List <Expression>();
                    tokens.PopExpected("{");
                    bool nextAllowed = true;
                    while (!tokens.PopIfPresent("}"))
                    {
                        if (!nextAllowed)
                        {
                            tokens.PopExpected("}");               // throws
                        }
                        arrayMembers.Add(this.Parse(tokens, owner));
                        nextAllowed = tokens.PopIfPresent(",");
                    }
                }
                else
                {
                    arrayMembers = new List <Expression>();
                }
            }

            switch (className.RootType)
            {
            case "[":
                ListDefinition arrayDefinition = new ListDefinition(newToken, arrayMembers, className.Generics[0], owner, true, arrayAllocationSize);
                return(arrayDefinition);

            case "List":
                tokens.PopExpected("(");
                tokens.PopExpected(")");
                List <Expression> items;
                if (tokens.IsNext("{"))
                {
                    items = this.ParseArrayDeclarationItems(tokens, owner);
                }
                else
                {
                    items = new List <Expression>();
                }
                return(new ListDefinition(newToken, items, className.Generics[0], owner, false, null));

            case "Dictionary":
                tokens.PopExpected("(");
                tokens.PopExpected(")");
                List <Expression> dictionaryKeys   = new List <Expression>();
                List <Expression> dictionaryValues = new List <Expression>();
                if (tokens.IsNext("{"))
                {
                    this.ParseDictionaryInlineItems(tokens, dictionaryKeys, dictionaryValues, owner);
                }
                return(new DictionaryDefinition(
                           newToken,
                           className.Generics[0],
                           className.Generics[1],
                           dictionaryKeys,
                           dictionaryValues,
                           owner));

            default:
                break;
            }

            IList <Expression> args = this.ParseArgumentList(tokens, owner);

            return(new Instantiate(newToken, className.FirstToken, className.RootType, className.Generics, args, owner));
        }
Exemple #60
0
 public void PickIndexError15()
 {
     AType result = this.engine.Execute <AType>("(0;0) pick (();3)");
 }