• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Compiler.LambdaCompiler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Linq.Expressions.Compiler.LambdaCompiler的典型用法代码示例。如果您正苦于以下问题:C# LambdaCompiler类的具体用法?C# LambdaCompiler怎么用?C# LambdaCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LambdaCompiler类属于System.Linq.Expressions.Compiler命名空间,在下文中一共展示了LambdaCompiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LocalStorage

 internal LocalStorage(LambdaCompiler compiler, ParameterExpression v)
     : base(compiler, v) {
     // ByRef variables are supported. This is used internally by
     // the compiler when emitting an inlined lambda invoke, to 
     // handle ByRef parameters. BlockExpression prevents this
     // from being exposed to user created trees.
     _local = compiler.GetNamedLocal(v.IsByRef ? v.Type.MakeByRefType() : v.Type, v.Name);
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:8,代码来源:CompilerScope.Storage.cs


示例2: AllocateLocals

 private void AllocateLocals(LambdaCompiler lc)
 {
     foreach (ParameterExpression expression in this.GetVariables())
     {
         if (((VariableStorageKind) this.Definitions[expression]) == VariableStorageKind.Local)
         {
             Storage storage;
             if (this.IsMethod && lc.Parameters.Contains(expression))
             {
                 storage = new ArgumentStorage(lc, expression);
             }
             else
             {
                 storage = new LocalStorage(lc, expression);
             }
             this._locals.Add(expression, storage);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:CompilerScope.cs


示例3: EmitNewHoistedLocals

 private void EmitNewHoistedLocals(LambdaCompiler lc)
 {
     if (this._hoistedLocals != null)
     {
         lc.IL.EmitInt(this._hoistedLocals.Variables.Count);
         lc.IL.Emit(OpCodes.Newarr, typeof(object));
         int num = 0;
         foreach (ParameterExpression expression in this._hoistedLocals.Variables)
         {
             lc.IL.Emit(OpCodes.Dup);
             lc.IL.EmitInt(num++);
             Type type = typeof(StrongBox<>).MakeGenericType(new Type[] { expression.Type });
             if (this.IsMethod && lc.Parameters.Contains(expression))
             {
                 int index = lc.Parameters.IndexOf(expression);
                 lc.EmitLambdaArgument(index);
                 lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type }));
             }
             else if (expression == this._hoistedLocals.ParentVariable)
             {
                 this.ResolveVariable(expression, this._closureHoistedLocals).EmitLoad();
                 lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type }));
             }
             else
             {
                 lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(Type.EmptyTypes));
             }
             if (this.ShouldCache(expression))
             {
                 lc.IL.Emit(OpCodes.Dup);
                 this.CacheBoxToLocal(lc, expression);
             }
             lc.IL.Emit(OpCodes.Stelem_Ref);
         }
         this.EmitSet(this._hoistedLocals.SelfVariable);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:CompilerScope.cs


