private void CompileWithArrayGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) { GlobalArrayRewriter rewriter = new GlobalArrayRewriter(); Expression <DlrMainCallTarget> lambda = rewriter.RewriteLambda(Code); // Compile target target = lambda.Compile(SourceUnit.EmitDebugSymbols); // Create globals globals = rewriter.CreateDictionary(); }
protected override MethodBuilder CompileForSave(TypeGen typeGen, Dictionary <SymbolId, FieldBuilder> symbolDict) { // first, serialize constants and dynamic sites: ToDiskRewriter diskRewriter = new ToDiskRewriter(typeGen); LambdaExpression lambda = diskRewriter.RewriteLambda(Code); // rewrite global variables: var globalRewriter = new GlobalArrayRewriter(symbolDict, typeGen); lambda = globalRewriter.RewriteLambda(lambda); MethodBuilder builder = lambda.CompileToMethod(typeGen.TypeBuilder, CompilerHelpers.PublicStatic | MethodAttributes.SpecialName, false); builder.SetCustomAttribute(new CustomAttributeBuilder( typeof(CachedOptimizedCodeAttribute).GetConstructor(new Type[] { typeof(string[]) }), new object[] { ArrayUtils.ToArray(globalRewriter.Names) } )); return(builder); }
protected override KeyValuePair<MethodBuilder, Type> CompileForSave(TypeGen typeGen, Dictionary<SymbolId, FieldBuilder> symbolDict) { // first, serialize constants and dynamic sites: ToDiskRewriter diskRewriter = new ToDiskRewriter(typeGen); LambdaExpression lambda = diskRewriter.RewriteLambda(Code); // rewrite global variables: var globalRewriter = new GlobalArrayRewriter(symbolDict, typeGen); lambda = globalRewriter.RewriteLambda(lambda); MethodBuilder builder = typeGen.TypeBuilder.DefineMethod(lambda.Name ?? "lambda_method", CompilerHelpers.PublicStatic | MethodAttributes.SpecialName); lambda.CompileToMethod(builder, false); builder.SetCustomAttribute(new CustomAttributeBuilder( typeof(CachedOptimizedCodeAttribute).GetConstructor(new Type[] { typeof(string[]) }), new object[] { ArrayUtils.ToArray(globalRewriter.Names) } )); return new KeyValuePair<MethodBuilder, Type>(builder, typeof(DlrMainCallTarget)); }
private void CompileWithArrayGlobals(out DlrMainCallTarget target, out IAttributesCollection globals) { GlobalArrayRewriter rewriter = new GlobalArrayRewriter(); Expression<DlrMainCallTarget> lambda = rewriter.RewriteLambda(Code); // Compile target target = lambda.Compile(SourceUnit.EmitDebugSymbols); // Create globals globals = rewriter.CreateDictionary(); }