/* shim.c — expose Lean's static inline runtime helpers as real extern * symbols for the render crate's future Rust FFI to link against. * * Mirror of `native/cubical/shim.c`, kept separate so the render crate * can link its own shim without dragging the cubical crate's object * files into its build. * * Lean 4's `lean_obj_tag` / `lean_ctor_get` / `lean_ctor_set` / * `lean_alloc_ctor` / `lean_inc` / `lean_dec` / `lean_string_cstr` / * `lean_mk_string` are all `static inline` in ``. A Rust * staticlib that calls them via `extern "C"` produces unresolved * references at link time. The wrappers below have real ELF symbols * with the `topolei_render_shim_*` prefix. Zero overhead — the * compiler should inline the calls. * * Compiled by `build.rs` via the `cc` crate. Native targets only; * wasm builds don't link against Lean's runtime. */ #include #include uint32_t topolei_render_shim_obj_tag(b_lean_obj_arg o) { return lean_obj_tag(o); } lean_obj_res topolei_render_shim_ctor_get(b_lean_obj_arg o, unsigned i) { return lean_ctor_get(o, i); } void topolei_render_shim_ctor_set(lean_object* o, unsigned i, lean_obj_arg v) { lean_ctor_set(o, i, v); } lean_obj_res topolei_render_shim_alloc_ctor(unsigned tag, unsigned num_objs, unsigned scalar_sz) { return lean_alloc_ctor(tag, num_objs, scalar_sz); } void topolei_render_shim_inc(b_lean_obj_arg o) { lean_inc(o); } void topolei_render_shim_dec(b_lean_obj_arg o) { lean_dec(o); } const char* topolei_render_shim_string_cstr(b_lean_obj_arg s) { return lean_string_cstr(s); } lean_obj_res topolei_render_shim_mk_string(const char* s) { return lean_mk_string(s); } /* ByteArray (lean_sarray) helpers — used by future bytes-based FFI. * These aren't in the cubical shim because cubical operates on ctor * objects, not byte buffers; for render we'll pass serialised * primitive lists + shader bytes through ByteArrays. */ size_t topolei_render_shim_sarray_size(b_lean_obj_arg a) { return lean_sarray_size(a); } const uint8_t* topolei_render_shim_sarray_cptr(b_lean_obj_arg a) { return lean_sarray_cptr(a); } lean_obj_res topolei_render_shim_alloc_sarray1(size_t size, size_t capacity) { /* Element size 1 (bytes); result has size==capacity elements ready * to be filled by the caller. */ return lean_alloc_sarray(1, size, capacity); }