Phase 07: Mochi extern emitter
Status: Planned
Deliverables
package3/kotlin/extern/emit.go—Emit(surface *APIObject, wrapperDir string, outputPath string) error— writeshim.mochifrom the type-mappedAPIObjectand thelibwrap.hentry points.package3/kotlin/extern/names.go— naming rules: KotlinFooBar.bazQux→ Mochifoo_bar_baz_qux, collision avoidance (suffix_2if a name is taken).package3/kotlin/extern/format.go—shim.mochiformatting: oneextern typeper Kotlin class, oneextern fnper function, sorted by class then by function name.package3/kotlin/extern/custom.go— preservecustomoverrides: if an existingshim.mochihasextern fn ... custom, do not overwrite those lines onmochi pkg sync kotlin.
shim.mochi format
// Code generated by mochi pkg lock. DO NOT EDIT.
// Artifact: com.squareup.okhttp3:[email protected]
// Wrapper: kotlin_wrap/okhttp/libwrap.so (sha256: a7c3d5...)
// Metadata: schema-version 9
extern type OkHttpClient
extern type Request
extern type RequestBuilder
extern type Response
extern type ResponseBody
extern type Call
extern fn okhttp_client_new(): OkHttpClient from kotlin "com.squareup.okhttp3.OkHttpClient.<init>"
extern fn okhttp_request_builder_new(): RequestBuilder from kotlin "com.squareup.okhttp3.Request.Builder.<init>"
extern fn okhttp_request_builder_url(b: RequestBuilder, url: string): RequestBuilder from kotlin "com.squareup.okhttp3.Request.Builder.url"
extern fn okhttp_request_builder_build(b: RequestBuilder): Request from kotlin "com.squareup.okhttp3.Request.Builder.build"
extern fn okhttp_client_new_call(c: OkHttpClient, req: Request): Call from kotlin "com.squareup.okhttp3.OkHttpClient.newCall"
extern fn okhttp_call_execute(call: Call): Response from kotlin "com.squareup.okhttp3.Call.execute"
extern fn okhttp_response_body(resp: Response): ResponseBody from kotlin "com.squareup.okhttp3.Response.body"
extern fn okhttp_response_body_string(body: ResponseBody): string from kotlin "com.squareup.okhttp3.ResponseBody.string"
The from kotlin "..." annotation is used by the Mochi linker to resolve the extern fn to the compiled libwrap.so entry point.
Gate
Emit shim.mochi for [email protected] and verify:
- The Mochi parser accepts all emitted
shim.mochifiles without parse errors. - Every
extern fnin the shim has a corresponding symbol inlibwrap.h. - Every
extern fnname is unique within the shim (no collisions). mochi pkg sync kotlinon an existing shim with oneextern fn ... customline preserves that line unchanged.- The generated comment header contains the correct artifact coordinates, SHA-256, and metadata schema version.