lumbda/c/TODO-named-let-bytecode.md
russell@unturf.com f7352b51b0 rename: uncommonlisp -> lumbda throughout the repo
Historical internal name "uncommonlisp" retired in favor of the
public name "lumbda" ahead of lumbda.com going live. Scope of
this commit:

Source files renamed:
  uncommonlisp.py                     -> lumbda.py
  asm/uncommonlisp.s                  -> asm/lumbda.s
  c/uncommonlisp.h                    -> c/lumbda.h
  whitepaper/uncommonlisp-whitepaper  -> whitepaper/lumbda-whitepaper (.rst + .pdf)

Binaries renamed (tracked ones; c/ was always gitignored):
  asm/uncommonlisp, asm/uncommonlisp-gc, asm/uncommonlisp.o,
  asm/uncommonlisp-gc.o                -> asm/lumbda(-gc)(.o)
  c/.gitignore                          -> ignores lumbda

Internal string updates (sed pass ordered longest-first):
  asm/uncommonlisp -> asm/lumbda
  c/uncommonlisp   -> c/lumbda
  uncommonlisp.py  -> lumbda.py
  UNCOMMONLISP_BIN -> LUMBDA_BIN (asm/test.sh env var)
  "uncommonlisp> " -> "lumbda> " (asm REPL prompt baked into binary)
  UNCOMMONLISP     -> LUMBDA (macros, comments)
  uncommonlisp     -> lumbda (prose)

Binary portal magic updated:
  "ULPORTAL" -> "LUMBDAB1"   # "Lumbda Binary v1"
Old portal files are not backward-compatible — this is a deliberate
break since it's the rename moment. S-expression portals already
carry their own ";; lumbda-portal v1" header and remain cleanly
versioned.

WHITEPAPER.pdf / WHITEPAPER.rst symlinks repointed to the renamed
files. Makefile's whitepaper target targets lumbda-whitepaper.pdf.

Not changed (intentional, separate phases):
  - Filesystem directory /home/fox/git/uncommonlisp itself
    (fox renames locally and the gitlab repo URL in a follow-up)
  - tests.py hardcoded cwd=/home/fox/git/uncommonlisp
    (matches the current on-disk location; will flip when the
    directory rename ships)
  - Git history (immutable; old commits still say uncommonlisp,
    which is correct — that's what they were)

Verified:
  137 asm no-GC + 137 asm GC + 571 Python + 83 C + 189 shared
  functional tests all pass under the new names.
  bench-gc-http (2000 req): all 4 cells behave as expected
  (cells 1/2 flat, 3 leaks, 4 bounded at 1 chunk).
  Python REPL, C REPL, asm REPL all start cleanly.
2026-04-19 10:20:11 -04:00

1.7 KiB

C --fast bytecode compiler: named-let + inner let+if bug

Reproduction (minimal)

(define (maybe x) (if (> x 3) #f (+ x 1)))
(define (g start)
  (let loop ((t start))
    (let ((next (maybe t)))
      (if next (loop next) t))))
(display (g 0)) (newline)

Expected output: 4

Actual with c/lumbda --fast: hangs or segfaults. Tree-walker (c/lumbda default) works correctly. Python --fast and asm tree-walker both work correctly.

What's special

The bug fires when:

  • Outer named-let: (let loop ((t ...)) BODY)
  • Inside BODY: (let ((next (fn t))) ...) — another let
  • Inside inner let: (if next (loop next) t) — recursive call through an if branch that was reached via an inner let-body

The recursive tail call to loop through the nested let + if doesn't reach the loop closure. Bytecode emission likely walks the wrong env chain or targets the wrong stack slot.

Workaround

Replace named-let with an internal recursive define:

(define (g start)
  (define (iter t)
    (let ((next (maybe t)))
      (if next (iter next) t)))
  (iter start))

Compiles correctly under --fast. Applied to proof/eml_proof_in_lumbda.lsp for the normalize function.

Where to look

c/vm.c:344 SYM_LET named-let branch emits: PUSH_ENV, MAKE_CLOSURE, DUP, BIND name, <args...>, CALL/TAIL_CALL.

Suspected: the lambda body's closure-env capture plus the inner let PUSH_ENV interact badly when the tail call is behind an if whose compilation path doesn't POP_ENV back to the closure's expected level.

Priority

Low for now — workaround lands in every affected .lsp and the other three tiers are unaffected. File for cleanup when the C --fast refactor happens.