lumbda/c
russell@unturf.com 7b6643d1fc
c: byte semantics — string-ref unsigned cast, pack_u64_slot bignum sentinel
Two C-tier defects surfaced when running foxhop's ecdsa Phase B emit
through the lumbda C interpreter. Both produced wrong bytes in the
generated QECCOPS1 binary; both Python tier handled correctly.

1. string-ref on a byte >= 0x80 returned a char with codepoint -1.

   The store was a `char` array (signed on x86_64); `s->data[idx]`
   sign-extends 0xFF into a negative int before VAL_CHAR wraps it.
   Round-tripping (char->integer (string-ref s 0)) for a 0xFF byte
   gave -1 instead of 255. The Scheme-level (u64-le n) packer uses
   (make-string 1 (integer->char (modulo v 256))) for each byte and
   reads them back; sign-extension corrupted the high-bit bytes.

   Cast through `unsigned char` in bi_string_ref.

2. pack_u64_slot treated bignum slots as raw fixnums.

   ecdsa's emit-stream binds (no-slot *no-slot*) where *no-slot* is
   18446744073709551615 (u64 max). On Python tier that's a regular
   big-int. C tier carries it as a bignum NaN-box slot. The packer
   knew about VAL_FALSE → 0xFFFF... but called as_int(v) on bignums,
   reading the NaN-box payload bits (pointer-to-Bignum) and writing
   that pointer as the field's 64-bit LE value.

   Add an IS_BIGNUM branch that extracts the low 64 magnitude bits
   directly. Cross-tier emit-stream code stays unchanged.

Tests: 88/88 c-test, 4/4 regression-named-let-leak, 205/205
functional. DIALOG_GCD smoke at p=11 n+1=5 now byte-identical to
Python tier (1,941,816 bytes match exactly).
2026-06-07 20:19:09 -04:00
..
.gitignore rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
bench.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
bignum.c c-tier bignum — arbitrary-precision integers unblock secp256k1 widths 2026-06-06 20:23:37 -04:00
builtins.c c: byte semantics — string-ref unsigned cast, pack_u64_slot bignum sentinel 2026-06-07 20:19:09 -04:00
eval.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
gc.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
jit.c rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
jit.h rename: uncommonlisp -> lumbda throughout the repo 2026-04-19 10:20:11 -04:00
lumbda.h c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
main.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
Makefile c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
portal.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
printer.c c-tier bignum — arbitrary-precision integers unblock secp256k1 widths 2026-06-06 20:23:37 -04:00
reader.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
test.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
types.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00
vm.c c: precise GC tracing for NaN-boxed Values 2026-06-07 17:18:45 -04:00