Пример #1
0
 public Compiler(IAstModuleLoader moduleLoader)
 {
     Context            = new CompilerContext(moduleLoader);
     _astBuilder        = new AstBuilder(Context);
     _resolveDefinition = new ResolveDefinition(Context);
     _checkRules        = new CheckRules(Context);
 }
Пример #2
0
        public static AstFile File(string code, IAstModuleLoader moduleLoader = null)
        {
            var file    = ParseFile(code);
            var context = new CompilerContext(moduleLoader ?? new ModuleLoader());

            return(BuildFile(file, context));
        }
Пример #3
0
        public static AstModuleImpl Module(string code, IAstModuleLoader moduleLoader = null)
        {
            var file    = ParseFile(code);
            var context = new CompilerContext(moduleLoader ?? new ModuleLoader());

            _ = BuildFile(file, context);
            return((AstModuleImpl)context.Modules.Modules.First());
        }
Пример #4
0
        public static AstFile File(string code, IAstModuleLoader moduleLoader = null)
        {
            var compiler = new Compiler(moduleLoader ?? new ModuleLoader());
            var errors   = compiler.ParseAst("UnitTests", "UnitTests", code);

            errors.PrintErrors();
            errors.Should().BeEmpty();

            return(((AstModuleImpl)compiler.Context.Modules.Modules.First()).Files.First());
        }
Пример #5
0
        public static EmitCode Run(string code, string testName, IAstModuleLoader moduleLoader = null)
        {
            var emit = Emit.Create(code, moduleLoader);

            emit.SaveAs($@".\{testName}\{testName}.cs");

            Console.WriteLine(emit.ToString());

            var targetPath = Emit.Build(testName);

            File.Exists(targetPath).Should().BeTrue();
            return(emit);
        }
Пример #6
0
        public static EmitCode Create(string code, IAstModuleLoader moduleLoader = null)
        {
            var compiler = new Compiler(moduleLoader ?? new ModuleLoader());
            var errors   = compiler.ParseAst("UnitTests", AssemblyName, code);

            foreach (var err in errors)
            {
                Console.WriteLine(err);
            }
            errors.Should().BeEmpty();

            var module = compiler.Context.Modules.Modules.First();
            var emit   = new EmitCode(AssemblyName);

            emit.Visit(module);
            return(emit);
        }
Пример #7
0
 public CompilerContext(IAstModuleLoader moduleLoader)
 {
     IntrinsicSymbols = CreateIntrinsicSymbols();
     Modules          = new AstModuleManager(IntrinsicSymbols, moduleLoader);
 }