Esempio n. 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());
        }
Esempio n. 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;
        }
Esempio n. 3
0
 public Scope Clone()
 {
     var ret = new Scope(Function, Parent);
     ret.Locals = new Dictionary<String,ScopeVar>(Locals);
     return ret;
 }
Esempio n. 4
0
 internal Scope(bool fun, Scope parent)
 {
     Function = fun;
     Parent = parent;
     Locals = new Dictionary<String,ScopeVar>();
 }
Esempio n. 5
0
        //Generates information about a lexical scope. Called
        //when a lexical scope starts.
        private void StartScope(bool fun, int line, int col)
        {
            CurrentScope = new Scope(fun, CurrentScope);

            if (debug)
                pdb.StartScope(cw.Offset, line, col);
        }
Esempio n. 6
0
        //This method allows to specify a scope from which to start search.
        private ScopeVar GetVariable(string name, Scope startScope, GetFlags getFlags, int line, int col)
        {
            var cur = startScope;
            var shift = 0;
            var var = ScopeVar.Empty;

            //Walks the scopes recursively to look for a variable
            do
            {
                if (cur.Locals.TryGetValue(name, out var))
                {
                    var.Address = shift | var.Address << 8;

                    if ((var.Flags & ElaVariableFlags.NoInit) == ElaVariableFlags.NoInit &&
                        (var.Flags & ElaVariableFlags.Function) != ElaVariableFlags.Function &&
                        (var.Flags & ElaVariableFlags.ClassFun) != ElaVariableFlags.ClassFun &&
                        (var.Flags & ElaVariableFlags.TypeFun) != ElaVariableFlags.TypeFun)
                        cleans.Replace(false);

                    return var;
                }

                if (cur.Function)
                    shift++;

                var = ScopeVar.Empty;
                cur = cur.Parent;
            }
            while (cur != null);

            //If this flag is set we don't need to go further
            if ((getFlags & GetFlags.Local) == GetFlags.Local)
            {
                if (!options.IgnoreUndefined && (getFlags & GetFlags.NoError) != GetFlags.NoError)
                    AddError(ElaCompilerError.UndefinedName, line, col, name);

                return ScopeVar.Empty;
            }

            return GetExternVariable(name, getFlags, line, col);
        }
Esempio n. 7
0
 internal Scope(bool fun, Scope parent)
 {
     Function = fun;
     Parent   = parent;
     Locals   = new Dictionary <String, ScopeVar>();
 }