Ejemplo n.º 1
0
            public List <MethodMirror> GetOverloads(string methodName)
            {
                List <MethodMirror> methods = new List <MethodMirror>();
                string name = string.Empty;

                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);

                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                foreach (ProcedureNode pNode in procList)
                {
                    name = pNode.name;
                    if (name == methodName)
                    {
                        methods.Add(new MethodMirror(pNode));
                    }
                }


                return(methods);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Returns the list of constructors defined for the given class
            /// </summary>
            /// <returns></returns>
            public List <MethodMirror> GetConstructors()
            {
                List <MethodMirror> constructors = new List <MethodMirror>();

                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);
                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                foreach (ProcedureNode pNode in procList)
                {
                    if (pNode.isConstructor == true)
                    {
                        constructors.Add(new MethodMirror(pNode));
                    }
                }

                return(constructors);
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Returns the base class hierarchy for the given class
            /// </summary>
            /// <returns></returns>
            public List <ClassMirror> GetClassHierarchy()
            {
                List <ClassMirror> baseClasses = new List <ClassMirror>();

                Validity.Assert(!string.IsNullOrEmpty(ClassName));
                Validity.Assert(staticCore != null);

                int ci;

                if (classNode == null)
                {
                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ClassNode cNode = classNode;

                while (cNode.baseList.Count > 0)
                {
                    ci = cNode.baseList[0];
                    Validity.Assert(ci != ProtoCore.DSASM.Constants.kInvalidIndex);

                    baseClasses.Add(new ClassMirror(staticCore, staticCore.ClassTable.ClassNodes[ci], this.libraryMirror));

                    cNode = staticCore.ClassTable.ClassNodes[ci];
                }
                return(baseClasses);
            }
        /// <summary>
        /// Traverses the identifierlist argument until class name resolution succeeds or fails.
        /// </summary>
        /// <param name="classTable"></param>
        /// <param name="identList"></param>
        /// <returns></returns>
        public static string[] GetResolvedClassName(ProtoCore.DSASM.ClassTable classTable, ProtoCore.AST.AssociativeAST.IdentifierListNode identList)
        {
            string[] classNames = classTable.GetAllMatchingClasses(ProtoCore.Utils.CoreUtils.GetIdentifierStringUntilFirstParenthesis(identList));

            // Failed to find the first time
            // Attempt to remove identifiers in the identifierlist until we find a class or not
            while (0 == classNames.Length)
            {
                // Move to the left node
                AssociativeNode leftNode = identList.LeftNode;
                if (leftNode is IdentifierListNode)
                {
                    identList  = leftNode as IdentifierListNode;
                    classNames = classTable.GetAllMatchingClasses(ProtoCore.Utils.CoreUtils.GetIdentifierStringUntilFirstParenthesis(identList));
                }
                if (leftNode is IdentifierNode)
                {
                    IdentifierNode identNode = leftNode as IdentifierNode;
                    classNames = classTable.GetAllMatchingClasses(identNode.Name);
                    break;
                }
                else
                {
                    break;
                }
            }
            return(classNames);
        }
Ejemplo n.º 5
0
            /// <summary>
            ///  Returns the list of function properties of the class only
            /// </summary>
            /// <returns> function nodes </returns>
            public List <MethodMirror> GetFunctions()
            {
                List <MethodMirror> methods = new List <MethodMirror>();
                string name = string.Empty;

                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);

                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                foreach (ProcedureNode pNode in procList)
                {
                    name = pNode.name;
                    if (!pNode.isAssocOperator && !pNode.isAutoGenerated && !pNode.isAutoGeneratedThisProc && !pNode.isConstructor)
                    {
                        methods.Add(new MethodMirror(pNode));
                    }
                }

                return(methods);
            }
Ejemplo n.º 6
0
        public int GetConversionDistance(List <StackValue> reducedParamSVs, ProtoCore.DSASM.ClassTable classTable, bool allowArrayPromotion, RuntimeCore runtimeCore)
        {
            // If the replication strategy allows array promotion, first check for the case
            // where it could be disabled using the [AllowArrayPromotion(false)] attribute
            // and if so set it from the attribute.
            if (allowArrayPromotion)
            {
                var ma = procedureNode.MethodAttribute;
                if (ma != null)
                {
                    allowArrayPromotion = ma.AllowArrayPromotion;
                }
            }
            int dist = ComputeTypeDistance(reducedParamSVs, classTable, runtimeCore, allowArrayPromotion);

            if (dist >= 0 && dist != (int)ProcedureDistance.MaxDistance) //Is it possible to convert to this type?
            {
                if (!FunctionGroup.CheckInvalidArrayCoersion(this, reducedParamSVs, classTable, runtimeCore, allowArrayPromotion))
                {
                    return(dist);
                }
            }

            return((int)ProcedureDistance.InvalidDistance);
        }
Ejemplo n.º 7
0
            public ClassMirror(string className, ProtoCore.Core core)
                : base(core, className)
            {
                if (core == null)
                {
                    return;
                }

                ClassName = className;

                if (classNode == null)
                {
                    ProtoCore.DSASM.ClassTable classTable = core.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                    else
                    {
                        throw new Exception(String.Format("Class {0} not defined", className));
                    }
                }
                libraryMirror = new LibraryMirror(classNode.ExternLib, core);
            }
Ejemplo n.º 8
0
            /// <summary>
            ///  Returns the list of class properties of this class
            /// </summary>
            /// <returns> symbol nodes</returns>
            public List <PropertyMirror> GetProperties()
            {
                List <PropertyMirror> properties = new List <PropertyMirror>();

                Dictionary <string, ProcedureNode> setterMap = new Dictionary <string, ProcedureNode>();
                string name = string.Empty;

                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);

                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);


                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;
                string getterPrefix = ProtoCore.DSASM.Constants.kGetterPrefix;
                string setterPrefix = ProtoCore.DSASM.Constants.kSetterPrefix;

                foreach (ProcedureNode pNode in procList)
                {
                    name = pNode.name;
                    if (name.Contains(getterPrefix) && pNode.argInfoList.Count == 0)
                    {
                        properties.Add(new PropertyMirror(pNode));
                    }
                    else if (name.Contains(setterPrefix) && pNode.argInfoList.Count == 1 && !pNode.isAutoGeneratedThisProc)
                    {
                        if (setterMap.ContainsKey(name))
                        {
                            ProcedureNode proc = setterMap[name];
                            if (proc.argTypeList[0].UID == (int)ProtoCore.PrimitiveType.kTypeVar && pNode.argTypeList[0].UID != (int)ProtoCore.PrimitiveType.kTypeVar)
                            {
                                setterMap.Remove(name);
                                setterMap.Add(name, pNode);
                            }
                        }
                        else
                        {
                            setterMap.Add(name, pNode);
                        }
                    }
                }
                foreach (var kvp in setterMap)
                {
                    properties.Add(new PropertyMirror(kvp.Value, true));
                }

                return(properties);
            }
