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); }
public TotemScriptCode( TotemEngine engine, LightExpression<Func<TotemEngine, IDynamicMetaObjectProvider, object>> lambda, SourceUnit sourceUnit) : base(sourceUnit) { this.lambda = lambda; this.engine = engine; }
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); }
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; }
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; }