Files
LithosAnanake/include
Claude d6895bdd15 Move vocabulary and control-flow state off file-scope statics onto VM
proof/FINDINGS.md's Isabelle/HOL word-source sweep (§1) found the two
defects severe enough to actively corrupt the live Tripod multi-VM fleet:
file-scope C statics standing in for state that belongs on struct VM.

- vocabulary_words.c (highest severity in the sweep): forth_vocab/
  context_vocab/current_vocab, context_var_addr/current_var_addr, the
  ctx_fc/forth_fc first-char search index, and the `initialized` guard
  were all process-wide statics. Only the first VM to touch any
  vocabulary word ever ran setup; every VM after that silently shared
  VM #1's dictionary-chain pointers and reused VM #1's byte-offset
  addresses as if valid in its own vm->memory. One VM's VOCABULARY/
  DEFINITIONS/FORTH silently changed where every other VM looked up and
  defined words.

- control_words.c: cf_stack/cf_sp/cf_last_mode (IF/THEN/BEGIN/DO/CASE
  compile-time nesting) and the LEAVE/ENDOF patch-site bookkeeping
  (leave_addrs/leave_sp/leave_mark_*, endof_addrs/endof_sp/endof_mark_*)
  were also process-wide statics. Two VMs compiling colon definitions at
  overlapping times would corrupt each other's nesting state.

Both moved onto struct VM, following the existing hold_addr/hold_pos
precedent in include/vm.h ("lives in each VM's own memory... so child
VMs never alias Hera's buffer"):

- New VocabularyState struct (vm->vocab): chain heads, VM-cell addresses,
  first-char index, initialized flag.
- New ControlFlowState struct (vm->cf): cf_stack/cf_sp/cf_last_mode plus
  the LEAVE/ENDOF patch-site stacks. cf_tag_t/cf_item_t/CF_STACK_MAX
  moved from control_words.c into include/vm.h since they're now part of
  the struct VM field's type.
- Sentinel fields (-1/-999, meaning "empty") explicitly initialized in
  both vm_init_with_host() implementations (hosted src/vm_bootstrap.c and
  kernel src/starkernel/vm/vm_bootstrap.c) alongside the existing
  dsp/rsp = -1 initialization, since the preceding zero-init leaves them
  at 0 rather than their empty sentinel.

Every word function in both files already took VM *vm, so no call sites
outside these two files needed to change; cf_push_item/cf_pop_item/
cf_peek_item gained a VM* parameter to reach vm->cf.

Verified: hosted (amd64) and kernel (amd64, __STARKERNEL__) both build
clean with -Wall -Werror after a full clean rebuild (struct VM's layout
changed size, and this Makefile has no header-dependency tracking, so a
stale incremental build would have linked mismatched object layouts).
Hosted POST suite 1012/1012 passing (0 regressions). Manually exercised
VOCABULARY/DEFINITIONS/FORTH/ORDER, and IF/ELSE, DO/LOOP/LEAVE,
BEGIN/WHILE/REPEAT, and CASE/OF/ENDOF/ENDCASE (including nested DO with
I/J) in the REPL -- all correct and unchanged from pre-refactor behavior.

Note: a pre-existing CASE/ENDCASE default-clause bug (the code after the
last OF...ENDOF pair does not correctly become the "default" value once
DROP runs) was found while testing this refactor and confirmed present
on unmodified master too -- not touched here, out of scope for this pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014Qf6YcnHgaEtEygq3knx19
2026-09-05 14:07:41 +00:00
..
2026-08-01 07:49:56 -04:00
2026-08-01 07:49:56 -04:00
2026-08-01 07:49:56 -04:00
2026-08-01 07:49:56 -04:00

include/

Public headers for the hosted StarForth VM (src/). Kernel-only headers live under include/starkernel/.

Core VM

  • vm.h — the VM struct and all core types (DictEntry, DictPhysics, stacks, dictionary state); the central header most other files include.
  • vm_api.h — external VM API surface.
  • vm_host.h, vm_debug.h, startup.h, version.h — host integration, debug utilities, startup sequencing, version string.
  • cli.h, repl.h, io.h, log.h — CLI parsing, REPL loop, I/O, logging.
  • word_registry.h — word registration system shared by every src/word_source/*.c file.
  • compudynamics.h — the generic compudynamics module: tuning-word/config lookups (cd_tuning_word(), cd_tuning_vm()) consumed by ssm_jacquard.c.

Memory / blocks

  • memory_management.h, dictionary_management.h — dictionary allocator and search.
  • block_subsystem.h, blkcfg.h, blkio.h, blkio_factory.h — logical→ physical block mapper and pluggable block I/O backends (file/RAM).
  • platform_alloc.h, platform_lock.h, platform_time.h — platform abstraction shims (hosted vs. kernel allocation/locking/timing).

Physics-driven adaptive runtime (7 feedback loops)

  • physics_runtime.h — main physics coordinator.
  • physics_hotwords_cache.h — Loop #1, execution-heat hot-words cache.
  • physics_metadata.h — per-word DictPhysics metadata tracking.
  • physics_pipelining_metrics.h — Loop #4, word-transition prediction.
  • physics_execution_hooks.h — execution instrumentation hook points.
  • rolling_window_of_truth.h, rolling_window_knobs.h — Loop #2 circular execution-history buffer and its tuning knobs.
  • inference_engine.h — Loops #5/#6, window-width and decay-slope statistical inference.
  • dictionary_heat_optimization.h — Loop #1 heat counters.
  • ssm_jacquard.h — L8 Jacquard steady-state mode selector.
  • doe_metrics.h — Design of Experiments (2^7 factorial) metrics.
  • profiler.h — performance profiling hooks.

Arithmetic / codegen

  • q48_16.h — Q48.16 deterministic fixed-point arithmetic (used instead of IEEE-754 float specifically to keep cross-architecture behavior bit-identical).
  • math_portable.h — portable math helpers.
  • arch_detect.h, starforth_config.h — architecture detection and the build-flag fallback-default layer (used when a .c file is compiled by hand without make).
  • vm_asm_opt.h, vm_asm_opt_arm64.h, vm_asm_opt_riscv64.h, vm_inner_interp_asm.h, vm_inner_interp_arm64.h, vm_inner_interp_riscv64.h — per-architecture assembler-optimized inner interpreter (USE_ASM_OPT=1).

See include/starkernel/README.md for the bare-metal kernel headers.