Пример #1
0
        private IEnumerable <OpCode> ReadCode(BinaryReader br)
        {
            var c = br.ReadInt32();

            for (var i = 0; i < c; i++)
            {
                var opCode = (Op)br.ReadByte();
                var arg    = ElaCompiler.GetOpCodeSize(opCode) > 1 ? (int?)br.ReadInt32() : null;
                yield return(new OpCode(i, opCode, arg));
            }
        }
Пример #2
0
        public Tuple <ICompiledUnit, IEnumerable <MessageItem> > Compile(CodeDocument doc, string source)
        {
            var par    = new ElaParser();
            var parRes = par.Parse(source);
            var msg    = new List <MessageItem>();
            var unit   = doc.Unit;
            Func <ElaMessage, MessageItem> project = m => new MessageItem(
                m.Type == MessageType.Error ? MessageItemType.Error : MessageItemType.Warning, m.Message, doc, m.Line, m.Column);

            if (parRes.Success)
            {
                var copt = new CompilerOptions();

                copt.ShowHints         = false;
                copt.GenerateDebugInfo = true;
                copt.IgnoreUndefined   = true;

                //TODO: hack, should be taken from options
                copt.Prelude = "prelude";
                var comp = new ElaCompiler();

                try
                {
                    var compRes = comp.Compile(parRes.Program, copt, new ExportVars());
                    msg.AddRange(compRes.Messages.Where(m => m.Type != MessageType.Hint).Select(project));

                    if (compRes.CodeFrame != null)
                    {
                        unit = new CompiledUnit(doc, compRes.CodeFrame);
                    }
                }
                catch { }
            }
            else
            {
                msg.AddRange(parRes.Messages.Select(project));
            }

            return(Tuple.Create(unit, (IEnumerable <MessageItem>)msg));
        }
Пример #3
0
        private CodeFrame Build(ModuleReference mod, FileInfo fi)
        {
            try
            {
                var elap = new ElaParser();
                var pres = elap.Parse(fi);

                if (pres.Success)
                {
                    var elac = new ElaCompiler();
                    var copt = new BuildOptionsManager(App).CreateCompilerOptions();
                    return(elac.Compile(pres.Program,
                                        new CompilerOptions {
                        IgnoreUndefined = true, NoWarnings = true, ShowHints = false, Prelude = copt.Prelude
                    },
                                        new ExportVars()
                                        ).CodeFrame);
                }
            }
            catch { }

            return(null);
        }