Initial commit: WAFER (WebAssembly Forth Engine in Rust)
Optimizing Forth 2012 compiler targeting WebAssembly with IR-based compilation pipeline, multi-typed stack inference, subroutine threading, and JIT/consolidation modes. Rust kernel with ~35 primitives and Forth standard library for core/core-ext word sets.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
\ WAFER Boot - Minimal bootstrap loaded first after primitives
|
||||
\ This file defines the most fundamental derived words needed
|
||||
\ before the rest of the standard library can load.
|
||||
|
||||
\ These words are defined in terms of the ~35 Rust primitives.
|
||||
\ They form the foundation for core.fth and all subsequent files.
|
||||
|
||||
\ TODO: Step 7/8 - Populate with bootstrap definitions once
|
||||
\ the compiler and outer interpreter are working.
|
||||
\ For now this file documents what will go here:
|
||||
|
||||
\ Derived stack operations:
|
||||
\ : NIP ( x1 x2 -- x2 ) SWAP DROP ;
|
||||
\ : TUCK ( x1 x2 -- x2 x1 x2 ) SWAP OVER ;
|
||||
\ : 2DUP ( x1 x2 -- x1 x2 x1 x2 ) OVER OVER ;
|
||||
\ : 2DROP ( x1 x2 -- ) DROP DROP ;
|
||||
\ : ?DUP ( x -- 0 | x x ) DUP IF DUP THEN ;
|
||||
|
||||
\ Basic arithmetic derived from primitives:
|
||||
\ : 1+ ( n -- n+1 ) 1 + ;
|
||||
\ : 1- ( n -- n-1 ) 1 - ;
|
||||
\ : NEGATE ( n -- -n ) 0 SWAP - ;
|
||||
\ : ABS ( n -- |n| ) DUP 0< IF NEGATE THEN ;
|
||||
@@ -0,0 +1,48 @@
|
||||
\ WAFER Core Word Set - High-level words defined in Forth
|
||||
\ These implement Forth 2012 Core words that can be expressed
|
||||
\ in terms of primitives and boot words.
|
||||
|
||||
\ TODO: Step 10 - Populate as Core compliance tests are run.
|
||||
\ Each word here will be tested against forth2012-test-suite/src/core.fr
|
||||
|
||||
\ -- Derived stack operations --
|
||||
\ : NIP ( x1 x2 -- x2 ) SWAP DROP ;
|
||||
\ : TUCK ( x1 x2 -- x2 x1 x2 ) SWAP OVER ;
|
||||
\ : 2DUP ( x1 x2 -- x1 x2 x1 x2 ) OVER OVER ;
|
||||
\ : 2DROP ( x1 x2 -- ) DROP DROP ;
|
||||
\ : 2SWAP ( x1 x2 x3 x4 -- x3 x4 x1 x2 ) ROT >R ROT R> ;
|
||||
\ : 2OVER ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 ) >R >R 2DUP R> R> 2SWAP ;
|
||||
|
||||
\ -- Arithmetic --
|
||||
\ : 1+ 1 + ;
|
||||
\ : 1- 1 - ;
|
||||
\ : 2* 1 LSHIFT ;
|
||||
\ : 2/ 1 RSHIFT ;
|
||||
\ : NEGATE 0 SWAP - ;
|
||||
\ : ABS DUP 0< IF NEGATE THEN ;
|
||||
\ : MIN 2DUP > IF SWAP THEN DROP ;
|
||||
\ : MAX 2DUP < IF SWAP THEN DROP ;
|
||||
\ : MOD /MOD DROP ;
|
||||
\ : / /MOD NIP ;
|
||||
|
||||
\ -- Comparison --
|
||||
\ : 0= 0 = ;
|
||||
\ : 0<> 0= 0= ;
|
||||
\ : 0< 0 < ;
|
||||
\ : 0> 0 SWAP < ;
|
||||
\ : <> = 0= ;
|
||||
|
||||
\ -- Memory --
|
||||
\ : +! DUP @ ROT + SWAP ! ;
|
||||
\ : CELLS 4 * ;
|
||||
\ : CELL+ 4 + ;
|
||||
\ : CHARS ;
|
||||
\ : CHAR+ 1+ ;
|
||||
|
||||
\ -- Defining words --
|
||||
\ : VARIABLE CREATE 0 , ;
|
||||
\ : CONSTANT CREATE , DOES> @ ;
|
||||
|
||||
\ -- I/O --
|
||||
\ : SPACE BL EMIT ;
|
||||
\ : SPACES 0 ?DO SPACE LOOP ;
|
||||
@@ -0,0 +1,11 @@
|
||||
\ WAFER Core Extensions Word Set
|
||||
\ Forth 2012 Section 6.2
|
||||
|
||||
\ TODO: Step 13 - Implement as compliance tests are enabled
|
||||
\ : VALUE CREATE , DOES> @ ;
|
||||
\ : TO ' >BODY ! ;
|
||||
\ : DEFER CREATE ['] ABORT , DOES> @ EXECUTE ;
|
||||
\ : DEFER! >BODY ! ;
|
||||
\ : DEFER@ >BODY @ ;
|
||||
\ : IS STATE @ IF POSTPONE ['] POSTPONE DEFER! ELSE ' DEFER! THEN ; IMMEDIATE
|
||||
\ : ACTION-OF STATE @ IF POSTPONE ['] POSTPONE DEFER@ ELSE ' DEFER@ THEN ; IMMEDIATE
|
||||
@@ -0,0 +1,8 @@
|
||||
\ WAFER Prelude - Master loader for the standard library
|
||||
\ This file is loaded at boot after primitives are registered.
|
||||
\ It includes all word set files in dependency order.
|
||||
|
||||
\ TODO: Enable includes as each word set is implemented
|
||||
\ INCLUDE boot.fth
|
||||
\ INCLUDE core.fth
|
||||
\ INCLUDE core_ext.fth
|
||||
Reference in New Issue
Block a user