nimony-py — idiomatic Python backend

An idiomatic Python backend for nimony: Nim types become real Python objects, not byte offsets.

Status: early scaffold · private repo. The architecture is being designed; no working codegen has landed yet. Access via Discord timbuktu_guy.

What it is (and isn’t)

There are two ways to target Python from Nim:

  1. Linear-memory Python — a bytearray + struct/memoryview as one flat heap, pointers as offsets. Reuses nimony-web’s jslayout engine verbatim, but is slow and unreadable. If ever wanted, it belongs in nimony-web as a third linear target — not here.
  2. Idiomatic Python — real class/@dataclass, list, dict, Python’s own GC. Readable, fast enough, Pythonic. This repo is #2.

Python is in some ways an easier idiomatic target than TypeScript:

  idiomatic value
integers native arbitrary-precision int — no number/bigint split, no wrap footgun
object @dataclass / class
seq[T] list
Table[K,V] / HashSet dict / set
string str
memory Python’s refcount + cycle GC

Planned architecture

Shared with its sibling nimony-ts: a common Nim→high-level lowering (nimony-hl) feeds thin per-language emitters. Both consume nimony’s sem’d, pre-hexer NIF (.s.nif) — echo stays a named write call with the literal intact, object types nominal, seq[T] generic, try/raise structured — none of the C-model lowering the post-hexer .c.nif carries. It loads with existing nimony APIs (programs.loadModuleContent / setupProgram), so no compiler changes are needed.


Back to top

aoughwl — next-gen self-hosted platform for things n stuff. Reach out on Discord (timbuktu_guy) for access to the private backends.

This site uses Just the Docs, a documentation theme for Jekyll.