Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad2b377

Browse files
committed
Use reverse instead of forward (semantics) and add comparison operators
1 parente7da0bc commitad2b377

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

‎src/runtime/methodbinder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
351351
intclrnargs=pi.Length;
352352
isOperator=isOperator&&pynargs==clrnargs-1;// Handle mismatched arg numbers due to Python operator being bound.
353353
// Preprocessing pi to remove either the first or second argument.
354-
boolisForward=isOperator&&OperatorMethod.IsForward((MethodInfo)mi);// Only cast if isOperator.
355-
if(isOperator&&isForward){
354+
boolisReverse=isOperator&&OperatorMethod.IsReverse((MethodInfo)mi);// Only cast if isOperator.
355+
if(isOperator&&!isReverse){
356356
// The first Python arg is the right operand, while the bound instance is the left.
357357
// We need to skip the first (left operand) CLR argument.
358358
pi=pi.Skip(1).Take(1).ToArray();
359359
}
360-
elseif(isOperator&&!isForward){
360+
elseif(isOperator&&isReverse){
361361
// The first Python arg is the left operand.
362362
// We need to take the first CLR argument.
363363
pi=pi.Take(1).ToArray();
@@ -377,10 +377,10 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
377377
{
378378
// Postprocessing to extend margs.
379379
varmargsTemp=newobject[2];
380-
// Ifforward, thebound instance is the left operand.
381-
intboundOperandIndex=isForward?0:1;
382-
// Ifforward, thepassed instance is the right operand.
383-
intpassedOperandIndex=isForward?1:0;
380+
// Ifreverse, thepassed instance is the left operand.
381+
intpassedOperandIndex=isReverse?0:1;
382+
// Ifreverse, thebound instance is the right operand.
383+
intboundOperandIndex=isReverse?1:0;
384384
margsTemp[boundOperandIndex]=co.inst;
385385
margsTemp[passedOperandIndex]=margs[0];
386386
margs=margsTemp;

‎src/runtime/operatormethod.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ static OperatorMethod()
4646
["op_LeftShift"]=newSlotDefinition("__lshift__",TypeOffset.nb_lshift),
4747
["op_RightShift"]=newSlotDefinition("__rshift__",TypeOffset.nb_rshift),
4848
["op_Modulus"]=newSlotDefinition("__mod__",TypeOffset.nb_remainder),
49-
["op_OneComplement"]=newSlotDefinition("__invert__",TypeOffset.nb_invert)
49+
["op_OneComplement"]=newSlotDefinition("__invert__",TypeOffset.nb_invert),
50+
["op_GreaterThan"]=newSlotDefinition("__gt__",TypeOffset.tp_richcompare),
51+
["op_GreaterThanOrEqual"]=newSlotDefinition("__ge__",TypeOffset.tp_richcompare),
52+
["op_LessThan"]=newSlotDefinition("__lt__",TypeOffset.tp_richcompare),
53+
["op_LessThanOrEqual"]=newSlotDefinition("__le__",TypeOffset.tp_richcompare)
5054
};
5155
}
5256

@@ -137,15 +141,15 @@ public static string ReversePyMethodName(string pyName)
137141
}
138142

139143
/// <summary>
140-
/// Check if the method is performing aforward orreverse operation.
144+
/// Check if the method is performing a reverse operation.
141145
/// </summary>
142146
/// <param name="method">The operator method.</param>
143147
/// <returns></returns>
144-
publicstaticboolIsForward(MethodInfomethod)
148+
publicstaticboolIsReverse(MethodInfomethod)
145149
{
146150
TypedeclaringType=method.DeclaringType;
147151
TypeleftOperandType=method.GetParameters()[0].ParameterType;
148-
returnleftOperandType==declaringType;
152+
returnleftOperandType!=declaringType;
149153
}
150154

151155
publicstaticvoidFilterMethods(MethodInfo[]methods,outMethodInfo[]forwardMethods,outMethodInfo[]reverseMethods)
@@ -154,12 +158,12 @@ public static void FilterMethods(MethodInfo[] methods, out MethodInfo[] forwardM
154158
List<MethodInfo>reverseMethodsList=newList<MethodInfo>();
155159
foreach(varmethodinmethods)
156160
{
157-
if(IsForward(method))
161+
if(IsReverse(method))
158162
{
159-
forwardMethodsList.Add(method);
163+
reverseMethodsList.Add(method);
160164
}else
161165
{
162-
reverseMethodsList.Add(method);
166+
forwardMethodsList.Add(method);
163167
}
164168

165169
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp