def generate_function_declaration(fn: FuncIR, emitter: Emitter) -> None: emitter.context.declarations[emitter.native_function_name(fn.decl)] = HeaderDeclaration( '{};'.format(native_function_header(fn.decl, emitter)), needs_export=True) if fn.name != TOP_LEVEL_NAME: emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = HeaderDeclaration( '{};'.format(wrapper_function_header(fn, emitter.names)))
def native_function_header(fn: FuncDecl, emitter: Emitter) -> str: args = [] for arg in fn.sig.args: args.append('{}{}{}'.format(emitter.ctype_spaced(arg.type), REG_PREFIX, arg.name)) return '{ret_type}{name}({args})'.format( ret_type=emitter.ctype_spaced(fn.sig.ret_type), name=emitter.native_function_name(fn), args=', '.join(args) or 'void')
def generate_top_level_call(self, module: ModuleIR, emitter: Emitter) -> None: """Generate call to function representing module top level.""" # Optimization: we tend to put the top level last, so reverse iterate for fn in reversed(module.functions): if fn.name == TOP_LEVEL_NAME: emitter.emit_lines( 'char result = {}();'.format(emitter.native_function_name(fn.decl)), 'if (result == 2)', ' return NULL;', ) break
def generate_function_declaration(fn: FuncIR, emitter: Emitter) -> None: emitter.context.declarations[emitter.native_function_name(fn.decl)] = HeaderDeclaration( '{};'.format(native_function_header(fn.decl, emitter)), needs_export=True) if fn.name != TOP_LEVEL_NAME: if is_fastcall_supported(fn, emitter.capi_version): emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = HeaderDeclaration( '{};'.format(wrapper_function_header(fn, emitter.names))) else: emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = HeaderDeclaration( '{};'.format(legacy_wrapper_function_header(fn, emitter.names)))
def generate_class_type_decl(cl: ClassIR, c_emitter: Emitter, external_emitter: Emitter, emitter: Emitter) -> None: context = c_emitter.context name = emitter.type_struct_name(cl) context.declarations[name] = HeaderDeclaration( 'PyTypeObject *{};'.format(emitter.type_struct_name(cl)), needs_export=True) # If this is a non-extension class, all we want is the type object decl. if not cl.is_ext_class: return generate_object_struct(cl, external_emitter) generate_full = not cl.is_trait and not cl.builtin_base if generate_full: context.declarations[emitter.native_function_name(cl.ctor)] = HeaderDeclaration( '{};'.format(native_function_header(cl.ctor, emitter)), needs_export=True, )