Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5130aaa
Overload operators except for bit shifts and default args.
christabella Dec 16, 2020
0d0ca87
Remove params array tests since they are unrelated to operator overlo…
christabella Dec 17, 2020
253f9c7
Fix type bug; rename variables pynargs etc.
christabella Dec 17, 2020
8cdb61c
Remove unused variables and add comments.
christabella Dec 17, 2020
c26e589
Add comments and remove unused in operatormethod.cs
christabella Dec 18, 2020
3222a54
Address review by @lostmsu; Add forward operator test.
christabella Dec 20, 2020
550ff31
Add forward operator tests (OpObj, int).
christabella Dec 21, 2020
eab8edc
Address @amos402's comment on raising branch.
christabella Dec 21, 2020
c2be3f1
Add operator overload and rename pynargs, clrnargs
christabella Dec 21, 2020
581a047
Revert variable renames
christabella Dec 22, 2020
e11327f
Update AUTHORS and CHANGELOG
christabella Dec 22, 2020
35be4bc
Revert rename to pynargs
christabella Dec 23, 2020
f19c281
Address @tminka's comments.
christabella Dec 23, 2020
d7f52d2
Remove whitespace
christabella Dec 23, 2020
5855a1b
Fix nits
christabella Dec 24, 2020
e7da0bc
Support reverse binary operations
christabella Dec 28, 2020
a376838
Use reverse instead of forward (semantics)
christabella Dec 29, 2020
6923a78
Address @tminka's comments
christabella Dec 30, 2020
4c992d8
Support unary neg and pos operators
christabella Dec 30, 2020
8cce61d
Remove isOperator from MatchesArgumentCount (simplify), add test.
christabella Jan 4, 2021
09a2047
Revert "Remove isOperator from MatchesArgumentCount (simplify)"
christabella Jan 4, 2021
41bd07f
Properly remove isOperator from MatchesArgumentCount (@tminka comment)
christabella Jan 4, 2021
10ccf1e
Update changelog.
christabella Jan 4, 2021
5682e0c
Add ones complement and modulo tests (@tminka comment)
christabella Jan 4, 2021
5f45c70
Merge branch 'master' into feat/operator-overloads
lostmsu Jan 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Properly remove isOperator from MatchesArgumentCount (@tminka comment)
  • Loading branch information
christabella committed Jan 4, 2021
commit 41bd07fe3ad2ae53162f81f961f1ec8b402753d1
20 changes: 6 additions & 14 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,14 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
int kwargsMatched;
int defaultsNeeded;
bool isOperator = OperatorMethod.IsOperatorMethod(mi);
if (!MatchesArgumentCount(pynargs, pi, kwargDict, isOperator, out paramsArray, out defaultArgList, out kwargsMatched, out defaultsNeeded))
int clrnargs = pi.Length;
// Binary operator methods will have 2 CLR args but only one Python arg
// (unary operators will have 1 less each), since Python operator methods are bound.
isOperator = isOperator && pynargs == clrnargs - 1;
if (!MatchesArgumentCount(pynargs, pi, kwargDict, out paramsArray, out defaultArgList, out kwargsMatched, out defaultsNeeded) && !isOperator)
{
continue;
}
var outs = 0;
int clrnargs = pi.Length;
isOperator = isOperator && pynargs == clrnargs - 1; // Handle mismatched arg numbers due to Python operator being bound.
// Preprocessing pi to remove either the first or second argument.
bool isReverse = isOperator && OperatorMethod.IsReverse((MethodInfo)mi); // Only cast if isOperator.
if (isOperator && !isReverse) {
Expand All @@ -362,6 +363,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
// We need to take the first CLR argument.
pi = pi.Take(1).ToArray();
}
var outs = 0;
var margs = TryConvertArguments(pi, paramsArray, args, pynargs, kwargDict, defaultArgList,
needsResolution: _methods.Length > 1, // If there's more than one possible match.
outs: out outs);
Expand Down Expand Up @@ -685,15 +687,13 @@ static Type TryComputeClrArgumentType(Type parameterType, IntPtr argument, bool
/// <param name="positionalArgumentCount">Number of positional args passed from Python.</param>
/// <param name="parameters">Parameters of the specified .NET method.</param>
/// <param name="kwargDict">Keyword args passed from Python.</param>
/// <param name="isOperator">True if the parameters' method is an operator.</param>
/// <param name="paramsArray">True if the final param of the .NET method is an array (`params` keyword).</param>
/// <param name="defaultArgList">List of default values for arguments.</param>
/// <param name="kwargsMatched">Number of kwargs from Python that are also present in the .NET method.</param>
/// <param name="defaultsNeeded">Number of non-null defaultsArgs.</param>
/// <returns></returns>
static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] parameters,
Dictionary<string, IntPtr> kwargDict,
bool isOperator,
out bool paramsArray,
out ArrayList defaultArgList,
out int kwargsMatched,
Expand All @@ -711,14 +711,6 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
else if (positionalArgumentCount < parameters.Length && (!paramsArray || positionalArgumentCount == parameters.Length - 1))
{
match = true;
// operator methods will have 2 CLR args but only one Python arg,
// since Python operator methods are bound
if (isOperator && positionalArgumentCount == parameters.Length - 1)
{
// return early since a C# operator method cannot have
// keyword args, default args, or params arrays (exclusive cases)
return match;
}
// every parameter past 'positionalArgumentCount' must have either
// a corresponding keyword arg or a default param, unless the method
// method accepts a params array (which cannot have a default value)
Expand Down