public DynamicMetaObject Bind (DynamicContext ctx, Type callingType) { Expression res; try { var rc = new Compiler.ResolveContext (new RuntimeBinderContext (ctx, callingType), ResolveOptions); // Static typemanager and internal caches are not thread-safe lock (resolver) { expr = expr.Resolve (rc, Compiler.ResolveFlags.VariableOrValue); } if (expr == null) throw new RuntimeBinderInternalCompilerException ("Expression resolved to null"); res = expr.MakeExpression (new Compiler.BuilderContext ()); } catch (RuntimeBinderException e) { if (errorSuggestion != null) return errorSuggestion; res = CreateBinderException (e.Message); } catch (Exception) { if (errorSuggestion != null) return errorSuggestion; throw; } return new DynamicMetaObject (res, restrictions); }
public static SLE.Expression MakeExpression(BuilderContext ctx, Expression instance, MethodSpec mi, Arguments args) { #if STATIC throw new NotSupportedException(); #else var instance_expr = instance == null ? null : instance.MakeExpression(ctx); return(SLE.Expression.Call(instance_expr, (MethodInfo)mi.GetMetaInfo(), Arguments.MakeExpression(args, ctx))); #endif }
public static DynamicMetaObject Bind(DynamicMetaObject target, Compiler.Expression expr, BindingRestrictions restrictions, DynamicMetaObject errorSuggestion) { var report = new Compiler.Report(ErrorPrinter.Instance) { WarningLevel = 0 }; var ctx = new Compiler.CompilerContext(report); Compiler.RootContext.ToplevelTypes = new Compiler.ModuleContainer(ctx, true); InitializeCompiler(ctx); Expression res; try { // TODO: ResolveOptions Compiler.ResolveContext rc = new Compiler.ResolveContext(new RuntimeBinderContext(ctx)); // Static typemanager and internal caches are not thread-safe lock (resolver) { expr = expr.Resolve(rc); } if (expr == null) { throw new RuntimeBinderInternalCompilerException("Expression resolved to null"); } res = expr.MakeExpression(new Compiler.BuilderContext()); } catch (RuntimeBinderException e) { if (errorSuggestion != null) { return(errorSuggestion); } if (binder_exception_ctor == null) { binder_exception_ctor = typeof(RuntimeBinderException).GetConstructor(new[] { typeof(string) }); } // // Uses target type to keep expressions composition working // res = Expression.Throw(Expression.New(binder_exception_ctor, Expression.Constant(e.Message)), target.LimitType); } catch (Exception) { if (errorSuggestion != null) { return(errorSuggestion); } throw; } return(new DynamicMetaObject(res, restrictions)); }
public DynamicMetaObject Bind(DynamicContext ctx, Type callingType) { Expression res; try { var rc = new Compiler.ResolveContext(new RuntimeBinderContext(ctx, callingType), ResolveOptions); // Static typemanager and internal caches are not thread-safe lock (resolver) { expr = expr.Resolve(rc, Compiler.ResolveFlags.VariableOrValue); } if (expr == null) { throw new RuntimeBinderInternalCompilerException("Expression resolved to null"); } res = expr.MakeExpression(new Compiler.BuilderContext()); } catch (RuntimeBinderException e) { if (errorSuggestion != null) { return(errorSuggestion); } res = CreateBinderException(e.Message); } catch (Exception) { if (errorSuggestion != null) { return(errorSuggestion); } throw; } return(new DynamicMetaObject(res, restrictions)); }
public static SLE.Expression MakeExpression (BuilderContext ctx, Expression instance, MethodSpec mi, Arguments args) { #if STATIC throw new NotSupportedException (); #else var instance_expr = instance == null ? null : instance.MakeExpression (ctx); return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx)); #endif }