feat(v4.0.0): a node is handed a line -- ENGINE.md step 1

A v4 node no longer reads its own command line or prints a prompt.  Its
host puts a line of text in the node's input buffer and starts it at
(LINE); the node interprets it and stops at (IDLE), leaving in
(LINE-STATUS) how it ended: completed, an error, or QUIT.  The host says
" ok" or " ERROR" and prompts, as the kernel's REPL does for a v3 VM.  A
line may be 1024 characters, a block, as v3's.  Ruled 2026-10-05
(V3-PARITY.md 1b); design ENGINE.md 3.1.

- quit.v4: (REPL), the node's prompt loop, is gone; (LINE) (IDLE) (DONE)
- image.h/.c: v4_line_begin, v4_line_done, v4_line_status; the node is
  idle at switch-on
- boot.c: v4_boot_line, the one loop the hosted binary, the kernel and the
  capsule loader hand a line with; the code that took " ok" and the prompt
  back out of the node's output is gone
- hosted.c, sk_v4.c: the prompt and the line editing are the host's
- test_host_quit.c: the tests are the node's host; two tests of the old
  80-character prompt line now test a whole line, 1024 and 1025 characters

Verified: make -C v4 test passes at both widths; hosted-check passes on
three ISAs; clean qemu with STARFORTH_V4=1 on amd64, aarch64 and riscv64
passes POST (550 of 550) with the same hashes as hosted, and three lines
typed at each bare-metal prompt through the serial port are answered
correctly (logs/20261005-180922, -181152, -181541).

Still the lone node: kernel_main.c starts it before the fleet tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-05 18:17:37 -04:00
co-authored by Claude Opus 5.5
parent ab7a9bf06f
commit 01c447f9ab
17 changed files with 771 additions and 253 deletions
+45 -39
View File
@@ -7,12 +7,13 @@
* docs/v4.0.0/NUCLEUS.md. This file is all the kernel adds:
*
* - what the node prints goes to the kernel's console;
* - what is typed is given to the node a line at a time. The node does
* not send back what it reads -- on the mesh that is the console node's
* job -- so the line is edited here: characters are echoed, backspace
* rubs one out, and Enter hands the line over;
* - the prompt, and the line: it is read and edited here and handed to the
* node whole (docs/v4.0.0/ENGINE.md 3.1), and how it ended is said here;
* - blocks are kept in memory, and are gone at power-off.
*
* This is the lone node, started before the kernel's fleet and beside it.
* It goes when the node is brought up in the VM's place (ENGINE.md step 4).
*
* Nothing of the v3 VM is started. docs/v4.0.0/DECOMPOSITION.md.
*/
#include "starkernel/v4/sk_v4.h"
@@ -20,34 +21,14 @@
#include "v4/boot.h"
#define SK_V4_BLOCKS 64u
#define SK_V4_LINE 79u /* QUERY takes 80 characters: 79 and the new-line */
#define SK_V4_LINE 255u /* what the line editor here takes */
static v4_node sk_v4_node;
static v4_exec_state sk_v4_es;
static v4_heat sk_v4_heat;
static unsigned char sk_v4_disk[SK_V4_BLOCKS * V4_BLOCK_BYTES];
static char sk_v4_line[SK_V4_LINE + 1u];
static unsigned sk_v4_len;
/* One character from the keyboard. A finished line goes to the node. */
static void sk_v4_key(int c)
{
if (c == '\r' || c == '\n') {
console_putc('\n');
sk_v4_line[sk_v4_len++] = '\n';
(void)v4_node_console_feed(&sk_v4_node, sk_v4_line, sk_v4_len);
sk_v4_len = 0;
} else if (c == 8 || c == 127) {
if (sk_v4_len > 0) {
sk_v4_len--;
console_putc(8); console_putc(' '); console_putc(8);
}
} else if (c >= 32 && c < 127 && sk_v4_len < SK_V4_LINE) {
sk_v4_line[sk_v4_len++] = (char)c;
console_putc((char)c);
}
}
static char sk_v4_text[SK_V4_LINE + 1u];
static void sk_v4_out(const char *text, unsigned len)
{
@@ -55,32 +36,57 @@ static void sk_v4_out(const char *text, unsigned len)
for (i = 0; i < len; i++) console_putc(text[i]);
}
/* a character for a line that reads the keyboard, when there is one */
static int sk_v4_key(void)
{
int c = console_getc();
return c < 0 ? V4_BOOT_KEY_NONE : c;
}
/* Read a line from the keyboard: characters are echoed, backspace rubs one
* out, Enter ends it. Returns its length. */
static unsigned sk_v4_readline(void)
{
unsigned len = 0;
for (;;) {
int c = console_getc();
if (c < 0) continue;
if (c == '\r' || c == '\n') { console_putc('\n'); return len; }
if (c == 8 || c == 127) {
if (len > 0) { len--; console_putc(8); console_putc(' '); console_putc(8); }
} else if (c >= 32 && c < 127 && len < SK_V4_LINE) {
sk_v4_text[len++] = (char)c;
console_putc((char)c);
}
}
}
void sk_v4_run(void)
{
const v4_image *im = &v4_capsule_image;
v4_boot boot;
unsigned i;
console_println("StarForth v4: one host node, the F18-derived engine");
boot.n = &sk_v4_node; boot.es = &sk_v4_es; boot.h = &sk_v4_heat; boot.im = im; boot.out = sk_v4_out;
boot.n = &sk_v4_node; boot.es = &sk_v4_es; boot.h = &sk_v4_heat; boot.im = &v4_capsule_image;
boot.out = sk_v4_out; boot.key = sk_v4_key;
if (!v4_boot_run(&boot, sk_v4_disk, SK_V4_BLOCKS)) {
console_println("StarForth v4: not started");
for (;;) { }
}
/* The prompt is the host's: read a line, hand it to the node, say how it
* ended. */
for (;;) {
(void)v4_exec_step_word(&sk_v4_node, &sk_v4_es, &sk_v4_heat);
if (sk_v4_node.console_len) {
for (i = 0; i < sk_v4_node.console_len; i++) console_putc((char)sk_v4_node.console[i]);
sk_v4_node.console_len = 0;
}
if (sk_v4_node.stopped) {
unsigned len;
int how;
console_puts("ok> ");
len = sk_v4_readline();
how = v4_boot_line(&boot, sk_v4_text, len);
if (how == V4_LINE_COMPLETED) console_puts(" ok\n");
else if (how == V4_LINE_ERROR) console_puts(" ERROR\n");
else if (how == V4_BOOT_LINE_STOPPED) {
console_println("StarForth v4: the node stopped on a fault");
for (;;) { }
}
if (v4_image_waiting(&sk_v4_node, im)) {
int c = console_getc();
if (c >= 0) sk_v4_key(c);
}
}
}