Example #1
0
        public static Core.Type ResolveStruct(
            Core.Session session,
            Grammar.ASTNodeName nameNode,
            IList <Core.UseDirective> useDirectives,
            bool mustBeResolved)
        {
            var name = NameResolver.Resolve(nameNode);

            var foundDecls = session.GetDeclsWithUseDirectives(name, nameNode.path.isRooted, useDirectives);

            if (!session.ValidateSingleDecl(foundDecls, name, nameNode.GetSpan()))
            {
                return(new Core.TypeError());
            }

            if (!session.ValidateAsType(foundDecls[0], name, nameNode.GetSpan()))
            {
                return(new Core.TypeError());
            }

            return(Core.TypeStruct.Of(foundDecls[0].index));
        }
Example #2
0
        private void ResolveExprName(Grammar.ASTNodeExprName exprName, ref int curSegment, Core.DataAccess output)
        {
            var name = NameResolver.Resolve(((Grammar.ASTNodeExprNameConcrete)exprName).name);

            // Try to find a local with the same name.
            var bindingIndex = FindLocalBinding(name);

            if (bindingIndex >= 0)
            {
                funct.AddInstruction(curSegment,
                                     Core.InstructionMoveData.Of(
                                         exprName.GetSpan(),
                                         output,
                                         Core.DataAccessRegister.ForRegister(
                                             exprName.GetSpan(),
                                             funct.localBindings[bindingIndex].registerIndex)));
                return;
            }

            // Try to find a group of functs with the same name.
            var functList = session.GetDeclsWithUseDirectives(name, false, useDirectives);

            if (session.ValidateSingleDecl(functList, name, exprName.GetSpan()) &&
                session.ValidateAsFunct(functList[0], name, exprName.GetSpan()))
            {
                funct.AddInstruction(curSegment,
                                     Core.InstructionMoveLiteralFunct.With(exprName.GetSpan(), output, functList[0].index));
                return;
            }

            this.foundErrors = true;
            session.AddMessage(
                Diagnostics.MessageKind.Error,
                Diagnostics.MessageCode.Unknown,
                "unknown '" + name.GetString() + "'",
                exprName.GetSpan());
            throw new Core.CheckException();
        }