Exemplo n.º 1
0
        private static void AddSledSpecificFunctions(LuatTable table)
        {
            if (table == null)
                return;

            // add libsleddebugger table
            {
                var debuggerTable = new LuatTable { Description = "libsleddebugger injected functionality" };

                debuggerTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                debuggerTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                table.AddChild("libsleddebugger", debuggerTable);
            }

            // add libsledluaplugin table
            {
                var luaPluginTable = new LuatTable { Description = "libsledluaplugin injected functionality" };

                luaPluginTable.AddChild("version", new LuatLiteral(LuatTypeString.Instance));
                luaPluginTable.AddChild("instance", new LuatLiteral(LuatTypeNumber.Instance));

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "message" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("tty", function);
                }

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "condition", "message" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("assert", function);
                }

                {
                    var retVal = new LuatVariable(null, LuatTypeNil.Instance, LuatVariableFlags.None);
                    var function = new LuatFunction(retVal, new[] { "error" }) { ExpectsSelf = false };
                    luaPluginTable.AddChild("errorhandler", function);
                }

                table.AddChild("libsledluaplugin", luaPluginTable);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a variable to the unresolved type list
        /// </summary>
        /// <param name="variable"></param>
        /// <returns></returns>
        public bool AddUnresolvedVariableType(LuatVariable variable)
        {
            if (m_unresolvedVariableTypes.Contains(variable))
            {
                return(false);
            }

            if (!variable.IsFixedType)
            {
                variable.Type = LuatTypeUnknown.Instance;
            }

            m_unresolvedVariableTypes.Add(variable);

            foreach (LuatValue.IReference reference in variable.References)
            {
                reference.OnTypeInvalidated();
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to resolve (or infer) the variable type
        /// </summary>
        /// <param name="variable"></param>
        /// <returns>true if the type was resolved or false if the type could not be resolved</returns>
        private bool ResolveVariableType(LuatVariable variable)
        {
            LuatType type = variable.Type;

            foreach (LuatValue.IReference assignment in variable.Assignments)
            {
                if (null == assignment.Value)
                {
                    return false;
                }

                LuatType rhsType = assignment.Value.Type;

                if (rhsType is LuatTypeUnknown)
                {
                    // Being assigned an unknown results in an unknown
                    return false;
                }

                if (type is LuatTypeUnknown || type is LuatTypeNil)
                {
                    type = rhsType;
                    continue;
                }

                if (rhsType is LuatTypeNil)
                {
                    continue;
                }

                if (type.Equals(rhsType))
                {
                    continue;
                }

                if (variable.IsFixedType)
                {
                    assignment.AddWarning(WarningType.FixedType, string.Format("Type is fixed to {0}", type));
                    continue;
                }

                // Mixed types.
                var mixed = type as LuatTypeMixed;
                if (null == mixed)
                {
                    mixed = new LuatTypeMixed();
                    mixed.AddType(type);
                    type = mixed;
                }

                mixed.AddType(rhsType);
            }

            if (null == type)
            {
                return false;
            }

            variable.Type = type;

            // Propagate resolving of variable types through expressions
            foreach (LuatValue.IReference reference in variable.References)
            {
                reference.OnTypeInvalidated();
            }

            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a variable to the unresolved type list
        /// </summary>
        /// <param name="variable"></param>
        /// <returns></returns>
        public bool AddUnresolvedVariableType(LuatVariable variable)
        {
            if (m_unresolvedVariableTypes.Contains(variable))
                return false;

            if (!variable.IsFixedType)
                variable.Type = LuatTypeUnknown.Instance;

            m_unresolvedVariableTypes.Add(variable);

            foreach (LuatValue.IReference reference in variable.References)
            {
                reference.OnTypeInvalidated();
            }

            return true;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempts to resolve (or infer) the variable type
        /// </summary>
        /// <param name="variable"></param>
        /// <returns>true if the type was resolved or false if the type could not be resolved</returns>
        private bool ResolveVariableType(LuatVariable variable)
        {
            LuatType type = variable.Type;

            foreach (LuatValue.IReference assignment in variable.Assignments)
            {
                if (null == assignment.Value)
                {
                    return(false);
                }

                LuatType rhsType = assignment.Value.Type;

                if (rhsType is LuatTypeUnknown)
                {
                    // Being assigned an unknown results in an unknown
                    return(false);
                }

                if (type is LuatTypeUnknown || type is LuatTypeNil)
                {
                    type = rhsType;
                    continue;
                }

                if (rhsType is LuatTypeNil)
                {
                    continue;
                }

                if (type.Equals(rhsType))
                {
                    continue;
                }

                if (variable.IsFixedType)
                {
                    assignment.AddWarning(WarningType.FixedType, string.Format("Type is fixed to {0}", type));
                    continue;
                }

                // Mixed types.
                var mixed = type as LuatTypeMixed;
                if (null == mixed)
                {
                    mixed = new LuatTypeMixed();
                    mixed.AddType(type);
                    type = mixed;
                }

                mixed.AddType(rhsType);
            }

            if (null == type)
            {
                return(false);
            }

            variable.Type = type;

            // Propagate resolving of variable types through expressions
            foreach (LuatValue.IReference reference in variable.References)
            {
                reference.OnTypeInvalidated();
            }

            return(true);
        }