Beispiel #1
0
        public static void WrappedMain(string[] args)
        {
            CodeGenerator.module = LLVM.ModuleCreateWithName("psi.result");

            // primitives
            TypeMapper.Add(typeof(bool), BuiltinType.Boolean);
            TypeMapper.Add(typeof(byte), BuiltinType.Byte);
            TypeMapper.Add(typeof(long), BuiltinType.Integer);
            TypeMapper.Add(typeof(ulong), BuiltinType.UnsignedInteger);
            TypeMapper.Add(typeof(double), BuiltinType.Real);
            TypeMapper.Add(typeof(string), BuiltinType.String);
            TypeMapper.Add(typeof(int), BuiltinType.Character);

            // required types
            TypeMapper.Add(typeof(void), Type.VoidType);
            TypeMapper.Add(typeof(Type), Type.MetaType);
            TypeMapper.Add(typeof(Intermediate.Module), Type.ModuleType);

            var std = CreateStd();

            var syntaxModule = Load("../Sources/CompilerTest.psi");

            if (syntaxModule == null)
            {
                Console.WriteLine("Failed to parse!");
                return;
            }

            var printer = new ModulePrinter(Console.Out);

            printer.Print(syntaxModule);

            var declarableGlobalScope = new SimpleScope
            {
                new Symbol(Type.ModuleType, "std")
                {
                    Initializer = new ModuleLiteral(std),
                    IsConst     = true,
                    IsExported  = false
                }
            };

            InitializeGlobalOperators(declarableGlobalScope);

            // TODO: Add "linked libraries" to declarableGlobalScope

            var globalScope = new StackableScope();

            globalScope.Push(new AutoGlobalScope());
            globalScope.Push(declarableGlobalScope);

            var astConverter = new ASTConverter(globalScope);

            astConverter.AddModule(syntaxModule);
            astConverter.Convert();

            var output = astConverter.GetModule(syntaxModule);

            CodeGenerator.GenerateIL(output);
        }
        public BindingContext(ConfigMapping configurationContext, DriverOptions driverOptions, CppModule moduleContext)
            : base(driverOptions)
        {
            ConfigurationContext = configurationContext;
            ParserContext        = moduleContext;
            Options = driverOptions;

            FoundEnums = new SortedList();
            ASTConverter converter = new ASTConverter(this, configurationContext, moduleContext);

            ASTContext = converter.Convert();
        }
        static void Main(string [] args)
        {
            try
            {
                ASTConverter converter    = new ASTConverter();
                var          construction = converter.GetTestProgram();
                Generator    generator    = new Generator();
                generator.Generate(construction);

                //        System.Diagnostics.Process.Start( @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\Командная строка разработчика для VS 2017" );
                Console.WriteLine("Программа сгенерирована");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
Beispiel #4
0
 /// <summary>
 /// Converts a native parser AST to a managed AST.
 /// </summary>
 public static AST.ASTContext ConvertASTContext(ASTContext context)
 {
     var converter = new ASTConverter(context);
     return converter.Convert();
 }