Skip to content

Instantly share code, notes, and snippets.

@arpitbbhayani
Created January 2, 2020 19:31
Show Gist options
  • Save arpitbbhayani/405ce0af4e6a79303dd069a0af4757a4 to your computer and use it in GitHub Desktop.
Save arpitbbhayani/405ce0af4e6a79303dd069a0af4757a4 to your computer and use it in GitHub Desktop.
The new Binary addition implementation
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