Exemplo n.º 1
0
        internal override void RewriteBody(MSAst.ExpressionVisitor visitor)
        {
            _dlrBody = null;    // clear the cached body if we've been reduced

            MSAst.Expression funcCode = GlobalParent.Constant(GetOrMakeFunctionCode());
            FuncCodeExpr = funcCode;

            Body = new RewrittenBodyStatement(Body, visitor.Visit(Body));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the LambdaExpression which is the actual function body.
        /// </summary>
        private LightLambdaExpression EnsureFunctionLambda()
        {
            if (_dlrBody == null)
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Creating FunctionBody");
                _dlrBody = CreateFunctionLambda();
            }

            return(_dlrBody);
        }
Exemplo n.º 3
0
        internal override LightLambdaExpression GetLambda()
        {
            if (_dlrBody == null)
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Creating FunctionBody");
                _dlrBody = MakeClassBody();
            }

            return(_dlrBody);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns an expression which creates the function object.
        /// </summary>
        internal MSAst.Expression MakeFunctionExpression()
        {
            List <MSAst.Expression> defaults = new List <MSAst.Expression>(0);

            foreach (var param in _parameters)
            {
                if (param.DefaultValue != null)
                {
                    defaults.Add(AstUtils.Convert(param.DefaultValue, typeof(object)));
                }
            }

            MSAst.Expression funcCode = GlobalParent.Constant(GetOrMakeFunctionCode());
            FuncCodeExpr = funcCode;

            MSAst.Expression ret;
            if (EmitDebugFunction())
            {
                LightLambdaExpression code = CreateFunctionLambda();

                // we need to compile all of the debuggable code together at once otherwise mdbg gets confused.  If we're
                // in tracing mode we'll still compile things one off though just to keep things simple.  The code will still
                // be debuggable but naive debuggers like mdbg will have more issues.
                ret = Ast.Call(
                    AstMethods.MakeFunctionDebug,                                                   // method
                    Parent.LocalContext,                                                            // 1. Emit CodeContext
                    FuncCodeExpr,                                                                   // 2. FunctionCode
                    ((IPythonGlobalExpression)GetVariableExpression(_nameVariable)).RawValue(),     // 3. module name
                    defaults.Count == 0 ?                                                           // 4. default values
                    AstUtils.Constant(null, typeof(object[])) :
                    (MSAst.Expression)Ast.NewArrayInit(typeof(object), defaults),
                    IsGenerator ?
                    (MSAst.Expression) new PythonGeneratorExpression(code, GlobalParent.PyContext.Options.CompilationThreshold) :
                    (MSAst.Expression)code
                    );
            }
            else
            {
                ret = Ast.Call(
                    AstMethods.MakeFunction,                                                        // method
                    Parent.LocalContext,                                                            // 1. Emit CodeContext
                    FuncCodeExpr,                                                                   // 2. FunctionCode
                    ((IPythonGlobalExpression)GetVariableExpression(_nameVariable)).RawValue(),     // 3. module name
                    defaults.Count == 0 ?                                                           // 4. default values
                    AstUtils.Constant(null, typeof(object[])) :
                    (MSAst.Expression)Ast.NewArrayInit(typeof(object), defaults)
                    );
            }

            return(AddDecorators(ret, _decorators));
        }
Exemplo n.º 5
0
 internal override void RewriteBody(MSAst.ExpressionVisitor visitor) {
     _dlrBody = null;
     _body = new RewrittenBodyStatement(Body, visitor.Visit(Body));
 }
Exemplo n.º 6
0
        internal override LightLambdaExpression GetLambda() {
            if (_dlrBody == null) {
                PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Creating FunctionBody");
                _dlrBody = MakeClassBody();
            }

            return _dlrBody;
        }
Exemplo n.º 7
0
 internal override void RewriteBody(PythonAst.LookupVisitor visitor) {
     _dlrBody = null;
     _body = new PythonAst.RewrittenBodyStatement(Body, visitor.Visit(Body));
 }
Exemplo n.º 8
0
 internal override void RewriteBody(MSAst.ExpressionVisitor visitor)
 {
     _dlrBody = null;
     _body    = new RewrittenBodyStatement(Body, visitor.Visit(Body));
 }
Exemplo n.º 9
0
 internal override void RewriteBody(PythonAst.LookupVisitor visitor)
 {
     _dlrBody = null;
     _body    = new PythonAst.RewrittenBodyStatement(Body, visitor.Visit(Body));
 }
Exemplo n.º 10
0
 internal override void RewriteBody(PythonAst.LookupVisitor visitor) {
     _dlrBody = null;    // clear the cached body if we've been reduced
     
     MSAst.Expression funcCode = GlobalParent.Constant(GetOrMakeFunctionCode());
     FuncCodeExpr = funcCode;
     
     Body = new PythonAst.RewrittenBodyStatement(Body, visitor.Visit(Body));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Creates the LambdaExpression which is the actual function body.
        /// </summary>
        private LightLambdaExpression EnsureFunctionLambda() {
            if (_dlrBody == null) {
                PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Creating FunctionBody");
                _dlrBody = CreateFunctionLambda();
            }

            return _dlrBody;
        }