Example #1
0
        private ExportVars exports;                      //Exports for current module

        //globalScope is not empty (e.g. new Scope()) only if we are resuming in interactive mode
        internal Builder(CodeFrame frame, ElaCompiler comp, ExportVars exportVars, Scope globalScope)
        {
            this.frame       = frame;
            this.options     = comp.Options;
            this.exports     = exportVars;
            this.comp        = comp;
            this.cw          = new CodeWriter(frame.Ops, frame.OpData);
            this.globalScope = globalScope;

            CurrentScope = globalScope;
            debug        = options.GenerateDebugInfo;
            opt          = options.Optimize;

            stringLookup = new Dictionary <String, Int32>();
            cleans.Push(true);

            ResumeIndexer();
            Success = true;
        }
Example #2
0
        private Dictionary<String, Int32> stringLookup; //String table

        #endregion Fields

        #region Constructors

        //globalScope is not empty (e.g. new Scope()) only if we are resuming in interactive mode
        internal Builder(CodeFrame frame, ElaCompiler comp, ExportVars exportVars, Scope globalScope)
        {
            this.frame = frame;
            this.options = comp.Options;
            this.exports = exportVars;
            this.comp = comp;
            this.cw = new CodeWriter(frame.Ops, frame.OpData);
            this.globalScope = globalScope;

            CurrentScope = globalScope;
            debug = options.GenerateDebugInfo;
            opt = options.Optimize;

            stringLookup = new Dictionary<String,Int32>();
            cleans.Push(true);

            ResumeIndexer();
            Success = true;
        }
        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);
        }