asm tier: spawn-process-stdio + flush-port
Adds the two primitives lumbda's bend pattern needs to host GPU workers
on the asm tier, byte-identical to Python & C tiers shipped earlier.
(spawn-process-stdio path '(args …))
→ (stdin-port . stdout-port) or #f
Implementation:
- pipe2 + pipe2 (in_pipe, out_pipe)
- fork via SYS_FORK = 57
- parent: close child-side ends, encode_port both fds, make_pair
- child: dup2(in_pipe[0], 0); dup2(out_pipe[1], 1); close all 4;
execve(path, argv, NULL); exit(127) on failure
Stack frame: 4 KB scratch at %rbp (saved by RET_VAL via the
caller's pushq sequence). Layout:
0..15 = in_pipe + out_pipe (4 × int32 fds)
16..143 = argv[] (16 ptrs × 8 B)
144..399 = path buf (256 B, null-term)
400..2447 = arg bufs (8 args × 256 B)
Limits: ≤ 8 args, ≤ 255 bytes per string. Symbols not yet
converted to strings (the Python & C tiers do that; asm callers
must pass actual strings).
(flush-port port)
→ void, no-op. asm tier uses raw fds with no userspace buffering
(unlike the C tier's FILE* wrappers), so there's nothing to flush.
New syscall constants:
SYS_PIPE2 = 293
SYS_FORK = 57
SYS_EXECVE= 59
SYS_DUP2 = 33
Two new BI_ codes (BI_SPAWNPROC = 121, BI_FLUSHPORT = 122) with the
GC_* renumbered to 123..127 and BI_COUNT = 128 (GC_NAIVE) / 123.
bn_spawnproc + bn_flushport added to symbol table + builtin name array.
Verified on 3090-ai:
λ> (display (spawn-process-stdio "/bin/true" (quote ())))
(#<port> . #<port>)
λ> (define p (spawn-process-stdio "/bin/echo" (quote ("hello" "from" "asm"))))
λ> (display p)
(#<port> . #<port>)
Critical debug: %r15 is lumbda asm's heap bump pointer (line 14:
"# %r15 = heap bump pointer"). Initial draft used %r15 as scratch
base — make_pair → heap_alloc segfaulted immediately. Reverted &
re-wrote with %rbp (callee-saved + RET_VAL restores it). All future
asm primitives that need a scratch register MUST avoid %r15.
Per-tier matrix now:
Python tier ✓ host + client
C tier ✓ host + client (cross-tier byte-identical to Python)
asm tier ✓ spawn-process-stdio + flush-port working;
read-line on subprocess pipe still missing
(~20 LoC asm) before asm can fully host workers.