Beispiel #1
0
        public static LambdaExpression Rebind(BoundExpression expression)
        {
            var rebinder = new RebindToScope {
                BlockCount = expression.BlockNumber
            };

            return(rebinder.Rebind(expression.Expression));
        }
Beispiel #2
0
 /// <summary>
 /// Converts a single bind expression to the Haxl monad.
 /// </summary>
 /// <param name="bind"></param>
 /// <returns></returns>
 public static Func <Scope, Haxl> BindToHaxl(BindStatement bind)
 {
     return(scope =>
     {
         var rewritten = RebindToScope.Rebind(bind.Expression);
         var value = rewritten.Compile().DynamicInvoke(scope);
         var wrapped = (Fetchable)value;
         return wrapped.ToHaxlFetch(bind.Expression.BindVariable, scope);
     });
 }
Beispiel #3
0
 /// <summary>
 /// Converts a project expression to Haxl monad.
 /// </summary>
 public static Func <Scope, Haxl> ProjectToHaxl(ProjectStatement project, string parentBind)
 {
     return(scope => Haxl.FromFunc((cache, logger) =>
     {
         var rewritten = RebindToScope.Rebind(project.Expression);
         var result = rewritten.Compile().DynamicInvoke(scope);
         return Done.New(_ =>
         {
             if (project.Expression.BindVariable == HAXL_RESULT_NAME &&
                 !scope.IsRoot &&
                 parentBind != null)
             {
                 return scope.WriteParent(parentBind, result);
             }
             return scope.Add(project.Expression.BindVariable, result);
         });
     }));
 }