Reorganize source tree: kernel/, v3/, v4/ split and board infrastructure
Source tree reorganization: - Move StarForth v3 engine to v3/ (src/, include/, Makefile) - Move kernel to kernel/ (src/, include/, linker/, Makefile) - Create v4/ skeleton for F18-ISA golden model (DECOMPOSITION.md, JUSTIFICATION.md) - Move FABRIC-0..4.md to docs/fabric/ - Move ONTOLOGY.md and ROADMAP.md to docs/ Board infrastructure: - Add boards/ser5/, boards/raspi/, boards/milkv/, boards/zynq7020/ - Each board has board.mk (ISA, CPU flags, boot recipe) and README.md - Root Makefile becomes thin dispatcher: boot_image, all, clean, docs take TARGET - make boot_image TARGET=SER5|RASPI|MILKV builds one GPT/MBR image per board - ZYNQ7020 target exists but stops with clear error (ARMv7 port not built yet) - scripts/mkdiskimage.sh builds disk images for all boards Docs pipeline: - docs/book/ with LaTeX master (main.tex) and Makefile - pandoc converts Markdown to LaTeX at build time - Two Lua filters: table-widths.lua (wide tables wrap), code-breaks.lua (inline code breaks) - make docs builds single PDF (754 pages, 0 missing characters) - make docs TARGET=<board> adds board appendix - build/docs/<book|board>/meta.tex stamps git commit into PDF Bug fixes: - 42 include paths that only worked by accident now use correct relative paths - clang-18 hardcode replaced with configurable CC variable (fixed aarch64 build) - Pi 5: kernel_2712.img linked at 0x80000, .bss zeroed, memory reserved - Doxyfile, .clang-tidy, README.md, Kconfig paths updated Verified: - Hosted v3 build passes 1012 tests, 0 failures - SER5 image boots in QEMU (OVMF), POST passes, K exact (65536 = Q48_ONE) - Milk-V image boots in QEMU (OpenSBI + U-Boot + bootefi), POST passes - make clean TARGET=<board> removes only that board and its ISA objects - make all builds all boards, hosted v3, and docs in one run Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# src/word_source/
|
||||
|
||||
FORTH-79 word implementations, one file per category, registered into the
|
||||
dictionary via `include/word_registry.h`. Each `.c` file here has a
|
||||
matching header in `src/word_source/include/` and (for most categories) a
|
||||
matching test module in `src/test_runner/modules/`.
|
||||
|
||||
**FORTH-79 core**
|
||||
- `arithmetic_words.c`, `mixed_arithmetic_words.c` — `+ - * / MOD ABS MIN
|
||||
MAX` and mixed-precision arithmetic.
|
||||
- `stack_words.c` — `DUP DROP SWAP ROT OVER NIP TUCK`.
|
||||
- `control_words.c` — `IF ELSE THEN DO LOOP BEGIN UNTIL WHILE`.
|
||||
- `defining_words.c` — `: ; CREATE DOES> VARIABLE CONSTANT`.
|
||||
- `memory_words.c` — `@ ! C@ C! MOVE FILL`.
|
||||
- `return_stack_words.c` — `>R R> R@ RDROP 2>R 2R@ 2R>`.
|
||||
- `double_words.c` — `2DUP 2DROP 2SWAP 2@ 2! D+ D-`.
|
||||
- `logical_words.c` — `AND OR XOR NOT INVERT LSHIFT RSHIFT`.
|
||||
- `io_words.c` — `EMIT KEY TYPE CR TAB SPACE ACCEPT`.
|
||||
- `string_words.c` — `S" SLITERAL` and other string operations.
|
||||
- `block_words.c` — `BLOCK BUFFER LOAD THRU FLUSH`.
|
||||
- `format_words.c` — `.( .R .S HEX DECIMAL BASE`.
|
||||
- `system_words.c` — `BYE ABORT INCLUDE STATE`.
|
||||
- `dictionary_words.c` — `FIND SEARCH-WORDLIST WORDS`.
|
||||
- `dictionary_manipulation_words.c` — dictionary entry manipulation words.
|
||||
- `vocabulary_words.c` — `VOCABULARY DEFINITIONS FORTH-WORDLIST`.
|
||||
- `editor_words.c` — block editor words.
|
||||
- `defer_words.c` — `DEFER`/`IS` deferred-word mechanism, used by the
|
||||
Tripod message-dispatch shim (see `tools/hermes_tripod_smoke.sh`).
|
||||
|
||||
**StarForth-specific extensions**
|
||||
- `q48_16_words.c`, `q48_words.c` — Q48.16 fixed-point word bindings.
|
||||
- `starforth_words.c` — StarForth-specific extensions.
|
||||
- `acl_words.c` — word-level ACL system's FORTH-callable primitives (see
|
||||
`docs/03-architecture/word-acl/`).
|
||||
- `lifecycle_words_hosted.c` — hosted-build VM lifecycle words (birth/run
|
||||
primitives on the hosted side; kernel-only primitives live in
|
||||
`src/starkernel/capsule/mama_forth_words.c`).
|
||||
- `log_words.c` — FORTH-callable logging primitives.
|
||||
- `inference_words.c` — FORTH-callable bindings for the statistical
|
||||
inference engine (Loops #5/#6).
|
||||
- `physics_benchmark_words.c` — benchmark harness for the 7 physics
|
||||
feedback loops.
|
||||
- `physics_diagnostic_words.c` — physics diagnostics (`WORD-ENTROPY`).
|
||||
- `physics_freeze_words.c` — `PHYSICS-FREEZE` / `PHYSICS-THAW`.
|
||||
- `physics_pipelining_diagnostic_words.c` — Loop #4 pipelining
|
||||
diagnostics.
|
||||
- `dictionary_heat_diagnostic_words.c` — Loop #1 heat diagnostics.
|
||||
|
||||
See `src/word_source/include/` for the matching headers (also includes
|
||||
`mama_forth_words.h`, whose `.c` implementation lives under
|
||||
`src/starkernel/capsule/` since it's kernel-only).
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* DEFER / IS / DEFER@ primitives — late-binding deferred words.
|
||||
*
|
||||
* DEFER name ( -- ) Create a deferred word, data field = 0 (unset).
|
||||
* IS name ( xt -- ) Store xt into the data field of a DEFER word.
|
||||
* DEFER@ name ( -- xt ) Fetch the current action xt of a DEFER word.
|
||||
*
|
||||
* When a deferred word executes, defer_runtime reads its data field
|
||||
* (a raw DictEntry*) and calls that entry's func directly. This is
|
||||
* essential because the inner interpreter stores DictEntry* pointers
|
||||
* in compiled bodies at compile time — redefining a colon word after
|
||||
* compilation does not update callers. DEFER/IS gives late binding
|
||||
* without any name-lookup overhead at execution time.
|
||||
*
|
||||
* IS enforces that the named word was created by DEFER (func ==
|
||||
* defer_runtime). Attempting IS on any other word sets vm->error.
|
||||
*/
|
||||
|
||||
#include "include/defer_words.h"
|
||||
#include "../../include/vm.h"
|
||||
#include "../../include/word_registry.h"
|
||||
#include "../../include/log.h"
|
||||
#include "../../include/dictionary_management.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* ── defer_runtime ─────────────────────────────────────────────────────
|
||||
* The func stored in every DEFER-created word.
|
||||
* Data field = 0 means unset → error. Non-zero = DictEntry* to call.
|
||||
*/
|
||||
static void defer_runtime(VM *vm)
|
||||
{
|
||||
if (!vm || !vm->current_executing_entry) { if (vm) vm->error = 1; return; }
|
||||
|
||||
DictEntry *self = vm->current_executing_entry;
|
||||
cell_t *df = vm_dictionary_get_data_field(self);
|
||||
if (!df || *df == 0)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER runtime: no target set for '%.*s'",
|
||||
(int)self->name_len, self->name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
DictEntry *target = (DictEntry *)(uintptr_t)(*df);
|
||||
if (!target || !target->func)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER runtime: invalid target for '%.*s'",
|
||||
(int)self->name_len, self->name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
vm->current_executing_entry = target;
|
||||
target->func(vm);
|
||||
}
|
||||
|
||||
/* ── DEFER ─────────────────────────────────────────────────────────────
|
||||
* DEFER name ( -- )
|
||||
* Creates a new dictionary entry with defer_runtime as its func.
|
||||
* Data field initialised to 0 (unset). Calling the word before IS
|
||||
* has been used will set vm->error.
|
||||
*/
|
||||
static void word_defer(VM *vm)
|
||||
{
|
||||
char name[WORD_NAME_MAX + 1];
|
||||
int len = vm_parse_word(vm, name, sizeof(name));
|
||||
if (len <= 0)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER: missing name");
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
DictEntry *de = vm_create_word(vm, name, (size_t)len, defer_runtime);
|
||||
if (!de)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER: vm_create_word failed for '%.*s'", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t *df = vm_dictionary_get_data_field(de);
|
||||
if (!df)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER: no data field for '%.*s'", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
*df = 0; /* unset — defer_runtime will error if called before IS */
|
||||
|
||||
log_message(LOG_DEBUG, "DEFER: created '%.*s' (unset)", len, name);
|
||||
}
|
||||
|
||||
/* ── IS ────────────────────────────────────────────────────────────────
|
||||
* IS name ( xt -- )
|
||||
* Pops an execution token (DictEntry*) from the stack, parses the next
|
||||
* word from input, and stores the xt into that word's data field.
|
||||
* The named word MUST have been created by DEFER; any other word causes
|
||||
* an error. This prevents corrupting non-DEFER words' memory.
|
||||
*/
|
||||
static void word_is(VM *vm)
|
||||
{
|
||||
if (vm->dsp < 0)
|
||||
{
|
||||
log_message(LOG_ERROR, "IS: stack underflow");
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t xt = vm_pop(vm);
|
||||
|
||||
char name[WORD_NAME_MAX + 1];
|
||||
int len = vm_parse_word(vm, name, sizeof(name));
|
||||
if (len <= 0)
|
||||
{
|
||||
log_message(LOG_ERROR, "IS: missing name");
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
DictEntry *de = vm_find_word(vm, name, (size_t)len);
|
||||
if (!de)
|
||||
{
|
||||
log_message(LOG_ERROR, "IS: word '%.*s' not found", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (de->func != defer_runtime)
|
||||
{
|
||||
log_message(LOG_ERROR, "IS: '%.*s' was not created by DEFER", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t *df = vm_dictionary_get_data_field(de);
|
||||
if (!df)
|
||||
{
|
||||
log_message(LOG_ERROR, "IS: no data field for '%.*s'", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
*df = xt;
|
||||
log_message(LOG_DEBUG, "IS: stored xt into '%.*s'", len, name);
|
||||
}
|
||||
|
||||
/* ── DEFER@ ────────────────────────────────────────────────────────────
|
||||
* DEFER@ name ( -- xt )
|
||||
* Parses the next word from input and pushes its current action xt.
|
||||
* The named word must have been created by DEFER.
|
||||
*/
|
||||
static void word_defer_fetch(VM *vm)
|
||||
{
|
||||
char name[WORD_NAME_MAX + 1];
|
||||
int len = vm_parse_word(vm, name, sizeof(name));
|
||||
if (len <= 0)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER@: missing name");
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
DictEntry *de = vm_find_word(vm, name, (size_t)len);
|
||||
if (!de)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER@: word '%.*s' not found", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (de->func != defer_runtime)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER@: '%.*s' was not created by DEFER", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t *df = vm_dictionary_get_data_field(de);
|
||||
if (!df)
|
||||
{
|
||||
log_message(LOG_ERROR, "DEFER@: no data field for '%.*s'", len, name);
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
vm_push(vm, *df);
|
||||
log_message(LOG_DEBUG, "DEFER@: fetched xt from '%.*s'", len, name);
|
||||
}
|
||||
|
||||
/* ── Registration ──────────────────────────────────────────────────────*/
|
||||
void register_defer_words(VM *vm)
|
||||
{
|
||||
register_word(vm, "DEFER", word_defer);
|
||||
register_word(vm, "IS", word_is);
|
||||
register_word(vm, "DEFER@", word_defer_fetch);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
*** StarForth ***
|
||||
|
||||
dictionary_heat_diagnostic_words.c - FORTH Interface for Dictionary Heat Optimization
|
||||
|
||||
Introspection words to observe and control heat-aware dictionary lookup behavior.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vm.h"
|
||||
#include "word_registry.h"
|
||||
#include "platform_time.h"
|
||||
#include "dictionary_heat_optimization.h"
|
||||
|
||||
/**
|
||||
* @brief HEAT-PERCENTILES ( -- 25th 50th 75th )
|
||||
*
|
||||
* Pushes the three heat percentile thresholds currently used by the
|
||||
* heat-aware dictionary lookup strategy: @c heat_threshold_25th,
|
||||
* @c heat_threshold_50th, and @c heat_threshold_75th. These are updated
|
||||
* by @c dict_update_heat_percentiles() during bucket reorganisation.
|
||||
*
|
||||
* Stack effect: ( -- 25th 50th 75th ) TOS = 75th
|
||||
*
|
||||
* @param vm Active VM; sets @c vm->error = 1 on stack overflow
|
||||
*/
|
||||
void forth_HEAT_PERCENTILES(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
if (vm->dsp + 3 > STACK_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
vm->data_stack[vm->dsp++] = vm->heat_threshold_25th;
|
||||
vm->data_stack[vm->dsp++] = vm->heat_threshold_50th;
|
||||
vm->data_stack[vm->dsp++] = vm->heat_threshold_75th;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LOOKUP-STRATEGY@ ( -- strategy )
|
||||
*
|
||||
* Pushes the current dictionary lookup strategy: 0 = naive (newest-first
|
||||
* linear scan), 1 = heat-aware (hot-bucket-first).
|
||||
*
|
||||
* Stack effect: ( -- strategy )
|
||||
*
|
||||
* @param vm Active VM; sets @c vm->error = 1 on stack overflow
|
||||
*/
|
||||
void forth_LOOKUP_STRATEGY_FETCH(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
if (vm->dsp >= STACK_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
vm->data_stack[vm->dsp++] = (cell_t)vm->lookup_strategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LOOKUP-STRATEGY! ( strategy -- )
|
||||
*
|
||||
* Sets @c vm->lookup_strategy to @c strategy. Only values 0 (naive) and
|
||||
* 1 (heat-aware) are accepted; out-of-range values are silently discarded.
|
||||
*
|
||||
* Stack effect: ( strategy -- )
|
||||
*
|
||||
* @param vm Active VM; sets @c vm->error = 1 on stack underflow
|
||||
*/
|
||||
void forth_LOOKUP_STRATEGY_STORE(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
if (vm->dsp < 1) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t strategy = vm->data_stack[--vm->dsp];
|
||||
if (strategy == 0 || strategy == 1) {
|
||||
vm->lookup_strategy = (int)strategy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief REORG-BUCKETS ( -- )
|
||||
*
|
||||
* Immediately triggers @c dict_reorganize_buckets_by_heat() followed by
|
||||
* @c dict_update_heat_percentiles() to re-sort the dictionary's lookup
|
||||
* buckets by current execution heat and refresh the percentile thresholds.
|
||||
* Normally this happens automatically on a heartbeat cycle; this word forces
|
||||
* it on-demand for testing or after a large batch of @c HEAT! assignments.
|
||||
*
|
||||
* Stack effect: ( -- )
|
||||
*
|
||||
* @param vm Active VM; no-op if @c vm->error is set
|
||||
*/
|
||||
void forth_REORG_BUCKETS(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
dict_reorganize_buckets_by_heat(vm);
|
||||
dict_update_heat_percentiles(vm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SHOW-HEAT-OPTIMIZATION ( -- )
|
||||
*
|
||||
* Prints a summary of the current dictionary heat optimization state to
|
||||
* @c stdout: the active lookup strategy (naive or heat-aware), the three
|
||||
* percentile threshold values, and the resulting hot/warm/cool heat zones.
|
||||
* Intended for interactive diagnostics.
|
||||
*
|
||||
* Stack effect: ( -- )
|
||||
*
|
||||
* @param vm Active VM; no-op if @c vm->error is set
|
||||
*/
|
||||
void forth_SHOW_HEAT_OPTIMIZATION(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
printf("\n=== Dictionary Heat Optimization Status ===\n");
|
||||
|
||||
printf("Lookup Strategy: ");
|
||||
if (vm->lookup_strategy == 0) {
|
||||
printf("NAIVE (newest-first search)\n");
|
||||
} else if (vm->lookup_strategy == 1) {
|
||||
printf("HEAT-AWARE (hot words first)\n");
|
||||
} else {
|
||||
printf("UNKNOWN (%d)\n", vm->lookup_strategy);
|
||||
}
|
||||
|
||||
printf("Heat Percentile Thresholds:\n");
|
||||
printf(" 25th percentile: %ld\n", vm->heat_threshold_25th);
|
||||
printf(" 50th percentile: %ld\n", vm->heat_threshold_50th);
|
||||
printf(" 75th percentile: %ld\n", vm->heat_threshold_75th);
|
||||
|
||||
printf("\nHeat Zones:\n");
|
||||
printf(" TOP 25%% (hot) : >= %ld heat\n", vm->heat_threshold_75th);
|
||||
printf(" MIDDLE 50%% (warm) : %ld - %ld heat\n",
|
||||
vm->heat_threshold_25th, vm->heat_threshold_75th);
|
||||
printf(" BOTTOM 25%% (cool) : < %ld heat\n", vm->heat_threshold_25th);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief COMPARE-LOOKUPS ( iterations -- )
|
||||
*
|
||||
* Micro-benchmark that measures naive vs heat-aware dictionary lookup
|
||||
* performance over @c iterations passes through six common test words
|
||||
* (DUP, DROP, SWAP, @, !, EMIT). Prints elapsed time in milliseconds and
|
||||
* the percentage speedup (or slowdown) for heat-aware vs naive. Restores
|
||||
* the original @c vm->lookup_strategy on completion. Intended for
|
||||
* interactive diagnostics; not used in DoE mode.
|
||||
*
|
||||
* Stack effect: ( iterations -- )
|
||||
*
|
||||
* @param vm Active VM; sets @c vm->error = 1 on underflow or non-positive @c iterations
|
||||
*/
|
||||
void forth_COMPARE_LOOKUPS(VM *vm) {
|
||||
if (vm->error) return;
|
||||
|
||||
if (vm->dsp < 1) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
cell_t iterations = vm->data_stack[--vm->dsp];
|
||||
if (iterations <= 0) {
|
||||
printf("Need positive iteration count\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("\n=== Dictionary Lookup Comparison ===\n");
|
||||
printf("Iterations: %ld\n", iterations);
|
||||
|
||||
/* Common test words */
|
||||
const char *test_words[] = {"DUP", "DROP", "SWAP", "@", "!", "EMIT", NULL};
|
||||
|
||||
/* Strategy 1: Naive (current strategy) */
|
||||
printf("\nNaive (newest-first) lookup:\n");
|
||||
int orig_strategy = vm->lookup_strategy;
|
||||
vm->lookup_strategy = 0;
|
||||
|
||||
uint64_t start_ns = sf_monotonic_ns();
|
||||
for (cell_t i = 0; i < iterations; i++) {
|
||||
for (int j = 0; test_words[j]; j++) {
|
||||
vm_find_word(vm, test_words[j], strlen(test_words[j]));
|
||||
}
|
||||
}
|
||||
uint64_t naive_ns = sf_monotonic_ns() - start_ns;
|
||||
|
||||
/* Strategy 2: Heat-aware */
|
||||
printf("Heat-aware lookup:\n");
|
||||
dict_reorganize_buckets_by_heat(vm);
|
||||
vm->lookup_strategy = 1;
|
||||
|
||||
start_ns = sf_monotonic_ns();
|
||||
for (cell_t i = 0; i < iterations; i++) {
|
||||
for (int j = 0; test_words[j]; j++) {
|
||||
vm_find_word(vm, test_words[j], strlen(test_words[j]));
|
||||
}
|
||||
}
|
||||
uint64_t heat_ns = sf_monotonic_ns() - start_ns;
|
||||
|
||||
/* Restore original strategy */
|
||||
vm->lookup_strategy = orig_strategy;
|
||||
|
||||
/* Report results_run_01_2025_12_08 */
|
||||
printf("\n=== Benchmark Results ===\n");
|
||||
printf("Naive time: %.3f ms\n", (double)naive_ns / 1000000.0);
|
||||
printf("Heat-aware time: %.3f ms\n", (double)heat_ns / 1000000.0);
|
||||
|
||||
if (heat_ns > 0) {
|
||||
double speedup = (double)naive_ns / (double)heat_ns;
|
||||
if (speedup > 1.0) {
|
||||
printf("Speedup: %.2f%% faster\n", (speedup - 1.0) * 100.0);
|
||||
} else {
|
||||
printf("Slowdown: %.2f%% slower\n", (1.0 - speedup) * 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register all dictionary heat diagnostic words with the VM dictionary.
|
||||
*
|
||||
* Registers: @c HEAT-PERCENTILES, @c LOOKUP-STRATEGY@, @c LOOKUP-STRATEGY!,
|
||||
* @c REORG-BUCKETS, @c SHOW-HEAT-OPTIMIZATION, @c COMPARE-LOOKUPS.
|
||||
* Called during VM bootstrap.
|
||||
*
|
||||
* @param vm Active VM to register words into
|
||||
*/
|
||||
void register_dictionary_heat_diagnostic_words(VM *vm) {
|
||||
register_word(vm, "HEAT-PERCENTILES", forth_HEAT_PERCENTILES);
|
||||
register_word(vm, "LOOKUP-STRATEGY@", forth_LOOKUP_STRATEGY_FETCH);
|
||||
register_word(vm, "LOOKUP-STRATEGY!", forth_LOOKUP_STRATEGY_STORE);
|
||||
register_word(vm, "REORG-BUCKETS", forth_REORG_BUCKETS);
|
||||
register_word(vm, "SHOW-HEAT-OPTIMIZATION", forth_SHOW_HEAT_OPTIMIZATION);
|
||||
register_word(vm, "COMPARE-LOOKUPS", forth_COMPARE_LOOKUPS);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#include "include/dictionary_words.h"
|
||||
#include "../../include/word_registry.h"
|
||||
#include "vm.h"
|
||||
#include "../../include/log.h"
|
||||
|
||||
/* === SAFE DICTIONARY WORDS IMPLEMENTATION (addresses are VM offsets) === */
|
||||
|
||||
/**
|
||||
* @brief HERE ( -- addr ) Returns the dictionary pointer
|
||||
* @param vm Pointer to the VM structure
|
||||
*/
|
||||
void dictionary_word_here(VM *vm) {
|
||||
vm_push(vm, vm->here);
|
||||
}
|
||||
|
||||
static void dictionary_word_align(VM *vm) {
|
||||
vm_align(vm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ALLOT ( n -- ) Allocate n bytes in dictionary
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Allocates n bytes in the dictionary. n can be negative to deallocate space
|
||||
*/
|
||||
void dictionary_word_allot(VM *vm) {
|
||||
if (vm->dsp < 0) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
cell_t n = vm_pop(vm);
|
||||
cell_t new_here = vm->here + n;
|
||||
/* Dictionary growth is bounded to DICTIONARY_MEMORY_SIZE, not the full
|
||||
* VM_MEMORY_SIZE: blocks >= USER_BLOCKS_START live in the same flat
|
||||
* vm->memory array (see vm_get_block_addr), so letting `here` grow past
|
||||
* the dictionary region would silently corrupt live block/user data. */
|
||||
if (new_here < 0 || new_here > (cell_t) DICTIONARY_MEMORY_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vm->here = new_here;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief , ( n -- ) Compile cell into dictionary
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Compiles a single cell value into the dictionary at HERE
|
||||
*/
|
||||
void dictionary_word_comma(VM *vm) {
|
||||
if (vm->dsp < 0) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
cell_t n = vm_pop(vm);
|
||||
vm_align(vm);
|
||||
if (vm->here + (cell_t) sizeof(cell_t) > DICTIONARY_MEMORY_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vaddr_t addr = VM_ADDR(vm->here);
|
||||
if (!vm_addr_ok(vm, addr, sizeof(cell_t))) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vm_store_cell(vm, addr, n);
|
||||
vm->here += sizeof(cell_t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief C, ( c -- ) Compile byte into dictionary
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Compiles a single byte value into the dictionary at HERE
|
||||
*/
|
||||
void dictionary_word_c_comma(VM *vm) {
|
||||
if (vm->dsp < 0) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
cell_t c = vm_pop(vm);
|
||||
if (vm->here + 1 > DICTIONARY_MEMORY_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vaddr_t a = VM_ADDR(vm->here);
|
||||
if (!vm_addr_ok(vm, a, 1)) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vm_store_u8(vm, a, (uint8_t)(c & 0xFF));
|
||||
vm->here += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 2, ( d -- ) Compile double-cell into dictionary
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Compiles a double cell value into the dictionary at HERE, low cell first
|
||||
*/
|
||||
void dictionary_word_2comma(VM *vm) {
|
||||
if (vm->dsp < 1) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
cell_t high = vm_pop(vm);
|
||||
cell_t low = vm_pop(vm);
|
||||
vm_align(vm);
|
||||
if (vm->here + (cell_t)(2 * sizeof(cell_t)) > DICTIONARY_MEMORY_SIZE) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vaddr_t a = VM_ADDR(vm->here);
|
||||
if (!vm_addr_ok(vm, a, 2 * sizeof(cell_t))) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
vm_store_cell(vm, a, low);
|
||||
vm_store_cell(vm, a + sizeof(cell_t), high);
|
||||
vm->here += 2 * sizeof(cell_t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PAD ( -- addr ) Get scratch pad buffer address
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Returns VM address of 512-byte temporary text buffer at top of memory
|
||||
*/
|
||||
void dictionary_word_pad(VM *vm) {
|
||||
size_t pad_offset = VM_MEMORY_SIZE - 512;
|
||||
vm_push(vm, (cell_t) pad_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SP@ ( -- sp ) Get current stack pointer
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Returns the current stack-pointer index (top is 0)
|
||||
*/
|
||||
void dictionary_word_sp_fetch(VM *vm) {
|
||||
/* No stack args required */
|
||||
vm_push(vm, (cell_t) vm->dsp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SP! ( sp -- ) Set stack pointer
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Restores the stack-pointer, but never allows growing the stack
|
||||
*/
|
||||
void dictionary_word_sp_store(VM *vm) {
|
||||
if (vm->dsp < 0) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
} /* need one arg */
|
||||
cell_t new_sp = vm_pop(vm);
|
||||
|
||||
/* Valid range: -1 (empty stack) up to current dsp (can shrink, not grow) */
|
||||
if (new_sp < -1 || new_sp > vm->dsp) {
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
vm->dsp = new_sp;
|
||||
/* We don’t need to scrub values above dsp; they’re considered garbage/unused. */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LATEST ( -- addr ) Get latest definition address
|
||||
* @param vm Pointer to the VM structure
|
||||
* @details Returns VM address near most recent compiled definition (end of dictionary)
|
||||
*/
|
||||
void dictionary_word_latest(VM *vm) {
|
||||
vm_push(vm, vm->here);
|
||||
}
|
||||
|
||||
/* Registration */
|
||||
void register_dictionary_words(VM *vm) {
|
||||
register_word(vm, "HERE", dictionary_word_here);
|
||||
register_word(vm, "ALIGN", dictionary_word_align);
|
||||
register_word(vm, "ALLOT", dictionary_word_allot);
|
||||
register_word(vm, ",", dictionary_word_comma);
|
||||
register_word(vm, "C,", dictionary_word_c_comma);
|
||||
register_word(vm, "2,", dictionary_word_2comma);
|
||||
register_word(vm, "PAD", dictionary_word_pad);
|
||||
register_word(vm, "SP!", dictionary_word_sp_store);
|
||||
register_word(vm, "SP@", dictionary_word_sp_fetch);
|
||||
register_word(vm, "LATEST", dictionary_word_latest);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0
|
||||
*/
|
||||
|
||||
/* framebuffer_words.c — raw framebuffer hardware-boundary FORTH words
|
||||
* (FABRIC-0.md item 4.3.3). Kernel-only; no-op on hosted builds. */
|
||||
|
||||
#include "include/framebuffer_words.h"
|
||||
#include "../../include/log.h"
|
||||
#include "../../include/word_registry.h"
|
||||
|
||||
#ifdef __STARKERNEL__
|
||||
#include "starkernel/framebuffer.h"
|
||||
#endif
|
||||
|
||||
/* PLOT ( x y color -- ) : raw raster pixel write, top-left origin, Y-down.
|
||||
* No Cartesian awareness -- that is capsules/fabric.4th's job. */
|
||||
static void fbw_plot(VM *vm)
|
||||
{
|
||||
if (vm->dsp < 2) {
|
||||
log_message(LOG_ERROR, "PLOT: Stack underflow");
|
||||
vm->error = 1;
|
||||
return;
|
||||
}
|
||||
cell_t color = vm_pop(vm);
|
||||
cell_t y = vm_pop(vm);
|
||||
cell_t x = vm_pop(vm);
|
||||
#ifdef __STARKERNEL__
|
||||
fb_put_pixel((uint32_t)x, (uint32_t)y, (uint32_t)color);
|
||||
#else
|
||||
(void)x; (void)y; (void)color;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* FB-WIDTH ( -- n ) */
|
||||
static void fbw_width(VM *vm)
|
||||
{
|
||||
#ifdef __STARKERNEL__
|
||||
vm_push(vm, (cell_t)fb_width());
|
||||
#else
|
||||
vm_push(vm, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* FB-HEIGHT ( -- n ) */
|
||||
static void fbw_height(VM *vm)
|
||||
{
|
||||
#ifdef __STARKERNEL__
|
||||
vm_push(vm, (cell_t)fb_height());
|
||||
#else
|
||||
vm_push(vm, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void register_framebuffer_words(VM *vm)
|
||||
{
|
||||
register_word(vm, "PLOT", fbw_plot);
|
||||
register_word(vm, "FB-WIDTH", fbw_width);
|
||||
register_word(vm, "FB-HEIGHT", fbw_height);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# src/word_source/include/
|
||||
|
||||
Public headers for `src/word_source/`, one per `.c` file there (see
|
||||
`src/word_source/README.md` for the category breakdown), plus
|
||||
`control_words.h` and `mama_forth_words.h`:
|
||||
|
||||
- `control_words.h` — declarations for `control_words.c`'s `IF`/`THEN`/
|
||||
`ELSE`/`BEGIN`/`DO`/`LOOP` family.
|
||||
- `mama_forth_words.h` — declares the Mama VM word bindings implemented in
|
||||
`src/starkernel/capsule/mama_forth_words.c` (kernel-only; the header
|
||||
lives here for consistency with the rest of the word-category headers).
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "vm.h"
|
||||
|
||||
/* Register all ACL C primitive words into the VM dictionary */
|
||||
void register_acl_words(VM *vm);
|
||||
|
||||
/* Direct C entry point for birth inheritance (no stack manipulation needed) */
|
||||
void acl_inherit_entry(DictEntry *src, DictEntry *dst);
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ARITHMETIC_WORDS_H
|
||||
#define ARITHMETIC_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/* FORTH-79 Arithmetic Words:
|
||||
* + ( n1 n2 -- n3 ) Add n1 and n2
|
||||
* - ( n1 n2 -- n3 ) Subtract n2 from n1
|
||||
* * ( n1 n2 -- n3 ) Multiply n1 and n2
|
||||
* / ( n1 n2 -- n3 ) Divide n1 by n2
|
||||
* MOD ( n1 n2 -- n3 ) Remainder of n1/n2
|
||||
* /MOD ( n1 n2 -- n3 n4 ) n3=remainder, n4=quotient of n1/n2
|
||||
* NEGATE ( n1 -- n2 ) Negate n1
|
||||
* ABS ( n1 -- n2 ) Absolute value of n1
|
||||
* MIN ( n1 n2 -- n3 ) Minimum of n1 and n2
|
||||
* MAX ( n1 n2 -- n3 ) Maximum of n1 and n2
|
||||
* 1+ ( n1 -- n2 ) Add 1 to n1
|
||||
* 1- ( n1 -- n2 ) Subtract 1 from n1
|
||||
* 2* ( n1 -- n2 ) Multiply n1 by 2 (left shift)
|
||||
* 2/ ( n1 -- n2 ) Divide n1 by 2 (right shift)
|
||||
* STAR-SLASH ( n1 n2 n3 -- n4 ) Multiply n1*n2, divide by n3
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Registers all FORTH-79 arithmetic words with the virtual machine
|
||||
*
|
||||
* Registers the following words:
|
||||
* - + (add)
|
||||
* - - (subtract)
|
||||
* - * (multiply)
|
||||
* - / (divide)
|
||||
* - MOD (modulo)
|
||||
* - /MOD (divide with remainder)
|
||||
* - NEGATE
|
||||
* - ABS (absolute)
|
||||
* - MIN
|
||||
* - MAX
|
||||
* - 1+ (increment)
|
||||
* - 1- (decrement)
|
||||
* - 2* (multiply by 2)
|
||||
* - 2/ (divide by 2)
|
||||
* - STAR-SLASH (multiply then divide)
|
||||
*
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_arithmetic_words(VM * vm);
|
||||
|
||||
#endif /* ARITHMETIC_WORDS_H */
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file block_words.h
|
||||
* @brief FORTH-79 Block and Buffer System Implementation
|
||||
*
|
||||
* This file implements the standard FORTH-79 block and buffer words:
|
||||
* @li BLOCK ( u -- addr ) Get block buffer address
|
||||
* @li BUFFER ( u -- addr ) Get empty buffer for block
|
||||
* @li UPDATE ( -- ) Mark current block as modified
|
||||
* @li SAVE-BUFFERS ( -- ) Save all modified blocks
|
||||
* @li EMPTY-BUFFERS ( -- ) Mark all buffers as empty
|
||||
* @li FLUSH ( -- ) Save buffers and empty them
|
||||
* @li LIST ( u -- ) List block contents
|
||||
* @li LOAD ( u -- ) Load and interpret block
|
||||
* @li SCR ( -- addr ) Variable: screen/block being listed
|
||||
* @li THRU ( u1 u2 -- ) Load blocks from u1 to u2
|
||||
* @li --> or → ( -- ) Continue to next block
|
||||
*/
|
||||
|
||||
#ifndef BLOCK_WORDS_H
|
||||
#define BLOCK_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/** @name Block System Configuration
|
||||
* @{
|
||||
*/
|
||||
/** @brief Size of each block in bytes (1KB) */
|
||||
#define BLOCK_SIZE 1024
|
||||
/** @brief Maximum number of blocks (1024 blocks from 1MB memory) */
|
||||
#define MAX_BLOCKS (VM_MEMORY_SIZE / BLOCK_SIZE)
|
||||
/** @brief Number of block buffers in memory */
|
||||
#define BUFFER_COUNT 4
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @brief Block buffer types for different storage mechanisms
|
||||
*/
|
||||
typedef enum {
|
||||
BUFFER_TYPE_MEMORY, /**< Direct memory access (current implementation) */
|
||||
BUFFER_TYPE_HARDWARE, /**< Future: Hardware register blocks */
|
||||
BUFFER_TYPE_STORAGE, /**< Future: Persistent storage blocks */
|
||||
BUFFER_TYPE_NETWORK /**< Future: Network packet buffers */
|
||||
} buffer_type_t;
|
||||
|
||||
/**
|
||||
* @brief Block buffer structure maintaining buffer state
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned char data[BLOCK_SIZE]; /**< Block content buffer */
|
||||
int block_number; /**< Currently loaded block number (-1 = empty) */
|
||||
int dirty; /**< Modified flag for write-back */
|
||||
int accessed; /**< LRU counter for buffer management */
|
||||
buffer_type_t type; /**< Buffer type for storage mechanism */
|
||||
uintptr_t hw_address; /**< Future: Hardware backing address */
|
||||
} BlockBuffer;
|
||||
|
||||
/**
|
||||
* @brief Registers all block and buffer words with the virtual machine
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_block_words(VM * vm);
|
||||
|
||||
/**
|
||||
* @brief Initializes the block system
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void init_block_system(VM * vm);
|
||||
|
||||
/*
|
||||
* @brief Gets a buffer containing the specified block
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
* @param block_num Block number to retrieve
|
||||
* @return Pointer to the block buffer data
|
||||
*/
|
||||
unsigned char *get_block_buffer(VM *vm, int block_num);
|
||||
|
||||
/*
|
||||
* @brief Gets an empty buffer for the specified block
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
* @param block_num Block number to allocate
|
||||
* @return Pointer to the empty buffer data
|
||||
*/
|
||||
unsigned char *get_empty_buffer(VM *vm, int block_num);
|
||||
|
||||
/**
|
||||
* @brief Marks the current buffer as modified
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void mark_buffer_dirty(VM * vm);
|
||||
|
||||
/*
|
||||
* @brief Saves all modified buffers to storage
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void save_all_buffers(VM * vm);
|
||||
|
||||
/**
|
||||
* @brief Sync every dirty VM block-window slot to the C-layer block cache,
|
||||
* then flush the whole block subsystem to physical media --
|
||||
* the complete SAVE-BUFFERS implementation (unlike
|
||||
* save_all_buffers() above, which only calls blk_flush() and so
|
||||
* misses any BUFFER-modified-but-not-yet-UPDATE'd content still
|
||||
* sitting only in vm->memory's window). Cheap to call when nothing
|
||||
* is dirty -- every check inside is a small fixed-size scan, no
|
||||
* I/O happens unless something actually needs writing. Safe to
|
||||
* call from outside word dispatch (e.g. a periodic idle-tick
|
||||
* auto-flush); vm must be non-NULL.
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void blk_vm_flush_all(VM * vm);
|
||||
|
||||
/*
|
||||
* @brief Marks all buffers as empty
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void empty_all_buffers(VM * vm);
|
||||
|
||||
/**
|
||||
* @brief Discards vm->blk_vm_lbn[]/cbuf[]/dirty[] if the device chain has
|
||||
* changed since last validated (see this function's own doc comment in
|
||||
* block_words.c for why). Exposed (Phase 8 v3, 2026-09-23) so callers
|
||||
* outside this file that read vm->blk_vm_lbn[] directly (MOVE/CMOVE's
|
||||
* cross-device block-copy check, memory_words.c/string_words.c) go through
|
||||
* the same invalidation contract blk_vm_find() already uses internally,
|
||||
* rather than a second, divergent copy of this logic.
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void blk_vm_check_epoch(VM *vm);
|
||||
|
||||
/**
|
||||
* @brief Does `addr` fall inside the block I/O window? Pure address
|
||||
* arithmetic against the window's fixed compile-time base/size -- no VM
|
||||
* state needed. Exposed (Phase 8 v3, 2026-09-23) for MOVE/CMOVE/CMOVE>'s
|
||||
* cross-device block-copy check.
|
||||
* @param addr VM offset to test
|
||||
* @return slot index (0..BLK_VM_SLOTS-1) if inside the window, -1 otherwise
|
||||
*/
|
||||
int blk_vm_slot_for_addr(vaddr_t addr);
|
||||
|
||||
/**
|
||||
* @brief True if addr1/addr2 are both block-window addresses currently
|
||||
* loaded from two different physical devices (Phase 8 v3, 2026-09-23) --
|
||||
* the check MOVE/CMOVE/CMOVE> call before copying to refuse a same-VM,
|
||||
* cross-device raw block copy. See this function's own doc comment in
|
||||
* block_words.c for exactly what is and isn't flagged.
|
||||
* @param vm VM performing the copy
|
||||
* @param addr1 first VM offset (source or destination, order doesn't matter)
|
||||
* @param addr2 second VM offset
|
||||
* @return 1 if this copy should be refused, 0 otherwise
|
||||
*/
|
||||
int blk_vm_is_cross_device_copy(VM *vm, vaddr_t addr1, vaddr_t addr2);
|
||||
|
||||
#endif /* BLOCK_WORDS_H */
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef CONTROL_WORDS_H
|
||||
#define CONTROL_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup control_words FORTH-79 Control Flow Words
|
||||
* @{
|
||||
* @brief Standard FORTH-79 control flow words implementation
|
||||
*
|
||||
* @def IF ( flag -- )
|
||||
* Conditional execution based on flag
|
||||
*
|
||||
* @def THEN ( -- )
|
||||
* End of IF conditional block
|
||||
*
|
||||
* @def ELSE ( -- )
|
||||
* Alternative execution path
|
||||
*
|
||||
* @def BEGIN ( -- )
|
||||
* Start of indefinite loop
|
||||
*
|
||||
* @def UNTIL ( flag -- )
|
||||
* End loop if flag is true
|
||||
*
|
||||
* @def AGAIN ( -- )
|
||||
* End infinite loop
|
||||
*
|
||||
* @def WHILE ( flag -- )
|
||||
* Test condition in BEGIN loop
|
||||
*
|
||||
* @def REPEAT ( -- )
|
||||
* End of WHILE loop
|
||||
*
|
||||
* @def DO ( limit start -- )
|
||||
* Start definite loop
|
||||
*
|
||||
* @def LOOP ( -- )
|
||||
* End DO loop, increment by 1
|
||||
*
|
||||
* @def +LOOP ( n -- )
|
||||
* End DO loop, increment by n
|
||||
*
|
||||
* @def I ( -- n )
|
||||
* Get current loop index
|
||||
*
|
||||
* @def J ( -- n )
|
||||
* Get outer loop index
|
||||
*
|
||||
* @def LEAVE ( -- )
|
||||
* Exit current loop
|
||||
*
|
||||
* @def UNLOOP ( -- )
|
||||
* Discard loop parameters
|
||||
*
|
||||
* @def EXIT ( -- )
|
||||
* Exit current word
|
||||
*
|
||||
* @def ABORT ( -- )
|
||||
* Abort execution
|
||||
*
|
||||
* @def QUIT ( -- )
|
||||
* Return to interpreter
|
||||
*
|
||||
* @def EXECUTE ( xt -- )
|
||||
* Execute word at address
|
||||
*
|
||||
* @def BRANCH ( -- )
|
||||
* Unconditional branch
|
||||
*
|
||||
* @def 0BRANCH ( flag -- )
|
||||
* Branch if flag is zero
|
||||
*
|
||||
* @def (LIT) ( -- n )
|
||||
* Push inline literal
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Registers all control flow words with the Forth virtual machine
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_control_words(VM * vm);
|
||||
|
||||
#endif /* CONTROL_WORDS_H */
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0.
|
||||
*/
|
||||
|
||||
#ifndef DEFER_WORDS_H
|
||||
#define DEFER_WORDS_H
|
||||
|
||||
#include "../../../include/vm.h"
|
||||
|
||||
void register_defer_words(VM *vm);
|
||||
|
||||
#endif /* DEFER_WORDS_H */
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DEFINING_WORDS_H
|
||||
#define DEFINING_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup DefiningWords FORTH-79 Defining Words
|
||||
* @{
|
||||
* @brief Standard FORTH-79 defining words
|
||||
*
|
||||
* @details These words are used for creating new dictionary entries and defining words:
|
||||
* - : ( -- ) Start colon definition
|
||||
* - ; ( -- ) End colon definition
|
||||
* - CREATE ( -- ) Create dictionary entry
|
||||
* - DOES> ( -- ) Define runtime behavior
|
||||
* - <BUILDS ( -- ) Create word with <BUILDS/DOES>
|
||||
* - CONSTANT ( n -- ) Define constant
|
||||
* - VARIABLE ( -- ) Define variable
|
||||
* - 2CONSTANT ( d -- ) Define double constant
|
||||
* - 2VARIABLE ( -- ) Define double variable
|
||||
* - USER ( n -- ) Define user variable
|
||||
* - IMMEDIATE ( -- ) Make most recent word immediate
|
||||
* - [COMPILE] ( -- ) Force compilation of immediate word
|
||||
* - COMPILE ( -- ) Compile inline code
|
||||
* - FORGET ( -- ) Remove word and all after it
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*
|
||||
* @brief Registers all FORTH-79 defining words with the virtual machine
|
||||
* @param vm Pointer to the virtual machine instance
|
||||
*/
|
||||
void register_defining_words(VM * vm);
|
||||
|
||||
#endif /* DEFINING_WORDS_H */
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* dictionary_heat_diagnostic_words.h
|
||||
*
|
||||
* FORTH interface for dictionary heat optimization diagnostics
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_HEAT_DIAGNOSTIC_WORDS_H
|
||||
#define DICTIONARY_HEAT_DIAGNOSTIC_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* Register all dictionary heat diagnostic words with the VM
|
||||
*/
|
||||
void register_dictionary_heat_diagnostic_words(VM *vm);
|
||||
|
||||
#endif /* DICTIONARY_HEAT_DIAGNOSTIC_WORDS_H */
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_MANIPULATION_WORDS_H
|
||||
#define DICTIONARY_MANIPULATION_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup dictionary_words FORTH-79 Dictionary Manipulation Words
|
||||
* @{
|
||||
* @brief Standard FORTH-79 words for dictionary manipulation
|
||||
*
|
||||
* @par [ ( -- )
|
||||
* Enter interpretation mode. Switches the system to interpret incoming words.
|
||||
*
|
||||
* @par ] ( -- )
|
||||
* Enter compilation mode. Switches the system to compile incoming words.
|
||||
*
|
||||
* @par STATE ( -- addr )
|
||||
* Variable containing current compilation state. Returns address of STATE variable.
|
||||
*
|
||||
* @par SMUDGE ( -- )
|
||||
* Toggle smudge bit of latest defined word. Used during word definition.
|
||||
*
|
||||
* @par >BODY ( xt -- addr )
|
||||
* Convert execution token to parameter field address.
|
||||
*
|
||||
* @par >NAME ( xt -- addr )
|
||||
* Convert execution token to name field address.
|
||||
*
|
||||
* @par NAME> ( addr -- xt )
|
||||
* Convert name field address to execution token.
|
||||
*
|
||||
* @par >LINK ( addr -- addr )
|
||||
* Get link field address from name field address.
|
||||
*
|
||||
* @par LINK> ( addr -- addr )
|
||||
* Get next word's address from link field.
|
||||
*
|
||||
* @par CFA ( addr -- xt )
|
||||
* Get code field address from name field address.
|
||||
*
|
||||
* @par LFA ( addr -- addr )
|
||||
* Get link field address from name field address.
|
||||
*
|
||||
* @par NFA ( addr -- addr )
|
||||
* Get name field address from any field address.
|
||||
*
|
||||
* @par PFA ( addr -- addr )
|
||||
* Get parameter field address from name field address.
|
||||
*
|
||||
* @par TRAVERSE ( addr n -- addr )
|
||||
* Move through name field by n characters.
|
||||
*
|
||||
* @par INTERPRET ( -- )
|
||||
* Text interpreter - process input stream.
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Register all dictionary manipulation words with the virtual machine
|
||||
*
|
||||
* @param vm Pointer to the virtual machine instance
|
||||
*
|
||||
* This function registers all FORTH-79 standard dictionary manipulation words
|
||||
* with the provided virtual machine instance. These words are essential for
|
||||
* dictionary management and word definition functionality.
|
||||
*/
|
||||
void register_dictionary_manipulation_words(VM * vm);
|
||||
|
||||
#endif /* DICTIONARY_MANIPULATION_WORDS_H */
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DICTIONARY_WORDS_H
|
||||
#define DICTIONARY_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup dictionary FORTH-79 Dictionary & Compilation Words
|
||||
* @{
|
||||
*
|
||||
* @brief Dictionary and compilation words as defined in FORTH-79 Standard
|
||||
*
|
||||
* @word HERE ( -- addr ) Returns address of next free dictionary space
|
||||
* @word ALLOT ( n -- ) Allocates n bytes in dictionary
|
||||
* @word , ( n -- ) Compiles n into dictionary
|
||||
* @word C, ( c -- ) Compiles character into dictionary
|
||||
* @word 2, ( d -- ) Compiles double into dictionary
|
||||
* @word PAD ( -- addr ) Returns address of temporary text buffer
|
||||
* @word SP! ( addr -- ) Sets data stack pointer
|
||||
* @word SP@ ( -- addr ) Gets data stack pointer
|
||||
* @word LATEST ( -- addr ) Returns address of most recent definition
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Registers all dictionary and compilation words with the Forth VM
|
||||
*
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_dictionary_words(VM * vm);
|
||||
|
||||
#endif /* DICTIONARY_WORDS_H */
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DOUBLE_WORDS_H
|
||||
#define DOUBLE_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/* FORTH-79 Double Number Words:
|
||||
* S>D ( n -- d ) Convert single to double
|
||||
* D+ ( d1 d2 -- d3 ) Add double numbers
|
||||
* D- ( d1 d2 -- d3 ) Subtract double numbers
|
||||
* DNEGATE ( d1 -- d2 ) Negate double number
|
||||
* DABS ( d1 -- d2 ) Absolute value of double
|
||||
* DMAX ( d1 d2 -- d3 ) Maximum of two doubles
|
||||
* DMIN ( d1 d2 -- d3 ) Minimum of two doubles
|
||||
* D< ( d1 d2 -- flag ) Compare doubles: d1 < d2
|
||||
* D= ( d1 d2 -- flag ) Compare doubles: d1 = d2
|
||||
* 2DROP ( d -- ) Drop double from stack
|
||||
* 2DUP ( d -- d d ) Duplicate double
|
||||
* 2SWAP ( d1 d2 -- d2 d1 ) Swap two doubles
|
||||
* 2OVER ( d1 d2 -- d1 d2 d1 ) Copy second double to top
|
||||
* 2ROT ( d1 d2 d3 -- d2 d3 d1 ) Rotate three doubles
|
||||
* 2>R ( d -- ) ( R: -- d ) Move double to return stack
|
||||
* 2R> ( -- d ) ( R: d -- ) Move double from return stack
|
||||
* 2R@ ( -- d ) ( R: d -- d ) Copy double from return stack
|
||||
* D0= ( d -- flag ) Test if double is zero
|
||||
* D0< ( d -- flag ) Test if double is negative
|
||||
* D2* ( d1 -- d2 ) Multiply double by 2
|
||||
* D2/ ( d1 -- d2 ) Divide double by 2
|
||||
*/
|
||||
|
||||
/*
|
||||
* @brief Registers all double precision number manipulation words with the Forth virtual machine
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_double_words(VM * vm);
|
||||
|
||||
#endif /* DOUBLE_WORDS_H */
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef EDITOR_WORDS_H
|
||||
#define EDITOR_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup editor_words FORTH-79 Line Editor Words
|
||||
* @{
|
||||
*
|
||||
* @brief Line editor commands implementation
|
||||
*
|
||||
* @fn void L ( -- )
|
||||
* @brief List current screen
|
||||
*
|
||||
* @fn void T ( n -- )
|
||||
* @brief Type line n of current screen
|
||||
* @param[in] n Line number to type
|
||||
*
|
||||
* @fn void E ( n -- )
|
||||
* @brief Edit line n of current screen
|
||||
* @param[in] n Line number to edit
|
||||
*
|
||||
* @fn void S ( n addr -- )
|
||||
* @brief Replace line n with string at addr
|
||||
* @param[in] n Line number to replace
|
||||
* @param[in] addr Address of replacement string
|
||||
*
|
||||
* @fn void I ( n -- )
|
||||
* @brief Insert before line n
|
||||
* @param[in] n Line number to insert before
|
||||
*
|
||||
* @fn void R ( n -- )
|
||||
* @brief Replace line n
|
||||
* @param[in] n Line number to replace
|
||||
*
|
||||
* @fn void D ( n -- )
|
||||
* @brief Delete line n
|
||||
* @param[in] n Line number to delete
|
||||
*
|
||||
* @fn void P ( n -- )
|
||||
* @brief Position to line n
|
||||
* @param[in] n Line number to position to
|
||||
*
|
||||
* @fn void COPY ( n1 n2 -- )
|
||||
* @brief Copy line n1 to line n2
|
||||
* @param[in] n1 Source line number
|
||||
* @param[in] n2 Destination line number
|
||||
*
|
||||
* @fn void M ( n1 n2 -- )
|
||||
* @brief Move line n1 to line n2
|
||||
* @param[in] n1 Source line number
|
||||
* @param[in] n2 Destination line number
|
||||
*
|
||||
* @fn void TILL ( c -- )
|
||||
* @brief Search for character c
|
||||
* @param[in] c Character to search for
|
||||
*
|
||||
* @fn void N ( -- )
|
||||
* @brief Search for next occurrence
|
||||
*
|
||||
* @fn void WHERE ( -- )
|
||||
* @brief Show current position
|
||||
*
|
||||
* @fn void TOP ( -- )
|
||||
* @brief Go to top of screen
|
||||
*
|
||||
* @fn void BOTTOM ( -- )
|
||||
* @brief Go to bottom of screen
|
||||
*
|
||||
* @fn void CLEAR ( -- )
|
||||
* @brief Clear current screen
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Register all editor words with the Forth virtual machine
|
||||
*
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_editor_words(VM * vm);
|
||||
|
||||
#endif /* EDITOR_WORDS_H */
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FORMAT_WORDS_H
|
||||
#define FORMAT_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/* FORTH-79 Formatting & Conversion Words:
|
||||
* . ( n -- ) Print signed number
|
||||
* .R ( n width -- ) Print signed number right-justified
|
||||
* U. ( u -- ) Print unsigned number
|
||||
* U.R ( u width -- ) Print unsigned number right-justified
|
||||
* D. ( d -- ) Print double number
|
||||
* D.R ( d width -- ) Print double number right-justified
|
||||
* .S ( -- ) Print stack contents
|
||||
* ? ( addr -- ) Print value at address
|
||||
* DUMP ( addr u -- ) Hex dump u bytes from addr
|
||||
* <# ( -- ) Begin numeric conversion
|
||||
* # ( ud1 -- ud2 ) Convert one digit
|
||||
* #> ( ud -- addr u ) End numeric conversion
|
||||
* #S ( ud -- 0 0 ) Convert all remaining digits
|
||||
* HOLD ( c -- ) Insert character in conversion
|
||||
* SIGN ( n -- ) Insert sign if negative
|
||||
* BASE ( -- addr ) Variable containing number base
|
||||
* DECIMAL ( -- ) Set base to 10
|
||||
* HEX ( -- ) Set base to 16
|
||||
* OCTAL ( -- ) Set base to 8
|
||||
*/
|
||||
|
||||
/*
|
||||
* @brief Registers all formatting and conversion words with the Forth virtual machine
|
||||
* @param vm Pointer to the Forth virtual machine instance
|
||||
*/
|
||||
void register_format_words(VM * vm);
|
||||
|
||||
#endif /* FORMAT_WORDS_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0
|
||||
*/
|
||||
|
||||
#ifndef FRAMEBUFFER_WORDS_H
|
||||
#define FRAMEBUFFER_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* @defgroup framebuffer_words Framebuffer Words
|
||||
* @{
|
||||
*
|
||||
* @brief Raw hardware-boundary FORTH words for the Console drawing fabric
|
||||
* (FABRIC-0.md item 4.3.3). Deliberately raster-native -- no Cartesian
|
||||
* awareness, no policy. That lives in capsules/fabric.4th instead, per the
|
||||
* compose-in-FORTH-first rule.
|
||||
*
|
||||
* Kernel-only: no-op on hosted builds (no framebuffer exists there).
|
||||
*
|
||||
* @par PLOT ( x y color -- )
|
||||
* Write one pixel at raster coordinates (top-left origin, Y-down).
|
||||
* Out-of-bounds writes are silently ignored (inherited from fb_put_pixel).
|
||||
*
|
||||
* @par FB-WIDTH ( -- n )
|
||||
* @par FB-HEIGHT ( -- n )
|
||||
* Push the framebuffer's pixel width / height.
|
||||
* @}
|
||||
*/
|
||||
|
||||
void register_framebuffer_words(VM *vm);
|
||||
|
||||
#endif /* FRAMEBUFFER_WORDS_H */
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* inference_words.h — Module 26: SSM inference engine + Jacquard FORTH words
|
||||
*/
|
||||
|
||||
#ifndef INFERENCE_WORDS_H
|
||||
#define INFERENCE_WORDS_H
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/**
|
||||
* Register all inference engine / Jacquard FORTH words with the VM.
|
||||
* Module 26 in register_forth79_words().
|
||||
*/
|
||||
void register_inference_words(VM *vm);
|
||||
|
||||
#endif /* INFERENCE_WORDS_H */
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
StarForth — Steady-State Virtual Machine Runtime
|
||||
Copyright (c) 2023–2025 Robert A. James
|
||||
All rights reserved.
|
||||
|
||||
This file is part of the StarForth project.
|
||||
|
||||
Licensed under the StarForth License, Version 1.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at:
|
||||
https://github.com/star.4th@proton.me/StarForth/LICENSE.txt
|
||||
|
||||
This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
express or implied, including but not limited to the warranties of
|
||||
merchantability, fitness for a particular purpose, and noninfringement.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef IO_WORDS_H //!< Include guard
|
||||
#define IO_WORDS_H //!< Include guard
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
/* FORTH-79 I/O & Terminal Words:
|
||||
* EMIT ( c -- ) Output character c
|
||||
* CR ( -- ) Output carriage return
|
||||
* KEY ( -- c ) Input character from keyboard
|
||||
* ?TERMINAL ( -- flag ) True if key pressed
|
||||
* TYPE ( addr u -- ) Output u characters from addr
|
||||
* SPACE ( -- ) Output one space
|
||||
* SPACES ( n -- ) Output n spaces
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Registers all I/O related FORTH words with the virtual machine
|
||||
* @param vm Pointer to the virtual machine instance
|
||||
*
|
||||
* Registers the following FORTH-79 I/O & Terminal Words:
|
||||
* - EMIT ( c -- ) Output character c
|
||||
* - CR ( -- ) Output carriage return
|
||||
* - KEY ( -- c ) Input character from keyboard
|
||||
* - ?TERMINAL ( -- flag ) True if key pressed
|
||||
* - TYPE ( addr u -- ) Output u characters from addr
|
||||
* - SPACE ( -- ) Output one space
|
||||
* - SPACES ( n -- ) Output n spaces
|
||||
*/
|
||||
void register_io_words(VM * vm);
|
||||
|
||||
#endif /* IO_WORDS_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user