|
3 | 3 | from mypyc.ir.ops import ERR_NEVER, ERR_FALSE, ERR_ALWAYS |
4 | 4 | from mypyc.ir.rtypes import bool_rprimitive, object_rprimitive, void_rtype, exc_rtuple |
5 | 5 | from mypyc.primitives.registry import ( |
6 | | - simple_emit, call_emit, call_void_emit, call_and_fail_emit, custom_op, c_custom_op |
| 6 | + simple_emit, custom_op, c_custom_op |
7 | 7 | ) |
8 | 8 |
|
9 | 9 | # If the argument is a class, raise an instance of the class. Otherwise, assume |
|
15 | 15 | error_kind=ERR_ALWAYS) |
16 | 16 |
|
17 | 17 | # Raise StopIteration exception with the specified value (which can be NULL). |
18 | | -set_stop_iteration_value = custom_op( |
| 18 | +set_stop_iteration_value = c_custom_op( |
19 | 19 | arg_types=[object_rprimitive], |
20 | | - result_type=bool_rprimitive, |
21 | | - error_kind=ERR_FALSE, |
22 | | - format_str='set_stop_iteration_value({args[0]}); {dest} = 0', |
23 | | - emit=call_and_fail_emit('CPyGen_SetStopIterationValue')) |
| 20 | + return_type=void_rtype, |
| 21 | + c_function_name='CPyGen_SetStopIterationValue', |
| 22 | + error_kind=ERR_ALWAYS) |
24 | 23 |
|
25 | 24 | # Raise exception with traceback. |
26 | 25 | # Arguments are (exception type, exception value, traceback). |
27 | | -raise_exception_with_tb_op = custom_op( |
| 26 | +raise_exception_with_tb_op = c_custom_op( |
28 | 27 | arg_types=[object_rprimitive, object_rprimitive, object_rprimitive], |
29 | | - result_type=bool_rprimitive, |
30 | | - error_kind=ERR_FALSE, |
31 | | - format_str='raise_exception_with_tb({args[0]}, {args[1]}, {args[2]}); {dest} = 0', |
32 | | - emit=call_and_fail_emit('CPyErr_SetObjectAndTraceback')) |
| 28 | + return_type=void_rtype, |
| 29 | + c_function_name='CPyErr_SetObjectAndTraceback', |
| 30 | + error_kind=ERR_ALWAYS) |
33 | 31 |
|
34 | 32 | # Reraise the currently raised exception. |
35 | | -reraise_exception_op = custom_op( |
| 33 | +reraise_exception_op = c_custom_op( |
36 | 34 | arg_types=[], |
37 | | - result_type=bool_rprimitive, |
38 | | - error_kind=ERR_FALSE, |
39 | | - format_str='reraise_exc; {dest} = 0', |
40 | | - emit=call_and_fail_emit('CPy_Reraise')) |
| 35 | + return_type=void_rtype, |
| 36 | + c_function_name='CPy_Reraise', |
| 37 | + error_kind=ERR_ALWAYS) |
41 | 38 |
|
42 | 39 | # Propagate exception if the CPython error indicator is set (an exception was raised). |
43 | | -no_err_occurred_op = custom_op( |
| 40 | +no_err_occurred_op = c_custom_op( |
44 | 41 | arg_types=[], |
45 | | - result_type=bool_rprimitive, |
46 | | - error_kind=ERR_FALSE, |
47 | | - format_str='{dest} = no_err_occurred', |
48 | | - emit=call_emit('CPy_NoErrOccured')) |
| 42 | + return_type=bool_rprimitive, |
| 43 | + c_function_name='CPy_NoErrOccured', |
| 44 | + error_kind=ERR_FALSE) |
49 | 45 |
|
50 | 46 | # Assert that the error indicator has been set. |
51 | 47 | assert_err_occured_op = custom_op( |
|
68 | 64 | # handled exception" (by sticking it into sys.exc_info()). Returns the |
69 | 65 | # exception that was previously being handled, which must be restored |
70 | 66 | # later. |
71 | | -error_catch_op = custom_op( |
| 67 | +error_catch_op = c_custom_op( |
72 | 68 | arg_types=[], |
73 | | - result_type=exc_rtuple, |
74 | | - error_kind=ERR_NEVER, |
75 | | - format_str='{dest} = error_catch', |
76 | | - emit=call_emit('CPy_CatchError')) |
| 69 | + return_type=exc_rtuple, |
| 70 | + c_function_name='CPy_CatchError', |
| 71 | + error_kind=ERR_NEVER) |
77 | 72 |
|
78 | 73 | # Restore an old "currently handled exception" returned from. |
79 | 74 | # error_catch (by sticking it into sys.exc_info()) |
80 | | -restore_exc_info_op = custom_op( |
| 75 | +restore_exc_info_op = c_custom_op( |
81 | 76 | arg_types=[exc_rtuple], |
82 | | - result_type=void_rtype, |
83 | | - error_kind=ERR_NEVER, |
84 | | - format_str='restore_exc_info {args[0]}', |
85 | | - emit=call_void_emit('CPy_RestoreExcInfo')) |
| 77 | + return_type=void_rtype, |
| 78 | + c_function_name='CPy_RestoreExcInfo', |
| 79 | + error_kind=ERR_NEVER) |
86 | 80 |
|
87 | 81 | # Checks whether the exception currently being handled matches a particular type. |
88 | | -exc_matches_op = custom_op( |
| 82 | +exc_matches_op = c_custom_op( |
89 | 83 | arg_types=[object_rprimitive], |
90 | | - result_type=bool_rprimitive, |
91 | | - error_kind=ERR_NEVER, |
92 | | - format_str='{dest} = exc_matches {args[0]}', |
93 | | - emit=call_emit('CPy_ExceptionMatches')) |
| 84 | + return_type=bool_rprimitive, |
| 85 | + c_function_name='CPy_ExceptionMatches', |
| 86 | + error_kind=ERR_NEVER) |
94 | 87 |
|
95 | 88 | # Get the value of the exception currently being handled. |
96 | | -get_exc_value_op = custom_op( |
| 89 | +get_exc_value_op = c_custom_op( |
97 | 90 | arg_types=[], |
98 | | - result_type=object_rprimitive, |
99 | | - error_kind=ERR_NEVER, |
100 | | - format_str='{dest} = get_exc_value', |
101 | | - emit=call_emit('CPy_GetExcValue')) |
| 91 | + return_type=object_rprimitive, |
| 92 | + c_function_name='CPy_GetExcValue', |
| 93 | + error_kind=ERR_NEVER) |
102 | 94 |
|
103 | 95 | # Get exception info (exception type, exception instance, traceback object). |
104 | | -get_exc_info_op = custom_op( |
| 96 | +get_exc_info_op = c_custom_op( |
105 | 97 | arg_types=[], |
106 | | - result_type=exc_rtuple, |
107 | | - error_kind=ERR_NEVER, |
108 | | - format_str='{dest} = get_exc_info', |
109 | | - emit=call_emit('CPy_GetExcInfo')) |
| 98 | + return_type=exc_rtuple, |
| 99 | + c_function_name='CPy_GetExcInfo', |
| 100 | + error_kind=ERR_NEVER) |
0 commit comments