Exemple #1
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("wtf dude give some files: <output> <file.lah...>");
            }
            var outname = args[0];
            var sources = new string[] {
                "stdlib/mem.lah",
                "stdlib/collections.lah",
                "stdlib/math.lah"
            }.Concat(args.Skip(1));

            foreach (var file in args.Skip(1))
            {
                Console.WriteLine($"Compiling {file}");
            }
            var multiSource = new MultiCodeSource(sources.Select(x => CodeSource.FromFile(x)).ToArray());

            Console.WriteLine(multiSource.Content);
            var parser  = new LahdaParser(new LahdaLexer(new CompilationConfiguration(multiSource)));
            var output  = new StringBuilderOutput();
            var codeGen = new CodeGenerator(output, parser.Root());

            codeGen.Build();
            if (File.Exists(outname))
            {
                File.Delete(outname);
            }
            File.WriteAllText(outname, output.ToString());
        }
        public void CodeGenerator_should_generate_godlike_code(string content, int i)
        {
            var codeSource = CodeSource.FromMemory(content);
            var parser     = new LahdaParser(new LahdaLexer(new CompilationConfiguration(codeSource)));
            var output     = new StringBuilderOutput();
            var codeGen    = new CodeGenerator(output, parser.Root());

            codeGen.Build();
            var path = $"test_{i}.s";

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            File.WriteAllText(path, output.ToString());
        }