Ejemplo n.º 9
0
 public ClassMirror(ProtoCore.Type type, ProtoCore.Core core)
     : base(core, type.Name)
 {
     ClassName = type.Name;
     if (classNode == null)
     {
         ProtoCore.DSASM.ClassTable classTable = core.ClassTable;
         classNode = classTable.ClassNodes[type.UID];
     }
     libraryMirror = new LibraryMirror(classNode.ExternLib, core);
 }
Ejemplo n.º 10
0
            public MethodMirror GetDeclaredMethod(string className, string methodName, List <ProtoCore.Type> argumentTypes)
            {
                // Check global methods if classname is empty or null
                if (string.IsNullOrEmpty(className))
                {
                    List <MethodMirror> methods = null;
                    methods = GetGlobalMethods();
                    foreach (var method in methods)
                    {
                        if (method.MethodName == methodName)
                        {
                            List <ProtoCore.Type> argTypes = method.GetArgumentTypes();
                            if (argTypes.Count == argumentTypes.Count)
                            {
                                bool isEqual = true;
                                for (int i = 0; i < argumentTypes.Count; ++i)
                                {
                                    if (!argumentTypes[i].Equals(argTypes[i]))
                                    {
                                        isEqual = false;
                                        break;
                                    }
                                }
                                if (isEqual)
                                {
                                    return(method);
                                }
                            }
                        }
                    }
                }
                else // find method in Class
                {
                    Validity.Assert(staticCore != null);

                    ClassNode classNode = null;
                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(className);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }


                    ProcedureTable       procedureTable = classNode.vtable;
                    List <ProcedureNode> procList       = procedureTable.procList;

                    return(StaticMirror.FindMethod(methodName, argumentTypes, procList));
                }

                return(null);
            }
Ejemplo n.º 11
0
            public ClassMirror(int classIndex, ProtoCore.Core core)
            {
                if (classIndex == Constants.kInvalidIndex)
                {
                    throw new ArgumentException("classIndex is invalid");
                }

                ProtoCore.DSASM.ClassTable classTable = core.ClassTable;
                classNode     = classTable.ClassNodes[classIndex];
                libraryMirror = new LibraryMirror(classNode.ExternLib, core);
                ClassName     = classNode.name;
            }
Ejemplo n.º 12
0
            //public ClassMirror()
            //{
            //}

            public ClassMirror(ProtoCore.Type type, ProtoLanguage.CompileStateTracker compileState)
            {
                if (core != null)
                {
                    ClassName = type.Name;
                    if (classNode == null)
                    {
                        ProtoCore.DSASM.ClassTable classTable = core.DSExecutable.classTable;
                        classNode = classTable.ClassNodes[type.UID];
                    }
                    libraryMirror = new LibraryMirror(classNode.ExternLib, compileState);
                }
            }
Ejemplo n.º 13
0
        public int GetConversionDistance(List <StackValue> reducedParamSVs, ProtoCore.DSASM.ClassTable classTable, bool allowArrayPromotion, RuntimeCore runtimeCore)
        {
            int dist = ComputeTypeDistance(reducedParamSVs, classTable, runtimeCore, allowArrayPromotion);

            if (dist >= 0 && dist != (int)ProcedureDistance.kMaxDistance) //Is it possible to convert to this type?
            {
                if (!FunctionGroup.CheckInvalidArrayCoersion(this, reducedParamSVs, classTable, runtimeCore, allowArrayPromotion))
                {
                    return(dist);
                }
            }

            return((int)ProcedureDistance.kInvalidDistance);
        }
Ejemplo n.º 14
0
        public void SetClassTable(ProtoCore.DSASM.ClassTable table)
        {
            Validity.Assert(null != table);
            Validity.Assert(0 == table.ClassNodes.Count);

            if (0 != table.ClassNodes.Count)
            {
                return;
            }

            for (int i = 0; i < classTable.ClassNodes.Count; ++i)
            {
                table.Append(classTable.ClassNodes[i]);
            }
            classTable = table;
        }
Ejemplo n.º 15
0
            public MethodMirror GetDeclaredMethod(string methodName, List <ProtoCore.Type> argumentTypes)
            {
                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);

                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                return(StaticMirror.FindMethod(methodName, argumentTypes, procList));
            }
Ejemplo n.º 16
0
            public ClassMirror(string className, ProtoCore.Core core)
                : base(core)
            {
                if (core == null)
                {
                    return;
                }

                ClassName = className;

                if (classNode == null)
                {
                    ProtoCore.DSASM.ClassTable classTable = core.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }
                libraryMirror = new LibraryMirror(classNode.ExternLib, core);
            }
Ejemplo n.º 17
0
        /// <summary>
        /// Get a dictionary of the function end points that are type compatible
        /// with the costs of the associated conversions
        /// </summary>
        /// <param name="context"></param>
        /// <param name="formalParams"></param>
        /// <param name="replicationInstructions"></param>
        /// <returns></returns>
        public Dictionary <FunctionEndPoint, int> GetConversionDistances(ProtoCore.Runtime.Context context,
                                                                         List <StackValue> formalParams, List <ReplicationInstruction> replicationInstructions,
                                                                         ProtoCore.DSASM.ClassTable classTable, Core core, bool allowArrayPromotion = false)
        {
            Dictionary <FunctionEndPoint, int> ret = new Dictionary <FunctionEndPoint, int>();

            //@PERF: Consider parallelising this
            List <FunctionEndPoint> feps            = FunctionEndPoints;
            List <StackValue>       reducedParamSVs = Replicator.EstimateReducedParams(formalParams, replicationInstructions, core);

            foreach (FunctionEndPoint fep in feps)
            {
                int distance = fep.GetConversionDistance(reducedParamSVs, classTable, allowArrayPromotion, core);
                if (distance !=
                    (int)ProcedureDistance.kInvalidDistance)
                {
                    ret.Add(fep, distance);
                }
            }

            return(ret);
        }
