flan/test/programs/agent.flan
Joseph Ferano 96ab4c9cf0 Retire the per-type printers, since print says all of it
print-str, print-i64, print-f64, print-bytes, print-line and newline leave
the prelude. print and println are the whole printing surface now, and print
is the better call at every one of the sites that used them: it is the same
structural walk without the newline, so the no-newline case the family was
kept for is covered, and it takes the value as it is. The old print-i64
forced an explicit (i64 x) at every call site, because this language widens
nothing implicitly; that cast is gone from 127 places.

Dropping it moves one answer. hash-grid returns u64, and the cast through
the signed printer showed sand-headless's hash as -2851001042534928384.
print routes a u64 through flan_u64_to_bytes, so it now prints
15595743031174623232 — the same 64 bits, read as the unsigned number they
are. The pinned expectation follows the correction.

test-flan-dev.el and test_session.ml both reached for print-line as "a name
the prelude has"; they reach for rand-seed instead.
2026-09-12 05:32:25 +07:00

35 lines
1.3 KiB
Plaintext

;;;; The agent, end to end: a running program takes a redefinition over a
;;;; socket and installs it between "frames".
;;;;
;;;; [tick] is the function that gets redefined. It is called once before any
;;;; reload and once after each of two of them, and nothing else in this file
;;;; changes, so the three numbers are the whole result. Two reloads and not
;;;; one because that is the daemon's actual loop: a second module built from
;;;; the same session, reading state the first one introduced.
;;;;
;;;; It waits rather than polling on a timer because a test that races the
;;;; frame rate is a test that fails on a loaded machine. A game loop calls
;;;; poll at the top of the frame and ignores the answer; the split is in
;;;; vendor/agent/agent.flan.
(import agent "vendor:agent")
(defvar ticks i64)
(defn tick [] i64
(set ticks (+ ticks 1))
ticks)
(defn main [args [string]] i32
(if (< (len args) 2)
(do (println "usage: agent <socket>") 2)
(do
(if (< (agent/start (at args 1)) 0)
(do (println "cannot listen") 1)
(do
(print (tick)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (tick)) (println "")
(while (= (agent/wait 100) 0) 0)
(print (tick)) (println "")
0)))))