Example #1
0
        public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins, CodeFrame frame, Scope globalScope)
        {
            Options = options;
            var helper = new Builder(frame, this, builtins, globalScope);

            try
            {
                helper.CompileUnit(prog);
            }
            catch (TerminationException)
            {
                //Nothing should be done here. This was thrown to stop compilation.
            }
            #if !DEBUG
            catch (Exception ex)
            {
                if (ex is ElaCompilerException)
                    throw;

                throw new ElaCompilerException(Strings.GetMessage("Ice", ex.Message), ex);
            }
            #endif

            frame.Symbols = frame.Symbols == null ? helper.Symbols :
                helper.Symbols != null ? frame.Symbols.Merge(helper.Symbols) : frame.Symbols;
            frame.GlobalScope = globalScope;
            return new CompilerResult(frame, helper.Success, helper.Errors.ToArray());
        }
Example #2
0
        public CompilerOptions CreateCompilerOptions()
        {
            var c = app.Config<CompilerConfig>();
            var opt = new CompilerOptions();

            opt.GenerateDebugInfo = c.GenerateDebugInfo;
            opt.NoWarnings = c.NoWarnings;
            opt.Prelude = c.Prelude;
            opt.WarningsAsErrors = c.WarningsAsErrors;
            opt.Optimize = c.Optimize;
            opt.ShowHints = c.ShowHints;
            return opt;
        }
Example #3
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);
        }
Example #5
0
 public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins)
 {
     var frame = new CodeFrame();
     return Compile(prog, options, builtins, frame, new Scope(false, null));
 }