Ejemplo n.º 18
0
            /// <summary>
            ///  Get the super class of this class
            /// </summary>
            /// <returns></returns>
            public ClassMirror GetSuperClass()
            {
                Validity.Assert(!string.IsNullOrEmpty(ClassName));
                Validity.Assert(staticCore != null);

                int ci;

                if (classNode == null)
                {
                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ci = classNode.baseList[0];
                Validity.Assert(ci != ProtoCore.DSASM.Constants.kInvalidIndex);

                return(new ClassMirror(staticCore, staticCore.ClassTable.ClassNodes[ci], this.libraryMirror));
            }
Ejemplo n.º 19
0
        public ClassTable(ClassTable rhs)
        {
            classNodes = new List<ClassNode>();
            for (int n = 0; n < rhs.classNodes.Count; ++n)
            {
                classNodes.Add(new ClassNode(rhs.classNodes[n]));
            }

            symbolTable = new Namespace.SymbolTable(rhs.symbolTable);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Given a partial class name, get assembly to which the class belongs
        /// </summary>
        /// <param name="classTable"> class table in Core </param>
        /// <param name="className"> class name </param>
        /// <returns> assembly to which the class belongs </returns>
        public static string GetAssemblyFromClassName(ClassTable classTable, string className)
        {
            //throw new NotImplementedException();
            var ci = classTable.IndexOf(className);

            if (ci == ProtoCore.DSASM.Constants.kInvalidIndex) 
                return string.Empty;
            
            var classNode = classTable.ClassNodes[ci];
            return classNode.ExternLib;
        }
Ejemplo n.º 21
0
        public static bool CheckInvalidArrayCoersion(FunctionEndPoint fep, List<StackValue> reducedSVs, ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion)
        {
            for (int i = 0; i < reducedSVs.Count; i++)
            {
                Type typ = fep.FormalParams[i];
                if (typ.UID == (int)ProtoCore.PrimitiveType.kInvalidType)
                    return true;

                if (!typ.IsIndexable)
                    continue; //It wasn't an array param, skip

                //Compute the type of target param
                if (!allowArrayPromotion)
                    Validity.Assert(reducedSVs[i].IsArray, "This should be an array otherwise this shouldn't have passed previous tests");


                if (!allowArrayPromotion)
                {
                    if (typ.rank != ArrayUtils.GetMaxRankForArray(reducedSVs[i], runtimeCore) &&
                        typ.rank != DSASM.Constants.kArbitraryRank)
                        return true; //Invalid co-ercsion
                }
                else
                {
                    if (typ.rank < ArrayUtils.GetMaxRankForArray(reducedSVs[i], runtimeCore) &&
                        typ.rank != DSASM.Constants.kArbitraryRank)
                        return true; //Invalid co-ercsion
                    
                }


                Dictionary<ClassNode, int> arrayTypes = ArrayUtils.GetTypeStatisticsForArray(reducedSVs[i], runtimeCore);

                ClassNode cn = null;

                if (arrayTypes.Count == 0)
                {
                    //This was an empty array
                    Validity.Assert(cn == null, "If it was an empty array, there shouldn't be a type node");
                    cn = runtimeCore.DSExecutable.classTable.ClassNodes[(int)PrimitiveType.kTypeNull];
                }
                else if (arrayTypes.Count == 1)
                {
                    //UGLY, get the key out of the array types, of which there is only one
                    foreach (ClassNode key in arrayTypes.Keys)
                        cn = key;
                }
                else if (arrayTypes.Count > 1)
                {
                    ClassNode commonBaseType = ArrayUtils.GetGreatestCommonSubclassForArray(reducedSVs[i], runtimeCore);

                    if (commonBaseType == null)
                        throw new ProtoCore.Exceptions.ReplicationCaseNotCurrentlySupported(
                            string.Format(Resources.ArrayWithNotSupported, "{0C644179-14F5-4172-8EF8-A2F3739901B2}"));

                    cn = commonBaseType; //From now on perform tests on the commmon base type
                }

    

                ClassNode argTypeNode = classTable.ClassNodes[typ.UID];

                //cn now represents the class node of the argument
                //argTypeNode represents the class node of the argument



                bool isNotExactTypeMatch = cn != argTypeNode;
                bool argumentsNotNull = cn != runtimeCore.DSExecutable.classTable.ClassNodes[(int) PrimitiveType.kTypeNull];
                bool recievingTypeNotAVar = argTypeNode != runtimeCore.DSExecutable.classTable.ClassNodes[(int) PrimitiveType.kTypeVar];
                bool isNotConvertible = !cn.ConvertibleTo(typ.UID);
                
                //bool isCalleeVar = cn == core.classTable.list[(int) PrimitiveType.kTypeVar];
                

                //Is it an invalid conversion?
                if (isNotExactTypeMatch && argumentsNotNull && recievingTypeNotAVar && isNotConvertible)// && !isCalleeVar)
                {
                    return true; //It's an invalid coersion

                }


            }

            return false;


        }
Ejemplo n.º 22
0
 public ElementRewriter(ClassTable classTable, SymbolConflictWarningHandler warningHandler, ElementResolver resolver = null)
 {
     this.classTable = classTable;
     this.symbolConflictHandler = warningHandler;
     this.elementResolver = resolver ?? new ElementResolver();
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Compute the number of type transforms needed to turn the current type into the target type
        /// Note that this method returns int[] -> char[] as an exact match
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public int ComputeTypeDistance(List <StackValue> args, ProtoCore.DSASM.ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion = false)
        {
            if (args.Count == 0 && FormalParams.Length == 0)
            {
                return((int)ProcedureDistance.ExactMatchDistance);
            }

            if (args.Count != FormalParams.Length)
            {
                return((int)ProcedureDistance.MaxDistance);
            }

            int distance = (int)ProcedureDistance.MaxDistance;

            // Jun Comment:
            // Default args not provided by the caller would have been pushed by the call instruction as optype = DefaultArs
            for (int i = 0; i < args.Count; ++i)
            {
                int rcvdType = args[i].metaData.type;

                // If its a default argumnet, then it wasnt provided by the caller
                // The rcvdType is the type of the argument signature
                if (args[i].IsDefaultArgument)
                {
                    rcvdType = FormalParams[i].UID;
                }

                int expectedType = FormalParams[i].UID;
                int currentScore = (int)ProcedureDistance.NotMatchScore;

                //sv rank > param rank
                if (allowArrayPromotion)
                {
                    //stop array -> single
                    if (args[i].IsArray && !FormalParams[i].IsIndexable) //Replication code will take care of this
                    {
                        distance = (int)ProcedureDistance.MaxDistance;
                        break;
                    }
                }
                else
                {
                    //stop array -> single && single -> array
                    if (args[i].IsArray != FormalParams[i].IsIndexable)
                    //Replication code will take care of this
                    {
                        distance = (int)ProcedureDistance.MaxDistance;
                        break;
                    }
                }

                if (FormalParams[i].IsIndexable && (FormalParams[i].IsIndexable == args[i].IsArray))
                {
                    //In case of conversion from double to int, add a conversion score.
                    //There are overloaded methods and the difference is the parameter type between int and double.
                    //Add this to make it call the correct one. - Randy
                    bool bContainsDouble = ArrayUtils.ContainsDoubleElement(args[i], runtimeCore);
                    if (FormalParams[i].UID == (int)PrimitiveType.Integer && bContainsDouble)
                    {
                        currentScore = (int)ProcedureDistance.CoerceDoubleToIntScore;
                    }
                    else if (FormalParams[i].UID == (int)PrimitiveType.Double && !bContainsDouble)
                    {
                        currentScore = (int)ProcedureDistance.CoerceIntToDoubleScore;
                    }
                    else
                    {
                        currentScore = (int)ProcedureDistance.ExactMatchScore;
                    }
                }
                else if (expectedType == rcvdType && (FormalParams[i].IsIndexable == args[i].IsArray))
                {
                    currentScore = (int)ProcedureDistance.ExactMatchScore;
                }
                else if (rcvdType != ProtoCore.DSASM.Constants.kInvalidIndex)
                {
                    currentScore = classTable.ClassNodes[rcvdType].GetCoercionScore(expectedType);
                    if (currentScore == (int)ProcedureDistance.NotMatchScore)
                    {
                        distance = (int)ProcedureDistance.MaxDistance;
                        break;
                    }
                }
                distance -= currentScore;
            }
            return(distance);
        }
Ejemplo n.º 24
0
        internal int ComputeCastDistance(List<StackValue> args, ClassTable classTable, RuntimeCore runtimeCore)
        {
            //Compute the cost to migrate a class calls argument types to the coresponding base types
            //This cannot be used to determine whether a function can be called as it will ignore anything that doesn't
            //it should only be used to determine which class is closer
            if (args.Count != FormalParams.Length)
            {
                return int.MaxValue;
            }

            if (0 == args.Count)
            {
                return 0;
            }
            else
            {
                int distance = 0;
                // Check if all the types match the current function at 'n'
                for (int i = 0; i < args.Count; ++i)
                {
                    int rcvdType = args[i].metaData.type;

                    // If its a default argumnet, then it wasnt provided by the caller
                    // The rcvdType is the type of the argument signature
                    if (args[i].IsDefaultArgument)
                    {
                        rcvdType = FormalParams[i].UID;
                    }

                    int expectedType = FormalParams[i].UID;

                    if (FormalParams[i].IsIndexable != args[i].IsArray) //Replication code will take care of this
                    {
                        continue;
                    }
                    else if (FormalParams[i].IsIndexable)  // both are arrays
                    {
                        continue;
                    }
                    else if (expectedType == rcvdType)
                    {
                        continue;
                    }
                    else if (rcvdType != Constants.kInvalidIndex && expectedType != Constants.kInvalidIndex)
                    {
                        int currentCost = ClassUtils.GetUpcastCountTo(
                            classTable.ClassNodes[rcvdType], 
                            classTable.ClassNodes[expectedType], 
                            runtimeCore);
                        distance += currentCost;
                    }
                }
                return distance;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Returns a dictionary of the function end points that are type compatible
        /// with any branch of replicated parameters. 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="formalParams"></param>
        /// <param name="replicationInstructions"></param>
        /// <param name="classTable"></param>
        /// <param name="runtimeCore"></param>
        /// <returns></returns>
        public Dictionary<FunctionEndPoint, int> GetLooseConversionDistances(
            Runtime.Context context,
            List<StackValue> formalParams,
            List<ReplicationInstruction> replicationInstructions,
            ClassTable classTable,
            RuntimeCore runtimeCore)
        {
            Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>();
            var reducedParams = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, runtimeCore);

            foreach (FunctionEndPoint fep in FunctionEndPoints)
            {
                foreach (var reducedParam in reducedParams)
                {
                    int distance = fep.GetConversionDistance(reducedParam, classTable, true, runtimeCore);
                    if (distance != (int)ProcedureDistance.InvalidDistance)
                    {
                        ret.Add(fep, distance);
                        break;
                    } 
                }
            }

            return ret;
        }
Ejemplo n.º 26
0
        public void SetTypeSystem()
        {
            Validity.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.kMaxPrimitives);

            ClassNode cnode;

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Array, size = 0, rank = 5, symbols = null, vtable = null, typeSystem = this
            };

            /*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
             * cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
             * cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
             * cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
             * cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
             */
            cnode.classId = (int)PrimitiveType.kTypeArray;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Double, size = 0, rank = 4, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
            cnode.classId = (int)PrimitiveType.kTypeDouble;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Int, size = 0, rank = 3, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
            cnode.classId = (int)PrimitiveType.kTypeInt;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Bool, size = 0, rank = 2, symbols = null, vtable = null, typeSystem = this
            };
            // if convert operator to method call, without the following statement
            // a = true + 1 will fail, because _add expects two integers
            //cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeBool;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Char, size = 0, rank = 1, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);

            cnode.classId = (int)PrimitiveType.kTypeChar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.String, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeString;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Var, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };

            /*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            *  cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            *  cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            *  cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            *  cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);*/
            cnode.classId = (int)PrimitiveType.kTypeVar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVar);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Null, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeNull;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);

            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Void, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeVoid;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVoid);

            //
            //
            cnode = new ClassNode {
                name = "hostentityid", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeHostEntityID;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeHostEntityID);
            //
            //
            cnode = new ClassNode {
                name = "pointer_reserved", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            // if convert operator to method call, without the following statement,
            // a = b.c + d.e will fail, b.c and d.e are resolved as pointer and _add method requires two integer
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypePointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypePointer);
            //
            //
            cnode = new ClassNode {
                name = DSDefinitions.Keyword.FunctionPointer, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeFunctionPointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeFunctionPointer);

            //
            //
            cnode = new ClassNode {
                name = "return_reserved", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeReturn;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeReturn);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Compute the number of type transforms needed to turn the current type into the target type
        /// Note that this method returns int[] -> char[] as an exact match
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public int ComputeTypeDistance(List <StackValue> args, ProtoCore.DSASM.ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion = false)
        {
            //Modified from proc Table, does not use quite the same arguments

            int distance = (int)ProcedureDistance.kMaxDistance;

            if (0 == args.Count && 0 == FormalParams.Length)
            {
                distance = (int)ProcedureDistance.kExactMatchDistance;
            }
            else
            {
                // Jun Comment:
                // Default args not provided by the caller would have been pushed by the call instruction as optype = DefaultArs
                if (FormalParams.Length == args.Count)
                {
                    // Check if all the types match the current function at 'n'
                    for (int i = 0; i < args.Count; ++i)
                    {
                        int rcvdType = args[i].metaData.type;

                        // If its a default argumnet, then it wasnt provided by the caller
                        // The rcvdType is the type of the argument signature
                        if (args[i].IsDefaultArgument)
                        {
                            rcvdType = FormalParams[i].UID;
                        }

                        int expectedType = FormalParams[i].UID;
                        int currentScore = (int)ProcedureDistance.kNotMatchScore;

                        //Fuqiang: For now disable rank check
                        //if function is expecting array, but non-array or array of lower rank is passed, break.
                        //if (args[i].rank != -1 && args[i].UID != (int)PrimitiveType.kTypeVar && args[i].rank < argTypeList[i].rank)

                        //Only enable type check, and array and non-array check

                        /*  SUSPECTED REDUNDANT Luke,Jun
                         * if (args[i].rank != -1 && args[i].UID != (int)PrimitiveType.kTypeVar && !args[i].IsIndexable && FormalParams[i].IsIndexable)
                         * {
                         *   distance = (int)ProcedureDistance.kMaxDistance;
                         *   break;
                         * }
                         * else */

                        //sv rank > param rank

                        if (allowArrayPromotion)
                        {
                            //stop array -> single
                            if (args[i].IsArray && !FormalParams[i].IsIndexable) //Replication code will take care of this
                            {
                                distance = (int)ProcedureDistance.kMaxDistance;
                                break;
                            }
                        }
                        else
                        {
                            //stop array -> single && single -> array
                            if (args[i].IsArray != FormalParams[i].IsIndexable)
                            //Replication code will take care of this
                            {
                                distance = (int)ProcedureDistance.kMaxDistance;
                                break;
                            }
                        }

                        if (FormalParams[i].IsIndexable && (FormalParams[i].IsIndexable == args[i].IsArray))
                        {
                            //In case of conversion from double to int, add a conversion score.
                            //There are overloaded methods and the difference is the parameter type between int and double.
                            //Add this to make it call the correct one. - Randy
                            bool bContainsDouble = ArrayUtils.ContainsDoubleElement(args[i], runtimeCore);
                            if (FormalParams[i].UID == (int)PrimitiveType.kTypeInt && bContainsDouble)
                            {
                                currentScore = (int)ProcedureDistance.kCoerceDoubleToIntScore;
                            }
                            else if (FormalParams[i].UID == (int)PrimitiveType.kTypeDouble && !bContainsDouble)
                            {
                                currentScore = (int)ProcedureDistance.kCoerceIntToDoubleScore;
                            }
                            else
                            {
                                currentScore = (int)ProcedureDistance.kExactMatchScore;
                            }
                        }
                        else if (expectedType == rcvdType && (FormalParams[i].IsIndexable == args[i].IsArray))
                        {
                            currentScore = (int)ProcedureDistance.kExactMatchScore;
                        }
                        else if (rcvdType != ProtoCore.DSASM.Constants.kInvalidIndex)
                        {
                            currentScore = classTable.ClassNodes[rcvdType].GetCoercionScore(expectedType);
                            if (currentScore == (int)ProcedureDistance.kNotMatchScore)
                            {
                                distance = (int)ProcedureDistance.kMaxDistance;
                                break;
                            }
                        }
                        distance -= currentScore;
                    }
                }
            }
            return(distance);
        }
