Generates the 'throw' method for a generator class.
(builder: IRBuilder, fn_info: FuncInfo, fn_decl: FuncDecl)
| 300 | |
| 301 | |
| 302 | def add_throw_to_generator_class(builder: IRBuilder, fn_info: FuncInfo, fn_decl: FuncDecl) -> None: |
| 303 | """Generates the 'throw' method for a generator class.""" |
| 304 | with builder.enter_method(fn_info.generator_class.ir, "throw", object_rprimitive, fn_info): |
| 305 | typ = builder.add_argument("type", object_rprimitive) |
| 306 | val = builder.add_argument("value", object_rprimitive, ARG_OPT) |
| 307 | tb = builder.add_argument("traceback", object_rprimitive, ARG_OPT) |
| 308 | |
| 309 | # Because the value and traceback arguments are optional and hence |
| 310 | # can be NULL if not passed in, we have to assign them Py_None if |
| 311 | # they are not passed in. |
| 312 | none_reg = builder.none_object() |
| 313 | builder.assign_if_null(val, lambda: none_reg, fn_info.fitem.line) |
| 314 | builder.assign_if_null(tb, lambda: none_reg, fn_info.fitem.line) |
| 315 | |
| 316 | # Call the helper function using the arguments passed in, and return that result. |
| 317 | result = builder.add( |
| 318 | Call( |
| 319 | fn_decl, |
| 320 | [ |
| 321 | builder.self(), |
| 322 | builder.read(typ), |
| 323 | builder.read(val), |
| 324 | builder.read(tb), |
| 325 | none_reg, |
| 326 | Integer(0, object_pointer_rprimitive), |
| 327 | ], |
| 328 | fn_info.fitem.line, |
| 329 | ) |
| 330 | ) |
| 331 | builder.add(Return(result)) |
| 332 | |
| 333 | |
| 334 | def add_close_to_generator_class(builder: IRBuilder, fn_info: FuncInfo) -> None: |
no test coverage detected
searching dependent graphs…