An ultra-lightweight, zero-dependency, Turing-complete Forth Development Environment and virtual machine engine written in pure vanilla JavaScript. This platform emulates low-level hardware interactions, physical linear memory routing, and hardware I/O interrupts.
To demonstrate absolute Turing-completeness, a complete bare-metal Snake Game was developed entirely within the system's raw Forth dialect, обсчитывая физику векторов и сдвиг массивов исключительно через манипуляции с ячейками памяти.
In modern high-level engineering education, students often lose touch with bare-metal computation constraints. This platform serves as a powerful conceptual bridge between modern web engineering and low-level computer architecture classes (such as MIT 6.004 / Stanford CS107).
By restricting students to programming strictly in the native Forth environment—without touching the underlying JavaScript engine—the system delivers critical educational value:
- Destroys High-Level Laziness: Strips away variables, objects, and garbage-collected abstractions. Students must track memory addresses and manage scope manually using the data stack.
- Embedded Systems Emulation: Mentally clones the constraints of microcontrollers and real-time kernels where storage is measured in bytes and parameters are piped directly through processor registers.
- Algorithmic Discipline: Writing complex code on top of a naked stack structure forces students to produce highly optimized, concise loops. Spaghetti routines simply fail to compile.
💻 System Architecture & Low-Level Specifications
The runtime emulates a hardware processing unit with a dedicated execution loop and two isolated data structures:
- Data Stack (Parameter Stack): Handles all active calculation contexts, logic comparisons, and function parameters using Reverse Polish Notation (RPN / Postfix). Operates strictly on a Last-In, First-Out (LIFO) model.
- Return Stack (Control Stack): Completely isolated from arithmetic words. It holds subroutine callback pointers and tracks execution contexts during definite nesting loops.
Instead of relying on JavaScript objects, the engine instantiates an internal raw array buffer (Uint32Array(8192)). Addresses are mapped directly to physical integer coordinates:
0x0000 - 0x03E7(Addresses 0 - 999): High-performance Framebuffer (160x120 monochromatic/color map layout).0x03E8 - 0x07CF(Addresses 1000 - 1999): Dynamic Game State & Hardware Registers (Head X/Y, Direction, Delays).0x07D0 - 0x0FFF(Addresses 2000 - 4095): Cyclical Array Vectors Buffer (Tail coordinates management array).
The JavaScript loop hooks window event listeners to trap keyboard interrupts. When a key is targeted, it populates a virtual hardware buffer register. Forth utilizes polling words (key? and key) to extract, process, and immediately flush the input stream without blocking execution blocks.
📋 Core Instruction Set & Stack Notation Dictionary
All operations within the engine are documented below. Stack notation diagrams follow the standard Forth convention: ( input_elements -- output_elements ), where the rightmost item represents the top of the stack (TOS).
| Category | Word | Stack Diagram | Operational Description |
|---|---|---|---|
| Stack Ops | dup |
( n -- n n ) |
Duplicates the top element of the active data stack. |
| Stack Ops | drop |
( n -- ) |
Discards the top element from the stack. |
| Stack Ops | swap |
( n1 n2 -- n2 n1 ) |
Reverses the positions of the top two data stack elements. |
| Stack Ops | over |
( n1 n2 -- n1 n2 n1 ) |
Copies the second stack element onto the top of the stack. |
| Math | +, -, *, / |
( n1 n2 -- res ) |
Executes binary arithmetic on signed 32-bit integers. Div by zero drops an execution halt block. |
| Math | mod |
( n1 n2 -- rem ) |
Returns the remainder of integer division (modulo arithmetic). |
| Logic Ops | <, >, = |
( n1 n2 -- flag ) |
Evaluates logic. Pushes -1 (True in Forth) if comparison is valid, or 0 (False). |
| Memory I/O | @ (fetch) |
( addr -- val ) |
Pointer dereference. Reads a 32-bit value directly from the specified index in linear memory array. |
| Memory I/O | ! (store) |
( val addr -- ) |
Writes a 32-bit integer literal value into the specified index destination inside linear memory. |
| Hardware I/O | key? |
( -- flag ) |
Asynchronous pipeline query. Returns -1 if a hardware keyboard key is actively held down, else 0. |
| Hardware I/O | key |
( -- char ) |
Extracts the virtual keycode from the hardware latch buffer, pushes it to stack, and instantly flushes buffer. |
| Flow Control | if..else..then |
( flag -- ) |
Conditional branching statement block. Executes internal block if flag != 0. then marks end of construct. |
| Flow Control | do ... loop |
( limit init -- ) |
Definite loop. Pushes counter states onto return stack and loops from init up to limit boundary index. |
| Flow Control | i, j |
( -- index ) |
Runtime loop counters extraction. i pulls current inner loop iteration index. j pulls the outer loop index. |
| Graphics | plot |
( x y color -- ) |
Hardware graphic bridge. Writes target color directly to (x, y) coordinates into frame display layout. |
| Graphics | cls |
( -- ) |
Wipes frame canvas buffer array back to default dark opaque processing space. |
| System | exit |
( -- ) |
Forces instantaneous crash termination out of the current nested token subroutine subroutine loop. |
🎓 Academic Laboratory Coursework Syllabus (MIT / Stanford Architecture Spec)
This curriculum is designed to teach low-level algorithmic engineering, pointer routing, and memory optimization constraints strictly inside the ST3PH-FORTH execution environment. Students are forbidden from modifying the underlying JavaScript driver engine.
Laboratory Assignment 1: Stack Manipulation Mechanics & Integer Physics
- Objective: Mastery of Reverse Polish Notation (RPN), stack tracking, and data overflow boundaries.
-
Task Description: Build a custom word
quadratic ( a b c x -- result )that solves the polynomial equation$f(x) = ax^2 + bx + c$ using only pure stack primitives (dup,swap,over,drop) without storing values in variables or memory slots. - Evaluation Criteria: Minimum number of data mutations. The stack must be completely clean upon subroutine exit except for the final integer output.
Laboratory Assignment 2: Linear Memory Address Pointer Routing & Buffer Controls
- Objective: Comprehensive understanding of hardware multi-address arrays, vector allocations, and basic memory safety rules.
-
Task Description: Write a program that treats linear memory slots from address
4000to4020as a continuous vector data bank. Develop a routine that finds the largest signed integer inside this micro-allocated section and pushes its address index onto the parameter stack. - Evaluation Criteria: Proper array edge collision processing. The routine must not leak reads or corrupt data boundaries inside peripheral display blocks.
Laboratory Assignment 3: Direct Asynchronous Video Framebuffer Pipeline Generation
- Objective: Practical understanding of real-time polling loops, hardware interrupt processing, and geometric coordinates rendering.
-
Task Description: Implement a high-performance custom graphic screensaver or complex interactive display block. Students must use definite
do ... loopprimitives to render a beautiful checkerboard pattern or procedural sine wave approximation on the active 160x120 screen grid layout. - Evaluation Criteria: Efficiency of the internal execution loop. The Forth code must run smoothly inside the rendering cycle without choking the browser frame processing budget.
Developed by Stephaniia Bubnova 2026. This project is officially distributed and licensed under the conditions of the open-source MIT License. For deep structural alignment details, review the repository LICENSE mapping manifest.