Example #1
0
 public void ResolveType(ParseScope ActiveScope)
 {
     if (String.IsNullOrEmpty(DeclaredTypeName))
         DeclaredType = Type.Generic;
     else
     {
         DeclaredType = ActiveScope.FindType(DeclaredTypeName);
         if (DeclaredType == null) throw new CompileError("Could not find type '" + DeclaredTypeName + "'.");
     }
 }
Example #2
0
        public void ResolveTypes(ParseScope ActiveScope)
        {
            if (String.IsNullOrEmpty(SuperTypename))
                Super = null;
            else
            {
                Super = ActiveScope.FindType(SuperTypename);
                if (Super == null) throw new CompileError("Could not find type '" + SuperTypename + "'.");
            }

            if (Super == null)
                Members.Insert(0, new Variable
                {
                    Name = "__type",
                    DeclaredTypeName = "NUMBER",
                    StorageMethod = VariableStorageMethod.Member
                });

            var search = Super;
            while (search != null)
            {
                if (Object.ReferenceEquals(search, this)) throw new CompileError("Inheritance loop detected.");
                search = search.Super;
            }

            if (Origin == TypeOrigin.Script)
                foreach (var member in Members)
                {
                    if (String.IsNullOrEmpty(member.DeclaredTypeName))
                        member.DeclaredType = Type.Generic;
                    else
                    {
                        member.DeclaredType = ActiveScope.FindType(member.DeclaredTypeName);
                        if (member.DeclaredType == null) throw new CompileError("Could not find type '" +
                            member.DeclaredTypeName + "'.");
                    }
                }
        }
Example #3
0
        public void ResolveTypes(ParseScope Scope)
        {
            try
            {
                DeclarationScope = Scope.Push(ScopeType.Function);
                DeclarationScope.Owner = this;

                if (!String.IsNullOrEmpty(ReturnTypeName))
                {
                    ReturnType = Scope.FindType(ReturnTypeName);
                    if (ReturnType == null)
                    {
                        if (Body != null && Body.Body != null)
                            throw new CompileError("Could not find type '" +
                                ReturnTypeName + "'.", Body.Body.Source);
                        else
                            throw new CompileError("Could not find type '" +
                                ReturnTypeName + "'.");
                    }
                }
                else
                    ReturnType = EtcScriptLib.Type.Void;

                CreateParameterDescriptors();

                var header = DescriptiveHeader;
                if (Body != null) Body.Name = header;
                if (WhenClause != null) WhenClause.Name = header + " : when ...";
            }
            catch (Exception e)
            {
                throw new CompileError(e.Message + " while resolving types on " + DescriptiveHeader + "\n" + e.StackTrace);
            }
        }
Example #4
0
            public override Ast.Node Transform(ParseScope Scope)
            {
                List = List.Transform(Scope);
                ResultType = List.ResultType;

                //Try to find an access macro for this type.
                var getterArguments = DummyArguments(Keyword("GET"), Keyword("AT"), Term(Scope.FindType("NUMBER")),
                    Keyword("FROM"), Term(List.ResultType));
                var indexerMacro = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d =>
                    ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault();
                if (indexerMacro == null)
                    throw new CompileError("No macro of the form GET AT NUMBER FROM " +
                        List.ResultType.Name + " found.", Source);

                var lengthArguments = DummyArguments(Keyword("LENGTH"), Keyword("OF"), Term(List.ResultType));
                var lengthMacro = Scope.FindAllPossibleMacroMatches(lengthArguments).Where(d =>
                    ExactDummyMatch(d.Terms, lengthArguments)).FirstOrDefault();
                if (lengthMacro == null)
                    throw new CompileError("No macro of the form LENGTH OF " + List.ResultType.Name + " found.", Source);

                var nestedScope = Scope.Push(ScopeType.Block);

                ResultVariable = nestedScope.NewLocal("__result@" + VariableName, Scope.FindType("LIST"));
                ListVariable = nestedScope.NewLocal("__list@" + VariableName, Scope.FindType("LIST"));
                TotalVariable = nestedScope.NewLocal("__total@" + VariableName, Scope.FindType("NUMBER"));
                CounterVariable = nestedScope.NewLocal("__counter@" + VariableName, Scope.FindType("NUMBER"));
                ValueVariable = nestedScope.NewLocal(VariableName, indexerMacro.ReturnType);

                Indexer = Ast.StaticInvokation.CreateCorrectInvokationNode(Source, nestedScope, indexerMacro,
                    new List<Ast.Node>(new Ast.Node[] {
                        new Ast.Identifier(new Token { Type = TokenType.Identifier, Value = "__counter@"+VariableName }),
                        new Ast.Identifier(new Token { Type = TokenType.Identifier, Value = "__list@"+VariableName })
                    })).Transform(nestedScope);

                LengthFunc = Ast.StaticInvokation.CreateCorrectInvokationNode(Source, nestedScope, lengthMacro,
                    new List<Ast.Node>(new Ast.Node[] {
                        new Ast.Identifier(new Token { Type = TokenType.Identifier, Value = "__list@"+VariableName })
                    })).Transform(nestedScope);

                Condition = Condition.Transform(nestedScope);
                if (Condition.ResultType.Name != "BOOLEAN")
                    throw new CompileError("Condition to where clause must return boolean", Source);
                return this;
            }
Example #5
0
 public override EtcScriptLib.Ast.Node Transform(ParseScope Scope)
 {
     DeclarationScope = Scope;
     BoxType = Scope.FindType("BOXED");
     ResultType = Rulebook.ResultType;
     return this;
 }
Example #6
0
 public override Ast.Node Transform(ParseScope Scope)
 {
     ResultType = Type.Void;
     Max = Max.Transform(Scope);
     var nestedScope = Scope.Push(ScopeType.Block);
     TotalVariable = nestedScope.NewLocal("__total@" + VariableName, Scope.FindType("NUMBER"));
     Min = Min.Transform(nestedScope);
     CounterVariable = nestedScope.NewLocal("__counter@" + VariableName, Scope.FindType("NUMBER"));
     ValueVariable = nestedScope.NewLocal(VariableName, Scope.FindType("NUMBER"));
     Body = Body.Transform(nestedScope);
     return this;
 }