예제 #1
0
        public void HandleFileL(Action <UrclInstruction> emit, IEnumerable <string> src)
        {
            var source = string.Join(Environment.NewLine, src);

            try
            {
                var compiler = new LuC.Compiler();

                compiler.Compile(LuC.Parser.Parse(compiler, source));

                Standard.AddStandardDefaults(compiler);

                var emitter = new Emitters.Urcl(compiler);
                compiler.Emit(emitter, "Program.Main");

                foreach (var inst in new UrclOptimizer
                {
                    CullRedundantStackOps = true,
                    CullCreateLabel = true,
                    CullPragmas = true
                }.Optimize(emitter.Result.ToArray()))
                {
                    emit(inst);
                }
            }
            catch (SourceError ex)
            {
                ex.GetLineAndColumn(source, out int line, out int column);

                throw new ParserError($"Compile Error (Ln {line}, Col {column}): {ex.Message} \"{source.Substring(ex.Start, ex.Length)}\"");
            }
        }
예제 #2
0
        public void HandleFileL(Action <UrclInstruction> emit, IEnumerable <string> src)
        {
            var compiler = new LuC.Compiler();

            compiler.Compile(LuC.Parser.Parse(compiler, string.Join(Environment.NewLine, src)));

            LuC.Standard.AddStandardDefaults(compiler);

            var emitter = new Emitters.Urcl(compiler);

            compiler.Emit(emitter, "Program.Main");

            foreach (var inst in new UrclOptimizer
            {
                CullRedundantStackOps = true,
                CullCreateLabel = true,
                CullPragmas = true
            }.Optimize(emitter.Result.ToArray()))
            {
                emit(inst);
            }
        }