コード例 #1
0
 public ScopeEntry(AnalysisScope scope, Symbol key, object value, ScopeFlags flags)
 {
     Scope         = scope;
     Key           = key;
     Value         = value;
     Flags         = flags;
     HoistIndex    = -1;
     HoistOriginal = null;
 }
コード例 #2
0
        public void ChangeNativeToFrameLocal(ScopeEntry entry)
        {
            if (Names == null)
            {
                Names = new List <Symbol>();
            }

            UsesFramedVariables = true;
            Names.Add(entry.Key);
            entry.Value = Names.Count - 1;
        }
コード例 #3
0
        public ScopeEntry FindLocal(Symbol sym, ScopeFlags reason = 0)
        {
            for (var sc = this; sc != null; sc = sc.Parent)
            {
                foreach (var item in sc.Variables)
                {
                    if (item.Key == sym)
                    {
                        item.Flags |= reason;

                        if (item.Parameter != null && LambdaParent != sc.LambdaParent)
                        {
                            // Linq.Expression closures do not support native variables defined
                            // outside a separately compiled lambda.
                            var index       = LambdaParent.HoistVariables.Count;
                            var hoistedItem = new ScopeEntry(item, index);
                            LambdaParent.HoistVariables.Add(hoistedItem);
                            return(hoistedItem);
                        }
                        else
                        {
                            return(item);
                        }
                    }
                }

                if (LambdaParent == sc)
                {
                    foreach (var item in sc.HoistVariables)
                    {
                        if (item.Key == sym)
                        {
                            item.Flags |= reason;
                            item.HoistOriginal.Flags |= reason;
                            return(item);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #4
0
        public bool FindLocal(Symbol sym, ScopeFlags reason, out int depth, out ScopeEntry entry)
        {
            bool noCapturedNativeParametersBeyondThisPoint = false;

            depth = 0;
            entry = null;

            for (AnalysisScope sc = this; sc != null; sc = sc.Parent)
            {
                ScopeEntry item;

                if (sc.IsBlockScope && sym == Symbols.Tilde)
                {
                    if (sc.Tilde == null)
                    {
                        sc.Tilde = sc.DefineNativeLocal(Symbols.Tilde, ScopeFlags.All);
                    }
                }

                for (var i = sc.Variables.Count - 1; i >= 0; --i)
                {
                    item = sc.Variables[i];

                    // Looking for exact match
                    if (LexicalSymEqual(item.Key, sym))
                    {
                        entry       = item;
                        item.Flags |= reason;

                        if (item.Index != -1 || item.MacroValue != null || item.SymbolMacroValue != null)
                        {
                        }
                        else if (reason != 0 && noCapturedNativeParametersBeyondThisPoint && !LexicalSymEqual(sym, Symbols.Tilde))
                        {
                            // Linq.Expression closures do not support native variables defined
                            // outside the LambdaExpression. Whenever we encounter such a variable
                            // it is added to the free variables and also added as frame variable
                            // to keep the compiler happy.
                            // The recompile that comes later uses the list of free variables to
                            // choose the correct implementation scheme.
                            sc.FreeVariables.Add(sym);
                            sc.ChangeNativeToFrameLocal(item);
                        }

                        return(true);
                    }
                }

                if (sc.IsBlockScope && sym == Symbols.Tilde)
                {
                    // boundary for ~ variable which is tightly coupled to its DO block.
                    break;
                }

                if (sc.IsLambda)
                {
                    // boundary for native variables in closures.
                    noCapturedNativeParametersBeyondThisPoint = true;
                }

                if (sc.Names != null)
                {
                    ++depth;
                }
            }

            depth = 0;

            return(false);
        }
コード例 #5
0
        public void ChangeNativeToFrameLocal(ScopeEntry entry)
        {
            if (Names == null)
            {
                Names = new List<Symbol>();
            }

            UsesFramedVariables = true;
            Names.Add(entry.Key);
            entry.Value = Names.Count - 1;
        }
コード例 #6
0
        public bool FindLocal(Symbol sym, ScopeFlags reason, out int depth, out ScopeEntry entry)
        {
            bool noCapturedNativeParametersBeyondThisPoint = false;

            depth = 0;
            entry = null;

            for (AnalysisScope sc = this; sc != null; sc = sc.Parent)
            {
                ScopeEntry item;

                if (sc.IsBlockScope && sym == Symbols.Tilde)
                {
                    if (sc.Tilde == null)
                    {
                        sc.Tilde = sc.DefineNativeLocal(Symbols.Tilde, ScopeFlags.All);
                    }
                }

                for (var i = sc.Variables.Count - 1; i >= 0; --i)
                {
                    item = sc.Variables[i];

                    // Looking for exact match
                    if (LexicalSymEqual(item.Key, sym))
                    {
                        entry = item;
                        item.Flags |= reason;

                        if (item.Index != -1 || item.MacroValue != null || item.SymbolMacroValue != null)
                        {
                        }
                        else if (reason != 0 && noCapturedNativeParametersBeyondThisPoint && !LexicalSymEqual(sym, Symbols.Tilde))
                        {
                            // Linq.Expression closures do not support native variables defined
                            // outside the LambdaExpression. Whenever we encounter such a variable
                            // it is added to the free variables and also added as frame variable
                            // to keep the compiler happy.
                            // The recompile that comes later uses the list of free variables to
                            // choose the correct implementation scheme.
                            sc.FreeVariables.Add(sym);
                            sc.ChangeNativeToFrameLocal(item);
                        }

                        return true;
                    }
                }

                if (sc.IsBlockScope && sym == Symbols.Tilde)
                {
                    // boundary for ~ variable which is tightly coupled to its DO block.
                    break;
                }

                if (sc.IsLambda)
                {
                    // boundary for native variables in closures.
                    noCapturedNativeParametersBeyondThisPoint = true;
                }

                if (sc.Names != null)
                {
                    ++depth;
                }

            }

            depth = 0;

            return false;
        }
コード例 #7
0
 public ScopeEntry(ScopeEntry item, int index)
     : this(item.Scope, item.Key, item.Value, item.Flags)
 {
     HoistIndex    = index;
     HoistOriginal = item;
 }