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

Commit3c4ea26

Browse files
committed
Add eq and ineq operators, disallow reverse for comp
1 parent26a6dcb commit3c4ea26

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

‎src/embed_tests/TestOperator.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ public OperableObject(int num)
149149
returnnewOperableObject(a.Num^b);
150150
}
151151

152+
publicstaticbooloperator==(inta,OperableObjectb)
153+
{
154+
return(a==b.Num);
155+
}
156+
publicstaticbooloperator==(OperableObjecta,OperableObjectb)
157+
{
158+
return(a.Num==b.Num);
159+
}
160+
publicstaticbooloperator==(OperableObjecta,intb)
161+
{
162+
return(a.Num==b);
163+
}
164+
165+
publicstaticbooloperator!=(inta,OperableObjectb)
166+
{
167+
return(a!=b.Num);
168+
}
169+
publicstaticbooloperator!=(OperableObjecta,OperableObjectb)
170+
{
171+
return(a.Num!=b.Num);
172+
}
173+
publicstaticbooloperator!=(OperableObjecta,intb)
174+
{
175+
return(a.Num!=b);
176+
}
177+
152178
publicstaticbooloperator<=(inta,OperableObjectb)
153179
{
154180
return(a<=b.Num);

‎src/runtime/methodbinder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,17 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
354354
intkwargsMatched;
355355
intdefaultsNeeded;
356356
boolisOperator=OperatorMethod.IsOperatorMethod(mi);
357-
intclrnargs=pi.Length;
358357
// Binary operator methods will have 2 CLR args but only one Python arg
359358
// (unary operators will have 1 less each), since Python operator methods are bound.
360-
isOperator=isOperator&&pynargs==clrnargs-1;
359+
isOperator=isOperator&&pynargs==pi.Length-1;
360+
boolisReverse=isOperator&&OperatorMethod.IsReverse((MethodInfo)mi);// Only cast if isOperator.
361+
if(isReverse&&OperatorMethod.IsComparisonOp((MethodInfo)mi))
362+
continue;// Comparison operators in Python have no reverse mode.
361363
if(!MatchesArgumentCount(pynargs,pi,kwargDict,outparamsArray,outdefaultArgList,outkwargsMatched,outdefaultsNeeded)&&!isOperator)
362364
{
363365
continue;
364366
}
365367
// Preprocessing pi to remove either the first or second argument.
366-
boolisReverse=isOperator&&OperatorMethod.IsReverse((MethodInfo)mi);// Only cast if isOperator.
367368
if(isOperator&&!isReverse){
368369
// The first Python arg is the right operand, while the bound instance is the left.
369370
// We need to skip the first (left operand) CLR argument.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp