Exemple #1
0
        public IInterpreter GenericTypeAliasing()
        {
            var interpreter = new Interpreter.Interpreter();

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DebugThrowOnError = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Point", "V", VarianceMode.None))
                                   .With(Alias.Create("VType", NameReference.Create("V"), EntityModifier.Public)));

                VariableDeclaration decl = VariableDeclaration.CreateStatement("x", NameReference.Create("p", "VType"), Undef.Create(),
                                                                               env.Options.ReassignableModifier());
                root_ns.AddBuilder(FunctionBuilder.Create("main", NameFactory.Nat8NameReference(), Block.CreateStatement(
                                                              VariableDeclaration.CreateStatement("p", null,
                                                                                                  ExpressionFactory.StackConstructor(NameReference.Create("Point", NameFactory.Nat8NameReference()))),
                                                              decl,
                                                              Assignment.CreateStatement(NameReference.Create("x"), Nat8Literal.Create("5")),
                                                              Return.Create(NameReference.Create("x"))
                                                              )));

                ExecValue result = interpreter.TestRun(env);

                Assert.AreEqual((byte)5, result.RetValue.PlainValue);
            }

            return(interpreter);
        }
Exemple #2
0
        public IErrorReporter NameAliasing()
        {
            NameResolver resolver = null;
            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options() { DiscardingAnyExpressionDuringTests = true,
                    DebugThrowOnError = true }.SetMutability(mutability));
                var root_ns = env.Root;

                root_ns.AddBuilder(TypeBuilder.Create("Point")
                    .With(Alias.Create("Boo", NameFactory.Int64NameReference()))
                    .With(FunctionBuilder.Create("getIt", ExpressionReadMode.OptionalUse, NameFactory.UnitNameReference(),
                        Block.CreateStatement(
                            VariableDeclaration.CreateStatement("x", NameReference.Create("Boo"), Int64Literal.Create("2")),
                             ExpressionFactory.Readout("x"),

                            Alias.Create("Loc", NameFactory.Int64NameReference()),
                            VariableDeclaration.CreateStatement("y", NameReference.Create("Loc"), Int64Literal.Create("3")),
                             ExpressionFactory.Readout("y")
                        ))));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);
            }

            return resolver;
        }