lumbda/examples/rpc-relay.lsp
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

55 lines
2 KiB
Text

;;; rpc-relay.lsp — transparent S-expression relay.
;;;
;;; Listens on *listen-port*, forwards every request byte-for-byte to
;;; *backend-host*:*backend-port*, returns the backend's reply. Used
;;; to demonstrate a multi-runtime chain: Python client → C relay →
;;; asm backend, where the same .lsp runs at every hop and the wire
;;; format (Scheme source) needs no translation.
;;;
;;; python3 lumbda.py --fast examples/rpc-relay.lsp
;;; ./c/lumbda examples/rpc-relay.lsp
;;; ./asm/lumbda < examples/rpc-relay.lsp
;;;
;;; Override *listen-port* / *backend-port* by pre-defining before load
;;; (or edit here for a one-off demo).
(define *listen-port* 9082)
(define *backend-host* "127.0.0.1")
(define *backend-port* 9080)
(define *max-requests* 100000)
;;; Forward the raw request bytes to the backend, return the raw reply.
;;; No parsing — the relay never looks inside the sexp. Bytes in,
;;; bytes out. Which is the point: S-expressions are the envelope.
(define (forward-request req)
(let ((back (tcp-connect *backend-host* *backend-port*)))
(if back
(begin
(tcp-send back req)
(let ((reply (tcp-recv back 8192)))
(tcp-close back)
(if (and reply (> (string-length reply) 0))
reply
"(error \"empty from backend\")\n")))
"(error \"backend unreachable\")\n")))
(define server (tcp-listen *listen-port*))
(define (relay-loop n snap)
(if (>= n *max-requests*)
(begin (display "request cap reached, exiting\n") (tcp-close server))
(begin
(let ((client (tcp-accept server)))
(let ((req (tcp-recv client 4096)))
(if (and req (> (string-length req) 0))
(tcp-send client (forward-request req))
#f))
(tcp-close client))
(heap-restore snap)
(relay-loop (+ n 1) snap))))
(display "rpc-relay on :") (display *listen-port*)
(display " -> ") (display *backend-host*) (display ":") (display *backend-port*)
(newline)
(relay-loop 0 (heap-snapshot))