Goal
Add a Nim binding generator backend for alef, alongside the existing 16 backends.
Approach
Nim is a C FFI consumer with a clean syntax for declaring foreign procedures. Two viable approaches:
- Direct dynlib (recommended): emit
.nim source using {.dynlib: \"libname.so\".} pragmas to declare external procs. No additional Rust-side bridge crate needed.
cnim adapter: an alternative for projects that prefer compile-time C interop, but requires more glue.
This backend should follow the C FFI consumer pattern (Go/Java/C#/Zig), not the native-Rust-crate pattern.
Reference implementation
crates/alef-backend-zig/src/gen_bindings.rs — closest template (also a C FFI consumer with idiomatic syntax adaptation).
- Reuse
alef-codegen::c_consumer::{free_string_symbol, last_error_code_symbol, last_error_context_symbol}.
- Reuse
config.ffi_header_name(), config.ffi_lib_name(), config.ffi_prefix().
Suggested scope
- Stage A: New crate
crates/alef-backend-nim/ + NimMapper: TypeMapper. Add NIM_KEYWORDS to crates/alef-core/src/keywords.rs.
- Stage B: Emit
.nim source — object for structs, enum for unit-only enums, case object for tagged unions, proc with {.dynlib, importc.} pragmas.
- Stage C: Result via Nim's exception system (
raise newException(...)) — Nim doesn't have Result natively but std/options covers Option.
- Stage 1b: scaffold (
<crate>.nimble), e2e (unittest from stdlib), publish (nimble package).
Pin versions
Nim's package manager nimble — add template_versions::nimble submodule with deps and renovate markers.
Effort estimate
S–M (~3–5 days). Simpler than OCaml because no Rust-side bridge crate is needed.
Tracking
Part of Tier 2 per the language-backend expansion plan. Other Tier 2: Lua, OCaml, Julia.
Goal
Add a Nim binding generator backend for alef, alongside the existing 16 backends.
Approach
Nim is a C FFI consumer with a clean syntax for declaring foreign procedures. Two viable approaches:
.nimsource using{.dynlib: \"libname.so\".}pragmas to declare external procs. No additional Rust-side bridge crate needed.cnimadapter: an alternative for projects that prefer compile-time C interop, but requires more glue.This backend should follow the C FFI consumer pattern (Go/Java/C#/Zig), not the native-Rust-crate pattern.
Reference implementation
crates/alef-backend-zig/src/gen_bindings.rs— closest template (also a C FFI consumer with idiomatic syntax adaptation).alef-codegen::c_consumer::{free_string_symbol, last_error_code_symbol, last_error_context_symbol}.config.ffi_header_name(),config.ffi_lib_name(),config.ffi_prefix().Suggested scope
crates/alef-backend-nim/+NimMapper: TypeMapper. AddNIM_KEYWORDStocrates/alef-core/src/keywords.rs..nimsource —objectfor structs,enumfor unit-only enums,case objectfor tagged unions,procwith{.dynlib, importc.}pragmas.raise newException(...)) — Nim doesn't haveResultnatively butstd/optionscoversOption.<crate>.nimble), e2e (unittestfrom stdlib), publish (nimblepackage).Pin versions
Nim's package manager
nimble— addtemplate_versions::nimblesubmodule with deps and renovate markers.Effort estimate
S–M (~3–5 days). Simpler than OCaml because no Rust-side bridge crate is needed.
Tracking
Part of Tier 2 per the language-backend expansion plan. Other Tier 2: Lua, OCaml, Julia.