/// <summary> /// Produces a rule for the specified Action for the given arguments. /// /// The default implementation can produce rules for standard .NET types. Languages should /// override this and provide any custom behavior they need and fallback to the default /// implementation if no custom behavior is required. /// </summary> protected override void MakeRule(OldDynamicAction action, object[] args, RuleBuilder rule) { ContractUtils.RequiresNotNull(action, "action"); ContractUtils.RequiresNotNull(args, "args"); object[] extracted; CodeContext callerContext = ExtractCodeContext(args, out extracted); ContractUtils.RequiresNotNull(callerContext, "callerContext"); switch (action.Kind) { case DynamicActionKind.GetMember: new GetMemberBinderHelper(callerContext, (OldGetMemberAction)action, extracted, rule).MakeNewRule(); return; case DynamicActionKind.SetMember: new SetMemberBinderHelper(callerContext, (OldSetMemberAction)action, extracted, rule).MakeNewRule(); return; case DynamicActionKind.DeleteMember: new DeleteMemberBinderHelper(callerContext, (OldDeleteMemberAction)action, extracted, rule).MakeRule(); return; case DynamicActionKind.ConvertTo: new ConvertToBinderHelper(callerContext, (OldConvertToAction)action, extracted, rule).MakeRule(); return; default: throw new NotImplementedException(action.ToString()); } }
internal Expression Bind(OldDynamicAction action, object[] args, ReadOnlyCollection<ParameterExpression> parameters, LabelTarget returnLabel) { var builder = new RuleBuilder(parameters, returnLabel); MakeRule(action, args, builder); if (builder.Target != null) { return builder.CreateRule(); } return null; }
public Expression GetBoundPythonValue(RuleBuilder builder, ActionBinder binder, PythonType accessing) { return Ast.Call( typeof(PythonOps).GetMethod("SlotGetValue"), builder.Context, Ast.Constant(GetSlot(), typeof(PythonTypeSlot)), Ast.Constant(null), Ast.Constant(accessing) ); }
// This can produce a IsCallable rule that returns the immutable constant isCallable. // Beware that objects can have a mutable callable property. Eg, in Python, assign or delete the __call__ attribute. public static bool MakeIsCallableRule(CodeContext context, object self, bool isCallable, RuleBuilder rule) { rule.MakeTest(CompilerHelpers.GetType(self)); rule.Target = rule.MakeReturn( context.LanguageContext.Binder, Ast.Constant(isCallable) ); return true; }
public virtual Expression Bind(OldDynamicAction action, object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel) { var builder = new RuleBuilder(parameters, returnLabel); MakeRule(action, args, builder); if (builder.Target != null) { return(builder.CreateRule()); } return(null); }
public virtual ErrorInfo MakeEventValidation(RuleBuilder rule, MemberGroup members) { EventTracker ev = (EventTracker)members[0]; // handles in place addition of events - this validates the user did the right thing. return(ErrorInfo.FromValueNoError( Expression.Call( typeof(ScriptingRuntimeHelpers).GetMethod("SetEvent"), Expression.Constant(ev), rule.Parameters[1] ) )); }
public override Expression Bind(object[] args, ReadOnlyCollection<ParameterExpression> parameters, LabelTarget returnLabel) { ContractUtils.RequiresNotNull(args, "args"); CodeContext cc = ExtractCodeContext(ref args); ContractUtils.Requires(args.Length > 0); IOldDynamicObject ido = args[0] as IOldDynamicObject; ContractUtils.RequiresNotNull(ido, "args"); OldCallAction ca = OldCallAction.Make(cc.LanguageContext.Binder, _args); var builder = new RuleBuilder(parameters, returnLabel); if (!ido.GetRule(ca, cc, args, builder)) { throw new InvalidOperationException("Cannot perform call."); } return builder.CreateRule(); }
/// <summary> /// Internal helper to produce the actual expression used for the error when emitting /// the error into a rule. /// </summary> public Expression MakeErrorForRule(RuleBuilder rule, ActionBinder binder) { switch (_kind) { case ErrorInfoKind.Error: rule.IsError = true; return(rule.MakeReturn(binder, _value)); case ErrorInfoKind.Success: return(rule.MakeReturn(binder, _value)); case ErrorInfoKind.Exception: return(rule.MakeError(_value)); default: throw new InvalidOperationException(); } }
/// <summary> /// Produces a rule for the specified Action for the given arguments. /// /// The default implementation can produce rules for standard .NET types. Languages should /// override this and provide any custom behavior they need and fallback to the default /// implementation if no custom behavior is required. /// </summary> protected override void MakeRule(OldDynamicAction action, object[] args, RuleBuilder rule) { ContractUtils.RequiresNotNull(action, "action"); ContractUtils.RequiresNotNull(args, "args"); object[] extracted; CodeContext callerContext = ExtractCodeContext(args, out extracted); ContractUtils.RequiresNotNull(callerContext, "callerContext"); switch (action.Kind) { case DynamicActionKind.Call: new CallBinderHelper <OldCallAction>(callerContext, (OldCallAction)action, extracted, rule).MakeRule(); return; case DynamicActionKind.GetMember: new GetMemberBinderHelper(callerContext, (OldGetMemberAction)action, extracted, rule).MakeNewRule(); return; case DynamicActionKind.SetMember: new SetMemberBinderHelper(callerContext, (OldSetMemberAction)action, extracted, rule).MakeNewRule(); return; case DynamicActionKind.CreateInstance: new CreateInstanceBinderHelper(callerContext, (OldCreateInstanceAction)action, extracted, rule).MakeRule(); return; case DynamicActionKind.DoOperation: new DoOperationBinderHelper(callerContext, (OldDoOperationAction)action, extracted, rule).MakeRule(); return; case DynamicActionKind.DeleteMember: new DeleteMemberBinderHelper(callerContext, (OldDeleteMemberAction)action, extracted, rule).MakeRule(); return; case DynamicActionKind.ConvertTo: new ConvertToBinderHelper(callerContext, (OldConvertToAction)action, extracted, rule).MakeRule(); return; default: throw new NotImplementedException(action.ToString()); } }
public override Expression Bind(object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel) { ContractUtils.RequiresNotNull(args, "args"); CodeContext cc = ExtractCodeContext(ref args); ContractUtils.Requires(args.Length > 0); IOldDynamicObject ido = args[0] as IOldDynamicObject; ContractUtils.RequiresNotNull(ido, "args"); OldCallAction ca = OldCallAction.Make(cc.LanguageContext.Binder, _args); var builder = new RuleBuilder(parameters, returnLabel); if (!ido.GetRule(ca, cc, args, builder)) { throw new InvalidOperationException("Cannot perform call."); } return(builder.CreateRule()); }
public MemberBinderHelper(CodeContext context, TActionKind action, object[] args, RuleBuilder rule) : base(context, action) { ContractUtils.RequiresNotNull(args, "args"); if (args.Length == 0) { throw new ArgumentException("args must have at least one member"); } _args = args; _target = args[0]; if (CompilerHelpers.IsStrongBox(_target)) { _strongBoxType = _target.GetType(); _target = ((IStrongBox)_target).Value; } _rule = rule; }
/// <summary> /// Produces a rule for the specified Action for the given arguments. /// </summary> /// <param name="action">The Action that is being performed.</param> /// <param name="args">The arguments to the action as provided from the call site at runtime.</param> /// <param name="rule">The rule builder that will hold the result</param> protected abstract void MakeRule(OldDynamicAction action, object[] args, RuleBuilder rule);
/// <summary> /// Provides a way for the binder to provide a custom error message when lookup fails. Just /// doing this for the time being until we get a more robust error return mechanism. /// </summary> public virtual Expression MakeUndeletableMemberError(RuleBuilder rule, Type type, string name) { return MakeReadOnlyMemberError(rule, type, name); }
public virtual ErrorInfo MakeEventValidation(RuleBuilder rule, MemberGroup members) { EventTracker ev = (EventTracker)members[0]; // handles in place addition of events - this validates the user did the right thing. return ErrorInfo.FromValueNoError( Expression.Call( typeof(ScriptingRuntimeHelpers).GetMethod("SetEvent"), AstUtils.Constant(ev), rule.Parameters[1] ) ); }
private bool MakeGetMemberRule(OldGetMemberAction action, CodeContext context, RuleBuilder rule) { object value; if (TryGetValue(action.Name, out value)) { Debug.Assert(value is MemberTracker); MemberTracker memValue = (MemberTracker)value; rule.MakeTest(typeof(NamespaceTracker)); rule.AddTest( Expression.Equal( Expression.Property( Expression.Convert(rule.Parameters[0], typeof(NamespaceTracker)), typeof(NamespaceTracker).GetProperty("Id") ), Expression.Constant(Id) ) ); Expression target = context.LanguageContext.Binder.ReturnMemberTracker(memValue.DeclaringType, memValue); rule.Target = rule.MakeReturn(context.LanguageContext.Binder, target); return(true); } return(false); }
/// <summary> /// Provides a way for the binder to provide a custom error message when lookup fails. Just /// doing this for the time being until we get a more robust error return mechanism. /// </summary> public virtual Expression MakeReadOnlyMemberError(RuleBuilder rule, Type type, string name) { return rule.MakeError( Expression.New( typeof(MissingMemberException).GetConstructor(new Type[] { typeof(string) }), AstUtils.Constant(name) ) ); }
public CreateInstanceBinderHelper(CodeContext context, OldCreateInstanceAction action, object[] args, RuleBuilder rule) : base(context, action, args, rule) { }
public override ErrorInfo MakeEventValidation(RuleBuilder rule, MemberGroup members) { EventTracker ev = (EventTracker)members[0]; return ErrorInfo.FromValueNoError( Ast.Call( typeof(PythonOps).GetMethod("SlotTrySetValue"), rule.Context, Ast.Constant(PythonTypeOps.GetReflectedEvent(ev)), AstUtils.Convert(rule.Parameters[0], typeof(object)), Ast.Constant(null, typeof(PythonType)), AstUtils.Convert(rule.Parameters[1], typeof(object)) ) ); }
public CallBinderHelper(CodeContext context, TAction action, object[] args, RuleBuilder rule, IList <MethodBase> targets) : this(context, action, args, rule) { _targets = ArrayUtils.ToArray(targets); _maxLevel = NarrowingLevel.All; }
/// <summary> /// Internal helper to produce the actual expression used for the error when emitting /// the error into a rule. /// </summary> public Expression MakeErrorForRule(RuleBuilder rule, ActionBinder binder) { switch (_kind) { case ErrorInfoKind.Error: rule.IsError = true; return rule.MakeReturn(binder, _value); case ErrorInfoKind.Success: return rule.MakeReturn(binder, _value); case ErrorInfoKind.Exception: return rule.MakeError(_value); default: throw new InvalidOperationException(); } }
public bool GetRule(OldDynamicAction action, CodeContext context, object[] args, RuleBuilder rule) { if (action.Kind == DynamicActionKind.GetMember) { return(MakeGetMemberRule((OldGetMemberAction)action, context, rule)); } return(false); }
public bool GetRule(OldDynamicAction action, CodeContext context, object[] args, RuleBuilder rule) { if (action.Kind == DynamicActionKind.GetMember) { return MakeGetMemberRule((OldGetMemberAction)action, context, rule); } return false; }
/// <summary> /// Gets an Expression which calls the binding target if the method binding succeeded. /// /// Throws InvalidOperationException if the binding failed. /// /// OBSOLETE /// </summary> public Expression MakeExpression(RuleBuilder rule, IList<Expression> parameters) { ContractUtils.RequiresNotNull(rule, "rule"); if (_target == null) { throw new InvalidOperationException("An expression cannot be produced because the method binding was unsuccessful."); } return MakeExpression(new ParameterBinderWithCodeContext(_target.Binder._binder, rule.Context), parameters); }
/// <summary> /// Provides a way for the binder to provide a custom error message when lookup fails. Just /// doing this for the time being until we get a more robust error return mechanism. /// </summary> public virtual Expression MakeUndeletableMemberError(RuleBuilder rule, Type type, string name) { return(MakeReadOnlyMemberError(rule, type, name)); }
private readonly RuleBuilder _rule; // the rule we're building and returning public DoOperationBinderHelper(CodeContext context, OldDoOperationAction action, object[] args, RuleBuilder rule) : base(context, action) { _args = args; _types = CompilerHelpers.GetTypes(args); _rule = rule; _rule.MakeTest(_types); }
public ConvertToBinderHelper(CodeContext context, OldConvertToAction action, object[] args, RuleBuilder rule) : base(context, action) { ContractUtils.Requires(args.Length == 1, "can only convert single argument"); _arg = args[0]; _rule = rule; }
// This can produce a IsCallable rule that returns the immutable constant isCallable. // Beware that objects can have a mutable callable property. Eg, in Python, assign or delete the __call__ attribute. public static bool MakeIsCallableRule(CodeContext context, object self, bool isCallable, RuleBuilder rule) { rule.MakeTest(CompilerHelpers.GetType(self)); rule.Target = rule.MakeReturn( context.LanguageContext.Binder, Ast.Constant(isCallable) ); return(true); }
private bool MakeGetMemberRule(OldGetMemberAction action, CodeContext context, RuleBuilder rule) { object value; if (TryGetValue(action.Name, out value)) { Debug.Assert(value is MemberTracker); MemberTracker memValue = (MemberTracker)value; rule.MakeTest(typeof(NamespaceTracker)); rule.AddTest( Expression.Equal( Expression.Property( Expression.Convert(rule.Parameters[0], typeof(NamespaceTracker)), typeof(NamespaceTracker).GetProperty("Id") ), AstUtils.Constant(Id) ) ); Expression target = context.LanguageContext.Binder.ReturnMemberTracker(memValue.DeclaringType, memValue); rule.Target = rule.MakeReturn(context.LanguageContext.Binder, target); return true; } return false; }
public DeleteMemberBinderHelper(CodeContext context, OldDeleteMemberAction action, object[] args, RuleBuilder rule) : base(context, action, args, rule) { }