Beispiel #1
0
        private void MakeGlobalScope()
        {
            Push();

            Types.Bind("int", new IntType());
            Types.Bind("double", new DoubleType());
            Types.Bind("boolean", new BooleanType());
            Types.Bind("string", new StringType());
            Types.Bind("char", new CharType());
            Types.Bind("any", new AnyType());

            Values.Bind("println", new VariableBinding()
            {
                Name = "Console.WriteLine",
                Type = new FunctionType()
                {
                    ParameterTypes = new List <IType>()
                    {
                        new AnyType(),
                    }
                },
                IsConst = true,
            });
            Values.Bind("print", new VariableBinding()
            {
                Name = "Console.Write",
                Type = new FunctionType()
                {
                    ParameterTypes = new List <IType>()
                    {
                        new AnyType(),
                    }
                },
                IsConst = true,
            });

            Types.Bind("Pair", new GenericClassWrapper(
                           new ClassType()
            {
                Name    = "Pair",
                Members = new Dictionary <string, IType>()
                {
                    { "First", new GenericTypeIdentifier("TFirst") },
                    { "Second", new GenericTypeIdentifier("TSecond") },
                },
            },
                           new Dictionary <string, IType>()
            {
                { "TFirst", new GenericTypeIdentifier("TFirst") },
                { "TSecond", new GenericTypeIdentifier("TSecond") }
            },
                           new List <string>()
            {
                "TFirst", "TSecond"
            }
                           ));
        }