Skip to content

feat: Add Nim backend (community contribution welcome) #12

Description

@Goldziher

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

  1. Stage A: New crate crates/alef-backend-nim/ + NimMapper: TypeMapper. Add NIM_KEYWORDS to crates/alef-core/src/keywords.rs.
  2. Stage B: Emit .nim source — object for structs, enum for unit-only enums, case object for tagged unions, proc with {.dynlib, importc.} pragmas.
  3. Stage C: Result via Nim's exception system (raise newException(...)) — Nim doesn't have Result natively but std/options covers Option.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions