Esempio n. 1
0
        private LookupCompilationDelegate CompileBody(LightExpression <LookupCompilationDelegate> lambda)
        {
            LookupCompilationDelegate func;

            var extractConstant = ExtractConstant(lambda);

            if (extractConstant != null)
            {
                // skip compiling for really simple code
                object value = extractConstant.Value;
                return((codeCtx, functionCode) => value);
            }

            PythonContext pc = (PythonContext)Ast.CompilerContext.SourceUnit.LanguageContext;

            if (ShouldInterpret(pc))
            {
                func = lambda.Compile(pc.Options.CompilationThreshold);
            }
            else
            {
                func = lambda.ReduceToLambda().Compile(pc.EmitDebugSymbols(Ast.CompilerContext.SourceUnit));
            }

            return(func);
        }
Esempio n. 2
0
 public TotemScriptCode(
     TotemEngine engine,
     LightExpression<Func<TotemEngine, IDynamicMetaObjectProvider, object>> lambda,
     SourceUnit sourceUnit)
     : base(sourceUnit)
 {
     this.lambda = lambda;
     this.engine = engine;
 }
Esempio n. 3
0
        private static PythonConstantExpression ExtractConstant(LightExpression <LookupCompilationDelegate> lambda)
        {
            if (!(lambda.Body is BlockExpression body) ||
                body.Expressions.Count != 2 ||
                !(body.Expressions[0] is DebugInfoExpression) ||
                body.Expressions[1].NodeType != ExpressionType.Convert ||
                !(((MSAst.UnaryExpression)body.Expressions[1]).Operand is PythonConstantExpression))
            {
                return(null);
            }

            return((PythonConstantExpression)((MSAst.UnaryExpression)body.Expressions[1]).Operand);
        }
Esempio n. 4
0
        private static PythonConstantExpression ExtractConstant(LightExpression<LookupCompilationDelegate> lambda) {
            var body = lambda.Body as BlockExpression;
            if (body == null || 
                body.Expressions.Count != 2 || 
                !(body.Expressions[0] is DebugInfoExpression) || 
                body.Expressions[1].NodeType  != ExpressionType.Convert ||
                !(((MSAst.UnaryExpression)body.Expressions[1]).Operand is PythonConstantExpression)) {
                return null;
            }

            return (PythonConstantExpression)((MSAst.UnaryExpression)body.Expressions[1]).Operand;
        }
Esempio n. 5
0
        private LookupCompilationDelegate CompileBody(LightExpression<LookupCompilationDelegate> lambda) {
            LookupCompilationDelegate func;

            var extractConstant = ExtractConstant(lambda);

            if (extractConstant != null) {
                // skip compiling for really simple code
                object value = extractConstant.Value;
                return (codeCtx, functionCode) => value;
            }

            PythonContext pc = (PythonContext)Ast.CompilerContext.SourceUnit.LanguageContext;
            if (ShouldInterpret(pc)) {
                func = lambda.Compile(pc.Options.CompilationThreshold);
            } else {
                func = lambda.ReduceToLambda().Compile(pc.EmitDebugSymbols(Ast.CompilerContext.SourceUnit));
            }

            return func;
        }