本文整理汇总了C#中PythonContext.Operation方法的典型用法代码示例。如果您正苦于以下问题:C# PythonContext.Operation方法的具体用法?C# PythonContext.Operation怎么用?C# PythonContext.Operation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonContext
的用法示例。
在下文中一共展示了PythonContext.Operation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnaryOperationBinder
public static DynamicMetaObjectBinder UnaryOperationBinder(PythonContext state, PythonOperationKind operatorName) {
ExpressionType? et = GetExpressionTypeFromUnaryOperator(operatorName);
if (et == null) {
return state.Operation(
operatorName
);
}
return state.UnaryOperation(et.Value);
}
示例2: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ pyContext, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(pyContext, "__coerce__", types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
pyContext,
returnTransform(
DynamicExpression.Dynamic(
pyContext.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}
示例3: DoCoerce
/// <summary>
/// calls __coerce__ for old-style classes and performs the operation if the coercion is successful.
/// </summary>
private static void DoCoerce(PythonContext/*!*/ state, ConditionalBuilder/*!*/ bodyBuilder, PythonOperationKind op, DynamicMetaObject/*!*/[]/*!*/ types, bool reverse, Func<Expression, Expression> returnTransform) {
ParameterExpression coerceResult = Ast.Variable(typeof(object), "coerceResult");
ParameterExpression coerceTuple = Ast.Variable(typeof(PythonTuple), "coerceTuple");
if (!bodyBuilder.TestCoercionRecursionCheck) {
// during coercion we need to enforce recursion limits if
// they're enabled and the rule's test needs to reflect this.
bodyBuilder.Restrictions = bodyBuilder.Restrictions.Merge(
BindingRestrictions.GetExpressionRestriction(
Ast.Equal(
Ast.Call(typeof(PythonOps).GetMethod("ShouldEnforceRecursion")),
AstUtils.Constant(PythonFunction.EnforceRecursion)
)
)
);
bodyBuilder.TestCoercionRecursionCheck = true;
}
// tmp = self.__coerce__(other)
// if tmp != null && tmp != NotImplemented && (tuple = PythonOps.ValidateCoerceResult(tmp)) != null:
// return operation(tuple[0], tuple[1])
SlotOrFunction slot = SlotOrFunction.GetSlotOrFunction(state, Symbols.Coerce, types);
if (slot.Success) {
bodyBuilder.AddCondition(
Ast.AndAlso(
Ast.Not(
Ast.TypeIs(
Ast.Assign(
coerceResult,
slot.Target.Expression
),
typeof(OldInstance)
)
),
Ast.NotEqual(
Ast.Assign(
coerceTuple,
Ast.Call(
typeof(PythonOps).GetMethod("ValidateCoerceResult"),
coerceResult
)
),
AstUtils.Constant(null)
)
),
BindingHelpers.AddRecursionCheck(
returnTransform(
Ast.Dynamic(
state.Operation(op | PythonOperationKind.DisableCoerce),
op == PythonOperationKind.Compare ? typeof(int) : typeof(object),
reverse ? CoerceTwo(coerceTuple) : CoerceOne(coerceTuple),
reverse ? CoerceOne(coerceTuple) : CoerceTwo(coerceTuple)
)
)
)
);
bodyBuilder.AddVariable(coerceResult);
bodyBuilder.AddVariable(coerceTuple);
}
}