示例4: LocalStorage

 internal LocalStorage(LambdaCompiler compiler, ParameterExpression variable)
     : base(compiler, variable) {
     _local = compiler.GetNamedLocal(variable.Type, variable.Name);
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:4,代码来源:CompilerScope.Storage.cs


示例5: EmitClosureAccess

 private void EmitClosureAccess(LambdaCompiler lc, HoistedLocals locals)
 {
     if (locals != null)
     {
         this.EmitClosureToVariable(lc, locals);
         while ((locals = locals.Parent) != null)
         {
             ParameterExpression selfVariable = locals.SelfVariable;
             LocalStorage storage = new LocalStorage(lc, selfVariable);
             storage.EmitStore(this.ResolveVariable(selfVariable));
             this._locals.Add(selfVariable, storage);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:CompilerScope.cs


示例6: Storage

 internal Storage(LambdaCompiler compiler, ParameterExpression variable)
 {
     this.Compiler = compiler;
     this.Variable = variable;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:5,代码来源:CompilerScope.cs


示例7: LocalBoxStorage

 internal LocalBoxStorage(LambdaCompiler compiler, ParameterExpression variable) : base(compiler, variable)
 {
     this._boxType = typeof(StrongBox<>).MakeGenericType(new Type[] { variable.Type });
     this._boxValueField = this._boxType.GetField("Value");
     this._boxLocal = compiler.GetNamedLocal(this._boxType, variable);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:6,代码来源:CompilerScope.cs


示例8: AddLocal

 internal void AddLocal(LambdaCompiler gen, ParameterExpression variable)
 {
     this._locals.Add(variable, new LocalStorage(gen, variable));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:CompilerScope.cs


示例9: SetParent

 private void SetParent(LambdaCompiler lc, CompilerScope parent)
 {
     this._parent = parent;
     if (this.NeedsClosure && (this._parent != null))
     {
         this._closureHoistedLocals = this._parent.NearestHoistedLocals;
     }
     ReadOnlyCollection<ParameterExpression> vars = (from p in this.GetVariables()
         where ((VariableStorageKind) this.Definitions[p]) == VariableStorageKind.Hoisted
         select p).ToReadOnly<ParameterExpression>();
     if (vars.Count > 0)
     {
         this._hoistedLocals = new HoistedLocals(this._closureHoistedLocals, vars);
         this.AddLocal(lc, this._hoistedLocals.SelfVariable);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:CompilerScope.cs


示例10: SetParent

        private void SetParent(LambdaCompiler lc, CompilerScope parent)
        {
            Debug.Assert(_parent == null && parent != this);
            _parent = parent;

            if (NeedsClosure && _parent != null)
            {
                _closureHoistedLocals = _parent.NearestHoistedLocals;
            }

            ReadOnlyCollection<ParameterExpression> hoistedVars = GetVariables().Where(p => Definitions[p] == VariableStorageKind.Hoisted).ToReadOnly();

            if (hoistedVars.Count > 0)
            {
                _hoistedLocals = new HoistedLocals(_closureHoistedLocals, hoistedVars);
                AddLocal(lc, _hoistedLocals.SelfVariable);
            }
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:18,代码来源:CompilerScope.cs


示例11: EmitVariableAccess

        internal void EmitVariableAccess(LambdaCompiler lc, ReadOnlyCollection<ParameterExpression> vars)
        {
            if (NearestHoistedLocals != null && vars.Count > 0)
            {
                // Find what array each variable is on & its index
                var indexes = new ArrayBuilder<long>(vars.Count);

                foreach (ParameterExpression variable in vars)
                {
                    // For each variable, find what array it's defined on
                    ulong parents = 0;
                    HoistedLocals locals = NearestHoistedLocals;
                    while (!locals.Indexes.ContainsKey(variable))
                    {
                        parents++;
                        locals = locals.Parent;
                        Debug.Assert(locals != null);
                    }

                    // combine the number of parents we walked, with the
                    // real index of variable to get the index to emit.
                    ulong index = (parents << 32) | (uint)locals.Indexes[variable];

                    indexes.UncheckedAdd((long)index);
                }

                EmitGet(NearestHoistedLocals.SelfVariable);
                lc.EmitConstantArray(indexes.ToArray());
                lc.IL.Emit(OpCodes.Call, RuntimeOps_CreateRuntimeVariables_ObjectArray_Int64Array);
            }
            else
            {
                // No visible variables
                lc.IL.Emit(OpCodes.Call, RuntimeOps_CreateRuntimeVariables);
            }
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:36,代码来源:CompilerScope.cs


示例12: Enter

        /// <summary>
        /// Called when entering a lambda/block. Performs all variable allocation
        /// needed, including creating hoisted locals and IL locals for accessing
        /// parent locals
        /// </summary>
        internal CompilerScope Enter(LambdaCompiler lc, CompilerScope parent)
        {
            SetParent(lc, parent);

            AllocateLocals(lc);

            if (IsMethod && _closureHoistedLocals != null)
            {
                EmitClosureAccess(lc, _closureHoistedLocals);
            }

            EmitNewHoistedLocals(lc);

            if (IsMethod)
            {
                EmitCachedVariables();
            }

            return this;
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:25,代码来源:CompilerScope.cs


示例13: AllocateLocals

 // Allocates slots for IL locals or IL arguments
 private void AllocateLocals(LambdaCompiler lc) {
     foreach (ParameterExpression v in GetVariables()) {
         if (Definitions[v] == VariableStorageKind.Local) {
             Storage s;
             //If v is in lc.Parameters, it is a parameter.
             //Otherwise, it is a local variable.
             if (lc.Parameters.Contains(v)) {
                 s = new ArgumentStorage(lc, v);
             } else {
                 s = new LocalStorage(lc, v);
             }
             _locals.Add(v, s);
         }
     }
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:16,代码来源:CompilerScope.cs


示例14: EmitVariableAccess

        internal void EmitVariableAccess(LambdaCompiler lc, ReadOnlyCollection<ParameterExpression> vars) {
            if (NearestHoistedLocals != null) {
                // Find what array each variable is on & its index
                var indexes = new List<long>(vars.Count);

                foreach (var variable in vars) {
                    // For each variable, find what array it's defined on
                    ulong parents = 0;
                    HoistedLocals locals = NearestHoistedLocals;
                    while (!locals.Indexes.ContainsKey(variable)) {
                        parents++;
                        locals = locals.Parent;
                        Debug.Assert(locals != null);
                    }
                    
                    // combine the number of parents we walked, with the
                    // real index of variable to get the index to emit.
                    ulong index = (parents << 32) | (uint)locals.Indexes[variable];

                    indexes.Add((long)index);
                }

                if (indexes.Count > 0) {
                    EmitGet(NearestHoistedLocals.SelfVariable);
                    lc.EmitConstantArray(indexes.ToArray());
                    lc.IL.EmitCall(typeof(RuntimeOps).GetMethod("CreateRuntimeVariables", new[] { typeof(object[]), typeof(long[]) }));
                    return;
                }
            }

            // No visible variables
            lc.IL.EmitCall(typeof(RuntimeOps).GetMethod("CreateRuntimeVariables", Type.EmptyTypes));
            return;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:34,代码来源:CompilerScope.cs


示例15: EmitVariableAccess

 internal void EmitVariableAccess(LambdaCompiler lc, ReadOnlyCollection<ParameterExpression> vars)
 {
     if (this.NearestHoistedLocals != null)
     {
         List<long> list = new List<long>(vars.Count);
         foreach (ParameterExpression expression in vars)
         {
             ulong num = 0L;
             HoistedLocals nearestHoistedLocals = this.NearestHoistedLocals;
             while (!nearestHoistedLocals.Indexes.ContainsKey(expression))
             {
                 num += (ulong) 1L;
                 nearestHoistedLocals = nearestHoistedLocals.Parent;
             }
             ulong num2 = (num << 0x20) | ((ulong) nearestHoistedLocals.Indexes[expression]);
             list.Add((long) num2);
         }
         if (list.Count > 0)
         {
             this.EmitGet(this.NearestHoistedLocals.SelfVariable);
             lc.EmitConstantArray<long>(list.ToArray());
             lc.IL.Emit(OpCodes.Call, typeof(RuntimeOps).GetMethod("CreateRuntimeVariables", new Type[] { typeof(object[]), typeof(long[]) }));
             return;
         }
     }
     lc.IL.Emit(OpCodes.Call, typeof(RuntimeOps).GetMethod("CreateRuntimeVariables", Type.EmptyTypes));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:CompilerScope.cs


示例16: Enter

 internal CompilerScope Enter(LambdaCompiler lc, CompilerScope parent)
 {
     this.SetParent(lc, parent);
     this.AllocateLocals(lc);
     if (this.IsMethod && (this._closureHoistedLocals != null))
     {
         this.EmitClosureAccess(lc, this._closureHoistedLocals);
     }
     this.EmitNewHoistedLocals(lc);
     if (this.IsMethod)
     {
         this.EmitCachedVariables();
     }
     return this;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:CompilerScope.cs


示例17: EmitNewHoistedLocals

        // Emits creation of the hoisted local storage
        private void EmitNewHoistedLocals(LambdaCompiler lc)
        {
            if (_hoistedLocals == null)
            {
                return;
            }

            // create the array
            lc.IL.EmitInt(_hoistedLocals.Variables.Count);
            lc.IL.Emit(OpCodes.Newarr, typeof(object));

            // initialize all elements
            int i = 0;
            foreach (ParameterExpression v in _hoistedLocals.Variables)
            {
                // array[i] = new StrongBox<T>(...);
                lc.IL.Emit(OpCodes.Dup);
                lc.IL.EmitInt(i++);
                Type boxType = typeof(StrongBox<>).MakeGenericType(v.Type);

                if (IsMethod && lc.Parameters.Contains(v))
                {
                    // array[i] = new StrongBox<T>(argument);
                    int index = lc.Parameters.IndexOf(v);
                    lc.EmitLambdaArgument(index);
                    lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type }));
                }
                else if (v == _hoistedLocals.ParentVariable)
                {
                    // array[i] = new StrongBox<T>(closure.Locals);
                    ResolveVariable(v, _closureHoistedLocals).EmitLoad();
                    lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type }));
                }
                else
                {
                    // array[i] = new StrongBox<T>();
                    lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(Type.EmptyTypes));
                }
                // if we want to cache this into a local, do it now
                if (ShouldCache(v))
                {
                    lc.IL.Emit(OpCodes.Dup);
                    CacheBoxToLocal(lc, v);
                }
                lc.IL.Emit(OpCodes.Stelem_Ref);
            }

            // store it
            EmitSet(_hoistedLocals.SelfVariable);
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:51,代码来源:CompilerScope.cs


示例18: ArgumentStorage

 internal ArgumentStorage(LambdaCompiler compiler, ParameterExpression p) : base(compiler, p)
 {
     this._argument = compiler.GetLambdaArgument(compiler.Parameters.IndexOf(p));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:CompilerScope.cs


示例19: CacheBoxToLocal

 private void CacheBoxToLocal(LambdaCompiler lc, ParameterExpression v)
 {
     Debug.Assert(ShouldCache(v) && !_locals.ContainsKey(v));
     var local = new LocalBoxStorage(lc, v);
     local.EmitStoreBox();
     _locals.Add(v, local);
 }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:7,代码来源:CompilerScope.cs


示例20: EmitClosureAccess

        // Creates IL locals for accessing closures
        private void EmitClosureAccess(LambdaCompiler lc, HoistedLocals locals)
        {
            if (locals == null)
            {
                return;
            }

            EmitClosureToVariable(lc, locals);

            while ((locals = locals.Parent) != null)
            {
                ParameterExpression v = locals.SelfVariable;
                var local = new LocalStorage(lc, v);
                local.EmitStore(ResolveVariable(v));
                _locals.Add(v, local);
            }
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:18,代码来源:CompilerScope.cs



注:本文中的System.Linq.Expressions.Compiler.LambdaCompiler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Interpreter.Instruction类代码示例发布时间:2022-05-26
下一篇:
C# Expressions.UnaryExpression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap