Ruled (Captain Bob, 2026-11-14): "Find the TCG cost first". v3's whole POST took the amd64
accept from about 3 m 15 s to 8 m 45 s, and aarch64 past its 570 s (logs/20261114-091651,
STOPPED, committed). Profiled on the host (gprof, mesh-boot): 87% of the time in POST's
lines, about 280,000 opcodes a line -- the interpreter's dictionary lookup.
- POST puts the dictionary back before each of v3's suites, as v3's run_test_suite does
("to remove test-created words"): a mark, (POST), forgotten and made again
(V4_POST_SUITE). Only the dictionary: SCR, BASE and the rest stay as the cases left them.
- (LOOKUP) tries each entry by its count and first character first -- one fetch of the
name's first cell, masked -- and only then its hidden flag and the whole name. The answer
is the same; an entry that cannot be it costs a few opcodes, not some forty.
mesh-boot: 37.7 s -> 15.7 s, POST 990 of 990. make -C v4 test: all v4 tests passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
90 lines
5.1 KiB
C
90 lines
5.1 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* post.h -- POST, which is the kernel's. docs/v4.0.0/NUCLEUS.md section 6.
|
|
*
|
|
* As in v3, the kernel holds the cases and runs them on the node: nothing
|
|
* of POST is in the node's dictionary. A case is a name, its lines of
|
|
* FORTH, and what it must do. The table is generated from v3's own cases
|
|
* (v4/tools/mkpost.py -> v4/system/post_cases.c).
|
|
*/
|
|
#ifndef V4_POST_H
|
|
#define V4_POST_H
|
|
|
|
#include "v4/node.h"
|
|
|
|
#define V4_POST_STACK 0 /* its data stack and what it prints are compared */
|
|
#define V4_POST_DEPTH 1 /* only how many values it leaves; what it prints is not compared */
|
|
#define V4_POST_DEPTH_OUTPUT 2 /* how many values it leaves, and what it prints */
|
|
#define V4_POST_ERROR 3 /* it must end in an error; nothing else is compared */
|
|
#define V4_POST_HEAD 4 /* how many values it leaves, and how what it prints begins: the form of a
|
|
printout whose values are the run's own (TOP-WORDS; #189, 2026-11-14) */
|
|
#define V4_POST_KIND 7 /* the kind is expect's low bits; */
|
|
#define V4_POST_KERNEL 8 /* or'd in: the case needs the kernel's words (capsules/v4/physics.4th, its
|
|
requests on port 0) and is not run on a node with no kernel -- the hosted
|
|
product (#189 Phase 7: v3's whole POST) */
|
|
#define V4_POST_SUITE 16 /* or'd in: the first case of one of v3's suites. Before it the dictionary is put
|
|
back -- what the cases before defined is forgotten, to a mark -- as v3's
|
|
run_test_suite does after each suite ("to remove test-created words"): a
|
|
dictionary grown by every case before made each lookup longer, and 990
|
|
cases did not fit a boot's time under emulation */
|
|
|
|
typedef struct {
|
|
const char *name;
|
|
const char *const *lines; /* line_count of them, sent one at a time */
|
|
unsigned line_count;
|
|
int expect; /* V4_POST_* */
|
|
const long long *stack; /* V4_POST_STACK: depth values, the deepest first; else 0 */
|
|
unsigned depth;
|
|
const char *output; /* output_len characters */
|
|
unsigned output_len;
|
|
} v4_post_case;
|
|
|
|
extern const v4_post_case v4_post_cases[];
|
|
extern const unsigned v4_post_case_count;
|
|
|
|
/* THE RUNNER (v4/system/post.c). Whoever runs POST on a node supplies how a
|
|
* line is sent to it and where the console is. For each case the runner
|
|
* empties the node's data stack from outside; sends DECIMAL FORTH
|
|
* DEFINITIONS, the state every expected result was taken from; sends the
|
|
* case's lines one at a time, keeping what the node prints and showing none
|
|
* of it; and judges. A case passes when it ended in an error exactly if
|
|
* one was expected and, if none was, its stack and its printing are what
|
|
* the table has. It has ended in an error if any of its lines did. A
|
|
* case one of whose lines ends with QUIT fails: it went back to the
|
|
* terminal and did not complete. So does one whose starting state could
|
|
* not be set, and what the node said of that is shown. What
|
|
* the cases define is still in the node's dictionary when the runner
|
|
* returns: whoever runs POST puts the dictionary back afterwards, as v3
|
|
* does after each of its suites (v3/src/test_runner/test_common.c,
|
|
* run_test_suite: "to remove test-created words").
|
|
*
|
|
* If the node does not come back from a line -- it has stopped, or runs for
|
|
* ever -- that case fails and POST ends there: the runner says which case
|
|
* it was and how many were not run. */
|
|
#define V4_POST_OUT 1024u /* the most of a case's printing that is kept */
|
|
|
|
typedef struct {
|
|
void *self;
|
|
v4_node *n; /* the node: its data stack is read and emptied */
|
|
/* Send the node a line and run it to its end. What it prints is put at
|
|
* `out`, at most `cap` characters, and *len is how many it printed in
|
|
* all. Returns V4_TEXT_QUIT, V4_TEXT_COMPLETED or V4_TEXT_ERROR
|
|
* (message.h); or a negative number if the line did not come back. */
|
|
int (*line)(void *self, const char *text, unsigned text_len, char *out, unsigned cap, unsigned *len);
|
|
void (*say)(void *self, const char *text, unsigned len); /* the console */
|
|
int kernel; /* 1: the node has the kernel's words, so V4_POST_KERNEL cases are run */
|
|
} v4_post_host;
|
|
|
|
typedef struct { unsigned tests, pass, fail; } v4_post_tally;
|
|
|
|
/* Run the cases. Prints "POST FAIL: name out<...> stack<...>" for each
|
|
* failing case and then "PARITY:V4_POST tests=N pass=N fail=N", where tests
|
|
* is how many were run. Returns 1 if every case was run and none failed. */
|
|
int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count, v4_post_tally *tally);
|
|
|
|
/* How many of the cases are run on a node with the kernel's words (kernel 1) or without (0). */
|
|
unsigned v4_post_runs(const v4_post_case *cases, unsigned count, int kernel);
|
|
|
|
#endif /* V4_POST_H */
|