当前位置: 首页>>代码示例>>C#>>正文


C# Scope.EmitLocals方法代码示例

本文整理汇总了C#中Scope.EmitLocals方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.EmitLocals方法的具体用法?C# Scope.EmitLocals怎么用?C# Scope.EmitLocals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scope的用法示例。


在下文中一共展示了Scope.EmitLocals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildMainMethod

        public JsMain BuildMainMethod(BoundProgram program)
        {
            if (program == null)
                throw new ArgumentNullException("program");

            var method = _scriptBuilder.CreateFunction(typeof(JsMain), MainMethodName, null);

            _scope = new Scope(
                this,
                method.GetILBuilder(),
                false,
                program.Body,
                null,
                _scriptBuilder,
                null
            );

            _scope.EmitLocals(program.Body.TypeManager);

            if (program.Body.Closure != null)
                EmitClosureSetup(program.Body);

            EmitInitializeArguments(program.Body);

            EmitStatements(program.Body.Body);

            // Ensure that we return something.

            EmitReturn(new BoundReturn(null, SourceLocation.Missing));

            // Emit the exceptional return block if we need it.

            EmitExceptionalReturn();

            _scriptBuilder.Commit();

            return (JsMain)Delegate.CreateDelegate(typeof(JsMain), method.Method);
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:38,代码来源:CodeGenerator.cs

示例2: DeclareFunction

        private IFunctionBuilder DeclareFunction(BoundFunction function, ITypeBuilder typeBuilder, string sourceCode)
        {
            var method = typeBuilder.CreateFunction(typeof(JsFunction), function.Name, sourceCode);

            var argumentsReferenced = (function.Body.Flags & BoundBodyFlags.ArgumentsReferenced) != 0;
            BoundClosureField argumentsClosureField = null;

            var il = method.GetILBuilder();

            if (argumentsReferenced && function.Body.Closure != null)
                function.Body.Closure.Fields.TryGetValue(BoundClosure.ArgumentsFieldName, out argumentsClosureField);

            _scope = new Scope(
                this,
                il,
                true,
                function.Body,
                argumentsClosureField,
                typeBuilder,
                _scope
            );

            _scope.EmitLocals(function.Body.TypeManager);

            // Instantiate the closure if we own it.
            if (function.Body.Closure != null)
                EmitClosureSetup(function.Body);

            EmitInitializeArguments(function.Body);

            // Build the arguments object when we need it.

            if (argumentsReferenced)
            {
                // Initialize the arguments array.

                _scope.ArgumentsEmitter.EmitSetValue(new BoundEmitExpression(
                    BoundValueType.Object,
                    () =>
                    {
                        _scope.EmitLoad(SpecialLocal.Runtime);
                        _scope.EmitLoad(SpecialLocal.Callee);
                        _scope.EmitLoad(SpecialLocal.ArgumentsRaw);

                        IL.EmitCall(_runtimeCreateArguments);
                    }
                ));
            }

            // Emit the body.

            EmitStatements(function.Body.Body);

            // Ensure that we return something.

            EmitReturn(new BoundReturn(null, SourceLocation.Missing));

            // Emit the exceptional return block if we need it.

            EmitExceptionalReturn();

            // Put a debug location at the end of the function.

            if (function.Location != null)
            {
                IL.MarkSequencePoint(new SourceLocation(
                    function.Location.EndOffset,
                    function.Location.EndLine,
                    function.Location.EndColumn,
                    function.Location.EndOffset + 1,
                    function.Location.EndLine,
                    function.Location.EndColumn + 1,
                    null
                ));
            }

            _scope = _scope.Parent;

            return method;
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:80,代码来源:CodeGenerator.cs


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