Ejemplo n.º 28
0
        private void ResetAll(Options options)
        {
            ProtoCore.Utils.Validity.AssertExpiry();
            Options = options;
            Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>();
            FunctionTable = new Lang.FunctionTable();
            ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex;

            Heap = new DSASM.Heap();
            Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap);

            watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex;
            watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex;
            watchBaseOffset = 0;
            watchStack = new List<StackValue>();
            watchSymbolList = new List<SymbolNode>();
            watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex;

            ID = FIRST_CORE_ID;

            //recurtion
            recursivePoint = new List<FunctionCounter>();
            funcCounterTable = new List<FunctionCounter>();
            calledInFunction = false;

            GlobOffset = 0;
            GlobHeapOffset = 0;
            BaseOffset = 0;
            GraphNodeUID = 0;
            RunningBlock = 0;
            CodeBlockIndex = 0;
            RuntimeTableIndex = 0;
            CodeBlockList = new List<DSASM.CodeBlock>();
            CompleteCodeBlockList = new List<DSASM.CodeBlock>();
            DSExecutable = new ProtoCore.DSASM.Executable();

            AssocNode = null;

            // TODO Jun/Luke type system refactoring
            // Initialize the globalClass table and type system
            ClassTable = new DSASM.ClassTable();
            TypeSystem = new TypeSystem();
            TypeSystem.SetClassTable(ClassTable);
            ProcNode = null;
            ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope);

            //Initialize the function pointer table
            FunctionPointerTable = new DSASM.FunctionPointerTable();

            //Initialize the dynamic string table and dynamic function table
            DynamicVariableTable = new DSASM.DynamicVariableTable();
            DynamicFunctionTable = new DSASM.DynamicFunctionTable();
            replicationGuides = new List<List<int>>();

            ExceptionHandlingManager = new ExceptionHandlingManager();
            startPC = ProtoCore.DSASM.Constants.kInvalidIndex;

            deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex;

            RuntimeStatus = new RuntimeStatus(this);

            SSASubscript = 0;
            ExpressionUID = 0;
            ModifierBlockUID = 0;
            ModifierStateSubscript = 0;

            ExprInterpreterExe = null;
            ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            assocCodegen = null;
            FunctionCallDepth = 0;

            // Default execution log is Console.Out.
            this.ExecutionLog = Console.Out;
            ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started

            DebugProps = new DebugProperties();
            //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>();
            //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>();
            InterpreterProps = new Stack<InterpreterProperties>();
            stackActiveExceptionRegistration = new Stack<ExceptionRegistration>();

            ExecutiveProvider = new ExecutiveProvider();

            Configurations = new Dictionary<string, object>();

            ContinuationStruct = new Lang.ContinuationStructure();
            ParsingMode = ProtoCore.ParseMode.Normal;

            IsParsingPreloadedAssembly = false;
            IsParsingCodeBlockNode = false;
            ImportHandler = null;

            deltaCompileStartPC = 0;
            builtInsLoaded = false;
            FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this);
        }
