public CodegenExpression Codegen( CodegenExpression reference, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { CodegenMethod methodNode = codegenMethodScope.MakeChild( typeof(long), typeof(IntervalDeltaExprTimePeriodNonConstForge), codegenClassScope) .AddParam(typeof(long), "reference"); methodNode.Block .DeclareVar<double>( "sec", timePeriod.EvaluateAsSecondsCodegen(methodNode, exprSymbol, codegenClassScope)) .MethodReturn( timeAbacus.DeltaForSecondsDoubleCodegen( Ref("sec"), codegenClassScope)); return LocalMethod(methodNode, reference); }
public static CodegenExpression MakePatternDeltaLambda( ExprNode parameter, MatchedEventConvertorForge convertor, TimeAbacus timeAbacus, CodegenMethod method, CodegenClassScope classScope) { var computeDelta = new CodegenExpressionLambda(method.Block) .WithParam<MatchedEventMap>("beginState") .WithParam<PatternAgentInstanceContext>("context"); var compute = NewInstance<PatternDeltaCompute>(computeDelta); //var compute = NewAnonymousClass(method.Block, typeof(PatternDeltaCompute)); //var computeDelta = CodegenMethod.MakeMethod(typeof(long), typeof(PatternDeltaComputeUtil), classScope) // .AddParam( // CodegenNamedParam.From( // typeof(MatchedEventMap), // "beginState", // typeof(PatternAgentInstanceContext), // "context")); //compute.AddMethod("ComputeDelta", computeDelta); if (parameter is ExprTimePeriod) { var timePeriod = (ExprTimePeriod) parameter; var time = ExprDotName(Ref("context"), "Time"); if (timePeriod.IsConstantResult) { var delta = classScope.AddDefaultFieldUnshared<TimePeriodCompute>( true, timePeriod.TimePeriodComputeForge.MakeEvaluator( classScope.NamespaceScope.InitMethod, classScope)); computeDelta.Block .ReturnMethodOrBlock( ExprDotMethod( delta, "DeltaAdd", time, ConstantNull(), ConstantTrue(), ExprDotMethod(Ref("context"), "GetAgentInstanceContext"))); } else { var delta = classScope.AddDefaultFieldUnshared<TimePeriodCompute>( true, timePeriod.TimePeriodComputeForge.MakeEvaluator( classScope.NamespaceScope.InitMethod, classScope)); computeDelta.Block .DeclareVar<EventBean[]>( "events", LocalMethod( convertor.Make(method, classScope), //convertor.Make(computeDelta, classScope), Ref("beginState"))) .ReturnMethodOrBlock( ExprDotMethod( delta, "DeltaAdd", time, Ref("events"), ConstantTrue(), ExprDotMethod(Ref("context"), "GetAgentInstanceContext"))); } } else { var eval = CodegenLegoMethodExpression.CodegenExpression(parameter.Forge, method, classScope, true); CodegenExpression events; if (parameter.Forge.ForgeConstantType.IsConstant) { events = ConstantNull(); } else { events = LocalMethod( convertor.Make(method, classScope), //convertor.Make(computeDelta, classScope), Ref("beginState")); } computeDelta.Block .DeclareVar<EventBean[]>("events", events) .DeclareVar( parameter.Forge.EvaluationType.GetBoxedType(), "result", LocalMethod( eval, Ref("events"), ConstantTrue(), ExprDotMethod(Ref("context"), "GetAgentInstanceContext"))); if (parameter.Forge.EvaluationType.CanBeNull()) { computeDelta.Block .IfRefNull("result") .BlockThrow( NewInstance<EPException>(Constant("Null value returned for guard expression"))); } computeDelta.Block.ReturnMethodOrBlock( timeAbacus.DeltaForSecondsDoubleCodegen(Ref("result"), classScope)); } return compute; }