def _finish_off(block, prim=None): """ Convert block to an AST and add it to the ast_list. Raise a PyExportError on failure. """ if prim is None: prim = _get_prim(block) if convert_me: if prim.export_me: try: new_ast = prim.get_ast(*arg_asts) except ValueError: traceback.print_exc() raise PyExportError(_("error while exporting block"), block=block) if isinstance(new_ast, (list, tuple)): ast_list.extend(new_ast) elif new_ast is not None: ast_list.append(new_ast) elif arg_asts: # TODO do we ever get here? new_ast = ast.List(elts=arg_asts, ctx=ast.Load) ast_list.append(new_ast) else: ast_list.append((prim, ) + tuple(arg_asts))
def _get_prim(block): prim = lc.get_prim_callable(block.primitive) # fail gracefully if primitive is not a Primitive object if not isinstance(prim, Primitive): raise PyExportError(_("block is not exportable"), block=block) return prim