Ejemplo n.º 29
0
 public InternalAttributes(ProtoCore.DSASM.ClassTable classTable)
 {
     this.ClassTable = classTable;
     BuildInteralAttributes();
 }
Ejemplo n.º 30
0
        private void ResetAll(Options options)
        {
            Heap = new Heap();
            //Rmem = new RuntimeMemory(Heap);
            Configurations = new Dictionary<string, object>();
            DllTypesToLoad = new List<System.Type>();

            Options = options;
            
            Compilers = new Dictionary<Language, Compiler>();
            ClassIndex = Constants.kInvalidIndex;

            FunctionTable = new FunctionTable(); 


            watchFunctionScope = Constants.kInvalidIndex;
            watchSymbolList = new List<SymbolNode>();
            watchBaseOffset = 0;


            GlobOffset = 0;
            GlobHeapOffset = 0;
            BaseOffset = 0;
            GraphNodeUID = 0;
            CodeBlockIndex = 0;
            RuntimeTableIndex = 0;
            CodeBlockList = new List<CodeBlock>();
            CompleteCodeBlockList = new List<CodeBlock>();
            CallsiteGuidMap = new Dictionary<Guid, int>();

            AssocNode = null;

            // TODO Jun/Luke type system refactoring
            // Initialize the globalClass table and type system
            ClassTable = new ClassTable();
            TypeSystem = new TypeSystem();
            TypeSystem.SetClassTable(ClassTable);
            ProcNode = null;
            ProcTable = new ProcedureTable(Constants.kGlobalScope);

            // Initialize internal attributes
            internalAttributes = new InternalAttributes(ClassTable);

            //Initialize the function pointer table
            FunctionPointerTable = new FunctionPointerTable();

            //Initialize the dynamic string table and dynamic function table
            DynamicVariableTable = new DynamicVariableTable();
            DynamicFunctionTable = new DynamicFunctionTable();

            watchStartPC = Constants.kInvalidIndex;

            deltaCompileStartPC = Constants.kInvalidIndex;

            BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning);

            SSAExpressionUID = 0;
            SSASubscript = 0;
            SSASubscript_GUID = Guid.NewGuid();
            SSAExprUID = 0;
            ExpressionUID = 0;
            ModifierBlockUID = 0;
            ModifierStateSubscript = 0;

            ExprInterpreterExe = null;
            Options.RunMode = InterpreterMode.Normal;

            assocCodegen = null;

            // Default execution log is Console.Out.
            ExecutionLog = Console.Out;

            DebuggerProperties = new DebugProperties();


            ParsingMode = ParseMode.Normal;
            
            IsParsingPreloadedAssembly = false;
            IsParsingCodeBlockNode = false;
            ImportHandler = null;

            deltaCompileStartPC = 0;
            builtInsLoaded = false;


            ForLoopBlockIndex = Constants.kInvalidIndex;

            GraphNodeCallList = new List<GraphNode>();
            InlineConditionalBodyGraphNodes = new Stack<List<GraphNode>>();

            newEntryPoint = Constants.kInvalidIndex;
        }
