Created
January 2, 2020 19:31
-
-
Save arpitbbhayani/405ce0af4e6a79303dd069a0af4757a4 to your computer and use it in GitHub Desktop.
The new Binary addition implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case TARGET(BINARY_ADD): { | |
PyObject *right = POP(); | |
PyObject *left = TOP(); | |
PyObject *result; | |
if (PyUnicode_CheckExact(left) && | |
PyUnicode_CheckExact(right)) { | |
result = unicode_concatenate(tstate, left, right, f, next_instr); | |
} | |
else { | |
// Do this operation only when both the operands are numbers and | |
// the evaluation was initiated from interactive interpreter (shell) | |
if (PyNumber_Check(left) && PyNumber_Check(right)) { | |
char operator = get_random_operator(); | |
result = binary_operate(left, right, operator); | |
printf( | |
"::::: %s + %s was evaluated as %s %c %s, hence to the value\n", | |
ReprStr(left), ReprStr(right), | |
ReprStr(left), operator, ReprStr(right) | |
); | |
} else { | |
result = PyNumber_Add(left, right); | |
} | |
... | |
} | |
... | |
SET_TOP(result); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment