@@ -1272,6 +1272,47 @@ void operatorInfo_init(OperatorInfo* info,
12721272}
12731273
12741274static void _OPT_ADD (OperatorInfo * op ) {
1275+ if (argType_isObject (op -> t1 )) {
1276+ if (!argType_isObject (op -> t2 )) {
1277+ VMState_setErrorCode (op -> vm , PIKA_RES_ERR_OPERATION_FAILED );
1278+ __platform_printf ("TypeError: unsupported operand +\n" );
1279+ op -> res = NULL ;
1280+ return ;
1281+ }
1282+ PikaObj * obj1 = arg_getPtr (op -> a1 );
1283+ Arg * method_add = obj_getMethodArg (obj1 , "__add__" );
1284+ if (NULL == method_add ) {
1285+ VMState_setErrorCode (op -> vm , PIKA_RES_ERR_OPERATION_FAILED );
1286+ __platform_printf ("TypeError: unsupported operand +\n" );
1287+ op -> res = NULL ;
1288+ return ;
1289+ }
1290+ arg_deinit (method_add );
1291+ PikaObj * obj2 = arg_getPtr (op -> a2 );
1292+ obj_setPtr (obj1 , "__others" , obj2 );
1293+ /* clang-format off */
1294+ PIKA_PYTHON (
1295+ __res = __add__ (__others )
1296+ )
1297+ /* clang-format on */
1298+ const uint8_t bytes [] = {
1299+ 0x0c , 0x00 , /* instruct array size */
1300+ 0x10 , 0x81 , 0x01 , 0x00 , 0x00 , 0x02 , 0x0a , 0x00 , 0x00 , 0x04 , 0x12 ,
1301+ 0x00 ,
1302+ /* instruct array */
1303+ 0x18 , 0x00 , /* const pool size */
1304+ 0x00 , 0x5f , 0x5f , 0x6f , 0x74 , 0x68 , 0x65 , 0x72 , 0x73 , 0x00 , 0x5f ,
1305+ 0x5f , 0x61 , 0x64 , 0x64 , 0x5f , 0x5f , 0x00 , 0x5f , 0x5f , 0x72 , 0x65 ,
1306+ 0x73 , 0x00 , /* const pool */
1307+ };
1308+ pikaVM_runByteCode (obj1 , (uint8_t * )bytes );
1309+ Arg * __res = arg_copy (obj_getArg (obj1 , "__res" ));
1310+ op -> res = __res ;
1311+ obj_removeArg (obj1 , "__others" );
1312+ obj_removeArg (obj1 , "__res" );
1313+ return ;
1314+ }
1315+
12751316 if ((op -> t1 == ARG_TYPE_STRING ) && (op -> t2 == ARG_TYPE_STRING )) {
12761317 char * num1_s = NULL ;
12771318 char * num2_s = NULL ;
@@ -1294,6 +1335,46 @@ static void _OPT_ADD(OperatorInfo* op) {
12941335}
12951336
12961337static void _OPT_SUB (OperatorInfo * op ) {
1338+ if (argType_isObject (op -> t1 )) {
1339+ if (!argType_isObject (op -> t2 )) {
1340+ VMState_setErrorCode (op -> vm , PIKA_RES_ERR_OPERATION_FAILED );
1341+ __platform_printf ("TypeError: unsupported operand +\n" );
1342+ op -> res = NULL ;
1343+ return ;
1344+ }
1345+ PikaObj * obj1 = arg_getPtr (op -> a1 );
1346+ Arg * method_sub = obj_getMethodArg (obj1 , "__sub__" );
1347+ if (NULL == method_sub ) {
1348+ VMState_setErrorCode (op -> vm , PIKA_RES_ERR_OPERATION_FAILED );
1349+ __platform_printf ("TypeError: unsupported operand +\n" );
1350+ op -> res = NULL ;
1351+ return ;
1352+ }
1353+ arg_deinit (method_sub );
1354+ PikaObj * obj2 = arg_getPtr (op -> a2 );
1355+ obj_setPtr (obj1 , "__others" , obj2 );
1356+ /* clang-format off */
1357+ PIKA_PYTHON (
1358+ __res = __sub__ (__others )
1359+ )
1360+ /* clang-format on */
1361+ const uint8_t bytes [] = {
1362+ 0x0c , 0x00 , /* instruct array size */
1363+ 0x10 , 0x81 , 0x01 , 0x00 , 0x00 , 0x02 , 0x0a , 0x00 , 0x00 , 0x04 , 0x12 ,
1364+ 0x00 ,
1365+ /* instruct array */
1366+ 0x18 , 0x00 , /* const pool size */
1367+ 0x00 , 0x5f , 0x5f , 0x6f , 0x74 , 0x68 , 0x65 , 0x72 , 0x73 , 0x00 , 0x5f ,
1368+ 0x5f , 0x73 , 0x75 , 0x62 , 0x5f , 0x5f , 0x00 , 0x5f , 0x5f , 0x72 , 0x65 ,
1369+ 0x73 , 0x00 , /* const pool */
1370+ };
1371+ pikaVM_runByteCode (obj1 , (uint8_t * )bytes );
1372+ Arg * __res = arg_copy (obj_getArg (obj1 , "__res" ));
1373+ op -> res = __res ;
1374+ obj_removeArg (obj1 , "__others" );
1375+ obj_removeArg (obj1 , "__res" );
1376+ return ;
1377+ }
12971378 if (op -> t2 == ARG_TYPE_NONE ) {
12981379 if (op -> t1 == ARG_TYPE_INT ) {
12991380 op -> res = arg_setInt (op -> res , "" , - op -> i1 );
0 commit comments