Ejemplo n.º 31
0
 public InternalAttributes(ProtoCore.DSASM.ClassTable classTable)
 {
     this.ClassTable = classTable;
     BuildInteralAttributes();
 }
Ejemplo n.º 32
0
        public void SetTypeSystem()
        {
            Validity.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.MaxPrimitive);

            ClassNode cnode;

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Array, Rank = 5, TypeSystem = this
            };
            cnode.ID = (int)PrimitiveType.Array;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Array);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Double, Rank = 4, TypeSystem = this
            };
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "num");
            cnode.CoerceTypes.Add((int)PrimitiveType.Bool, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.Integer, (int)ProtoCore.DSASM.ProcedureDistance.CoerceDoubleToIntScore);
            cnode.ID = (int)PrimitiveType.Double;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Double);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Int, Rank = 3, TypeSystem = this
            };
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "num");
            cnode.CoerceTypes.Add((int)PrimitiveType.Bool, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.Double, (int)ProtoCore.DSASM.ProcedureDistance.CoerceIntToDoubleScore);
            cnode.ID = (int)PrimitiveType.Integer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Integer);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Bool, Rank = 2, TypeSystem = this
            };
            cnode.ID = (int)PrimitiveType.Bool;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "bool");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Bool);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Char, Rank = 1, TypeSystem = this
            };
            cnode.CoerceTypes.Add((int)PrimitiveType.Bool, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.String, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);

            cnode.ID = (int)PrimitiveType.Char;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Char);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.String, Rank = 0, TypeSystem = this
            };
            cnode.CoerceTypes.Add((int)PrimitiveType.Bool, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.ID = (int)PrimitiveType.String;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "str");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.String);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Var, Rank = 0, TypeSystem = this
            };
            cnode.ID = (int)PrimitiveType.Var;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Var);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Null, Rank = 0, TypeSystem = this
            };
            cnode.CoerceTypes.Add((int)PrimitiveType.Double, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.Integer, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.Bool, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.Char, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.String, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.ID = (int)PrimitiveType.Null;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Null);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Void, Rank = 0, TypeSystem = this
            };
            cnode.ID = (int)PrimitiveType.Void;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Void);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.PointerReserved, Rank = 0, TypeSystem = this
            };
            cnode.CoerceTypes.Add((int)PrimitiveType.Integer, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.ID = (int)PrimitiveType.Pointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Pointer);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.FunctionPointer, Rank = 0, TypeSystem = this
            };
            cnode.CoerceTypes.Add((int)PrimitiveType.Integer, (int)ProtoCore.DSASM.ProcedureDistance.CoerceScore);
            cnode.ID = (int)PrimitiveType.FunctionPointer;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "func");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.FunctionPointer);

            cnode = new ClassNode {
                Name = DSDefinitions.Keyword.Return, Rank = 0, TypeSystem = this
            };
            cnode.ID = (int)PrimitiveType.Return;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.Return);
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Lookup namespace resolution map to substitute 
 /// partial classnames with their fully qualified names in ASTs.
 /// If partial class is not found in map, 
 /// update ResolutionMap with fully resolved name from compiler.
 /// </summary>
 /// <param name="classTable"></param>
 /// <param name="handler"></param>
 /// <param name="elementResolver"></param>
 /// <param name="astNodes"> parent AST node </param>
 public static IEnumerable<Node> RewriteElementNames(ClassTable classTable, 
     ElementResolver elementResolver, IEnumerable<Node> astNodes, SymbolConflictWarningHandler handler = null)
 {
     var elementRewriter = new ElementRewriter(classTable, handler, elementResolver);
     return astNodes.OfType<AssociativeNode>().Select(astNode => astNode.Accept(elementRewriter)).Cast<Node>().ToList();
 }
Ejemplo n.º 34
0
        public void SetTypeSystem()
        {
            Validity.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.kMaxPrimitives);

            ClassNode cnode;

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Array, rank = 5, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeArray;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Double, rank = 4, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
            cnode.classId = (int)PrimitiveType.kTypeDouble;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Int, rank = 3, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
            cnode.classId = (int)PrimitiveType.kTypeInt;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Bool, rank = 2, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeBool;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Char, rank = 1, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);

            cnode.classId = (int)PrimitiveType.kTypeChar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.String, rank = 0, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeString;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Var, rank = 0, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeVar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVar);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Null, rank = 0, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeNull;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.Void, rank = 0, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeVoid;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVoid);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.PointerReserved, rank = 0, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypePointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypePointer);

            cnode = new ClassNode {
                name = DSDefinitions.Keyword.FunctionPointer, rank = 0, typeSystem = this
            };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeFunctionPointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeFunctionPointer);

            cnode = new ClassNode {
                name = "return_reserved", rank = 0, typeSystem = this
            };
            cnode.classId = (int)PrimitiveType.kTypeReturn;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeReturn);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Get a dictionary of the function end points that are type compatible
        /// with the costs of the associated conversions
        /// </summary>
        /// <param name="context"></param>
        /// <param name="formalParams"></param>
        /// <param name="replicationInstructions"></param>
        /// <returns></returns>
        public Dictionary<FunctionEndPoint, int> GetConversionDistances(Runtime.Context context,
            List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, 
            ClassTable classTable, RuntimeCore runtimeCore, bool allowArrayPromotion = false)
        {
            Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>();

            //@PERF: Consider parallelising this
            List<FunctionEndPoint> feps = FunctionEndPoints;
            List<StackValue> reducedParamSVs = Replicator.EstimateReducedParams(formalParams, replicationInstructions, runtimeCore);

            foreach (FunctionEndPoint fep in feps)
            {
                int distance = fep.GetConversionDistance(reducedParamSVs, classTable, allowArrayPromotion, runtimeCore);
                if (distance != 
                    (int)ProcedureDistance.kInvalidDistance)
                    ret.Add(fep, distance);
            }

            return ret;
        }
