Everything so far installed one module. The daemon's job is N of them against one long-lived session, and that is where a registry that hands out fresh storage per module would show up. So the agent test now takes two: the first introduces a global the process was never built with, the second only reads it. 1007 rather than 7 is the whole assertion. Getting there needed stdout to be line buffered, set in flan_rt_init. The C default when stdout is a file or a pipe is a 4K block, so a program running for minutes with a REPL attached shows nothing until it exits, and a test driving one cannot see its progress at all - which is how this was found. One write per line instead of per 4K. Also written down: flan reload builds a fresh session from source each time, so if the program file was edited since the process launched, its idea of the host's names and memory describes a binary that is not running. That is a limit of the command, not of sessions. And Session.eval's origin defaults to <eval>, so the daemon has to pass the editor's real buffer path or errors point at a file that does not exist.
35 lines
1.3 KiB
Plaintext
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 (print-line "usage: agent <socket>") 2)
|
|
(do
|
|
(if (< (agent/start (at args 1)) 0)
|
|
(do (print-line "cannot listen") 1)
|
|
(do
|
|
(print-i64 (tick)) (newline)
|
|
(while (= (agent/wait 100) 0) 0)
|
|
(print-i64 (tick)) (newline)
|
|
(while (= (agent/wait 100) 0) 0)
|
|
(print-i64 (tick)) (newline)
|
|
0)))))
|