Ejemplo n.º 36
0
        public void SetClassTable(ProtoCore.DSASM.ClassTable table)
        {
            Debug.Assert(null != table);
            Debug.Assert(0 == table.ClassNodes.Count);

            if (0 != table.ClassNodes.Count)
            {
                return;
            }

            for (int i = 0; i < classTable.ClassNodes.Count; ++i)
            {
                table.Append(classTable.ClassNodes[i]);
            }
            classTable = table;
        }
Ejemplo n.º 37
0
        public Dictionary<FunctionEndPoint, int> GetCastDistances(ProtoCore.Runtime.Context context, List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, ClassTable classTable, RuntimeCore runtimeCore)
        {
            Dictionary<FunctionEndPoint, int> ret = new Dictionary<FunctionEndPoint, int>();

            //@PERF: Consider parallelising this
            List<FunctionEndPoint> feps = FunctionEndPoints;
            List<StackValue> reducedParamSVs = Replicator.EstimateReducedParams(formalParams, replicationInstructions, runtimeCore);

            foreach (FunctionEndPoint fep in feps)
            {
                int dist = fep.ComputeCastDistance(reducedParamSVs, classTable, runtimeCore);
                ret.Add(fep, dist);
            }

            return ret;
        }
Ejemplo n.º 38
0
        public void SetTypeSystem()
        {
            Debug.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.kMaxPrimitives);

            ProtoCore.DSASM.ClassNode cnode;

            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Array, size = 0, rank = 5, symbols = null, vtable = null, typeSystem = this };
            /*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            */
            cnode.classId = (int)PrimitiveType.kTypeArray;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Double, size = 0, rank = 4, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
            cnode.classId = (int)PrimitiveType.kTypeDouble;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Int, size = 0, rank = 3, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
            cnode.classId = (int)PrimitiveType.kTypeInt;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Bool, size = 0, rank = 2, symbols = null, vtable = null, typeSystem = this };
            // if convert operator to method call, without the following statement
            // a = true + 1 will fail, because _add expects two integers
            //cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeBool;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Char, size = 0, rank = 1, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);

            cnode.classId = (int)PrimitiveType.kTypeChar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.String, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeString;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Var, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            /*cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);*/
            cnode.classId = (int)PrimitiveType.kTypeVar;
            classTable.SetClassNodeAt(cnode,(int)PrimitiveType.kTypeVar);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Null, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeNull;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.Void, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeVoid;
            classTable.SetClassNodeAt(cnode,(int)PrimitiveType.kTypeVoid);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = "hostentityid", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeHostEntityID;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeHostEntityID);
            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = "pointer_reserved", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            // if convert operator to method call, without the following statement,
            // a = b.c + d.e will fail, b.c and d.e are resolved as pointer and _add method requires two integer
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypePointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypePointer);
            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = DSDefinitions.Keyword.FunctionPointer, size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeFunctionPointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeFunctionPointer);

            //
            //
            cnode = new ProtoCore.DSASM.ClassNode { name = "return_reserved", size = 0, rank = 0, symbols = null, vtable = null, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeReturn;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeReturn);
        }
Ejemplo n.º 39
0
        public void SetTypeSystem()
        {
            Validity.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.kMaxPrimitives);

            ClassNode cnode;

            cnode = new ClassNode { name = DSDefinitions.Keyword.Array, rank = 5, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeArray;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Double, rank = 4, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
            cnode.classId = (int)PrimitiveType.kTypeDouble;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Int, rank = 3, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
            cnode.classId = (int)PrimitiveType.kTypeInt;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Bool, rank = 2, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeBool;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Char, rank = 1, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);

            cnode.classId = (int)PrimitiveType.kTypeChar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);

            cnode = new ClassNode { name = DSDefinitions.Keyword.String, rank = 0, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeString;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Var, rank = 0, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeVar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVar);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Null, rank = 0, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeNull;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);

            cnode = new ClassNode { name = DSDefinitions.Keyword.Void, rank = 0, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeVoid;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVoid);

            cnode = new ClassNode { name = DSDefinitions.Keyword.PointerReserved, rank = 0, typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypePointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypePointer);

            cnode = new ClassNode { name = DSDefinitions.Keyword.FunctionPointer, rank = 0,typeSystem = this };
            cnode.coerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.classId = (int)PrimitiveType.kTypeFunctionPointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeFunctionPointer);

            cnode = new ClassNode { name = "return_reserved", rank = 0, typeSystem = this };
            cnode.classId = (int)PrimitiveType.kTypeReturn;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeReturn);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Inspects the input identifier list to match all class names with the class used in it
        /// </summary>
        /// <param name="classTable"></param>
        /// <param name="identifierList">single identifier or identifier list</param>
        /// <returns>list of fully resolved class names</returns>
        public static string[] GetResolvedClassName(ClassTable classTable, AssociativeNode identifierList)
        {
            var identListNode = identifierList as IdentifierListNode;
            var identifierNode = identifierList as IdentifierNode;
            Validity.Assert(identListNode != null || identifierNode != null);

            string partialName = identListNode != null ? 
                GetIdentifierStringUntilFirstParenthesis(identListNode) : identifierList.Name;

            string[] classNames = classTable.GetAllMatchingClasses(partialName);

            // Failed to find the first time
            // Attempt to remove identifiers in the identifierlist until we find a class or not
            while (0 == classNames.Length)
            {
                // Move to the left node
                AssociativeNode leftNode = identListNode != null ? identListNode.LeftNode : identifierNode;
                if (leftNode is IdentifierListNode)
                {
                    identListNode = leftNode as IdentifierListNode;
                    classNames = classTable.GetAllMatchingClasses(GetIdentifierStringUntilFirstParenthesis(identListNode));
                }
                if (leftNode is IdentifierNode)
                {
                    classNames = classTable.GetAllMatchingClasses(leftNode.Name);
                    break;
                }
                else
                {
                    break;
                }
            }
            return classNames;
        }
Ejemplo n.º 41
0
        public void SetTypeSystem()
        {
            Validity.Assert(null == classTable);
            if (null != classTable)
            {
                return;
            }

            classTable = new DSASM.ClassTable();

            classTable.Reserve((int)PrimitiveType.kMaxPrimitives);

            ClassNode cnode;

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Array, Rank = 5, TypeSystem = this };
            cnode.ID = (int)PrimitiveType.kTypeArray;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeArray);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Double, Rank = 4, TypeSystem = this };
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "num");
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceDoubleToIntScore);
            cnode.ID = (int)PrimitiveType.kTypeDouble;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeDouble);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Int, Rank = 3, TypeSystem = this };
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "num");
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceIntToDoubleScore);
            cnode.ID = (int)PrimitiveType.kTypeInt;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeInt);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Bool, Rank = 2, TypeSystem = this };
            cnode.ID = (int)PrimitiveType.kTypeBool;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "bool");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeBool);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Char, Rank = 1, TypeSystem = this };
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);

            cnode.ID = (int)PrimitiveType.kTypeChar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeChar);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.String, Rank = 0, TypeSystem = this };
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.ID = (int)PrimitiveType.kTypeString;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "str");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeString);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Var, Rank = 0, TypeSystem = this };
            cnode.ID = (int)PrimitiveType.kTypeVar;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVar);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Null, Rank = 0, TypeSystem = this };
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeDouble, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeBool, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeChar, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeString, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.ID = (int)PrimitiveType.kTypeNull;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeNull);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.Void, Rank = 0, TypeSystem = this };
            cnode.ID = (int)PrimitiveType.kTypeVoid;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeVoid);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.PointerReserved, Rank = 0, TypeSystem = this };
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.ID = (int)PrimitiveType.kTypePointer;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypePointer);

            cnode = new ClassNode { Name = DSDefinitions.Keyword.FunctionPointer, Rank = 0,TypeSystem = this };
            cnode.CoerceTypes.Add((int)PrimitiveType.kTypeInt, (int)ProtoCore.DSASM.ProcedureDistance.kCoerceScore);
            cnode.ID = (int)PrimitiveType.kTypeFunctionPointer;
            cnode.ClassAttributes = new AST.AssociativeAST.ClassAttributes("", "func");
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeFunctionPointer);

            cnode = new ClassNode { Name = "return_reserved", Rank = 0, TypeSystem = this };
            cnode.ID = (int)PrimitiveType.kTypeReturn;
            classTable.SetClassNodeAt(cnode, (int)PrimitiveType.kTypeReturn);
        }
Ejemplo n.º 42
0
        private void ResetAll(Options options)
        {
            ProtoCore.Utils.Validity.AssertExpiry();
            Options = options;
            Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>();
            FunctionTable = new Lang.FunctionTable();
            ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex;

            Heap = new DSASM.Heap();
            Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap);

            watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex;
            watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex;
            watchBaseOffset = 0;
            watchStack = new List<StackValue>();
            watchSymbolList = new List<SymbolNode>();
            watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex;

            ID = FIRST_CORE_ID;

            //recurtion
            recursivePoint = new List<FunctionCounter>();
            funcCounterTable = new List<FunctionCounter>();
            calledInFunction = false;

            GlobOffset = 0;
            GlobHeapOffset = 0;
            BaseOffset = 0;
            GraphNodeUID = 0;
            RunningBlock = 0;
            CodeBlockIndex = 0;
            RuntimeTableIndex = 0;
            CodeBlockList = new List<DSASM.CodeBlock>();
            CompleteCodeBlockList = new List<DSASM.CodeBlock>();
            DSExecutable = new ProtoCore.DSASM.Executable();

            AssocNode = null;

            // TODO Jun/Luke type system refactoring
            // Initialize the globalClass table and type system
            ClassTable = new DSASM.ClassTable();
            TypeSystem = new TypeSystem();
            TypeSystem.SetClassTable(ClassTable);
            ProcNode = null;
            ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope);

            //Initialize the function pointer table
            FunctionPointerTable = new DSASM.FunctionPointerTable();

            //Initialize the dynamic string table and dynamic function table
            DynamicVariableTable = new DSASM.DynamicVariableTable();
            DynamicFunctionTable = new DSASM.DynamicFunctionTable();
            replicationGuides = new List<List<ProtoCore.ReplicationGuide>>();

            ExceptionHandlingManager = new ExceptionHandlingManager();
            startPC = ProtoCore.DSASM.Constants.kInvalidIndex;

            deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex;

            if (options.SuppressBuildOutput)
            {
                //  don't log any of the build related messages
                //  just accumulate them in relevant containers with
                //  BuildStatus object
                //
                BuildStatus = new BuildStatus(this, false, false, false);
            }
            else
            {
                BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning);
            }
            RuntimeStatus = new RuntimeStatus(this);

            SSASubscript = 0;
            SSASubscript_GUID = System.Guid.NewGuid();
            ExpressionUID = 0;
            ModifierBlockUID = 0;
            ModifierStateSubscript = 0;

            ExprInterpreterExe = null;
            ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal;

            assocCodegen = null;
            FunctionCallDepth = 0;

            // Default execution log is Console.Out.
            this.ExecutionLog = Console.Out;
            ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started

            DebugProps = new DebugProperties();
            //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>();
            //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>();
            InterpreterProps = new Stack<InterpreterProperties>();
            stackActiveExceptionRegistration = new Stack<ExceptionRegistration>();

            ExecutiveProvider = new ExecutiveProvider();

            Configurations = new Dictionary<string, object>();

            ContinuationStruct = new Lang.ContinuationStructure();
            ParsingMode = ProtoCore.ParseMode.Normal;
            
            IsParsingPreloadedAssembly = false;
            IsParsingCodeBlockNode = false;
            ImportHandler = null;

            deltaCompileStartPC = 0;
            builtInsLoaded = false;
            FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this);

            csExecutionState = null;
            EnableCallsiteExecutionState = false;

            // TODO: Remove check once fully implemeted
            if (EnableCallsiteExecutionState)
            {
                csExecutionState = CallsiteExecutionState.LoadState();
            }
            else
            {
                csExecutionState = new CallsiteExecutionState();
            }
            CallsiteCache = new Dictionary<int, CallSite>();
            CachedSSANodes = new List<AssociativeNode>();
            CallSiteToNodeMap = new Dictionary<Guid, Guid>();
            ASTToCallSiteMap = new Dictionary<int, CallSite>();

            ForLoopBlockIndex = ProtoCore.DSASM.Constants.kInvalidIndex;

            GraphNodeCallList = new List<GraphNode>();

            newEntryPoint = ProtoCore.DSASM.Constants.kInvalidIndex;
        }