Remove unused stub files: forth/, words/, compiler.rs, primitives.rs, types.rs
All were planning artifacts never imported or loaded: - forth/ (4 .fth files): commented-out TODO stubs, never loaded at startup - crates/core/src/words/mod.rs: empty module with commented-out submodules - compiler.rs: placeholder, all compiler logic lives in outer.rs - primitives.rs: placeholder, all primitives registered in outer.rs - types.rs: StackType/StackEffect defined but never imported anywhere
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
//! Forth compile mode: builds IR from word definitions.
|
||||
//!
|
||||
//! When the outer interpreter encounters `:`, it switches to compile mode.
|
||||
//! The compiler collects tokens and builds an IR representation until `;`.
|
||||
//! IMMEDIATE words are executed during compilation (e.g., IF, ELSE, THEN).
|
||||
|
||||
// TODO: Step 7 - Compiler implementation
|
||||
// - : (colon) starts compilation, ; (semicolon) ends it
|
||||
// - Build Vec<IrOp> for the word body
|
||||
// - Handle IMMEDIATE words
|
||||
// - Handle control structures (IF/ELSE/THEN, DO/LOOP, BEGIN/UNTIL)
|
||||
// - LITERAL, POSTPONE, ['], [CHAR]
|
||||
// - Defining words: VARIABLE, CONSTANT, CREATE, DOES>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn placeholder() {
|
||||
// Compiler tests will be added in Step 7
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,10 @@
|
||||
//!
|
||||
//! The compilation pipeline:
|
||||
//! 1. **Outer interpreter** tokenizes input and dispatches to interpret/compile mode
|
||||
//! 2. **Compiler** builds an intermediate representation (IR) for each word definition
|
||||
//! 3. **Type inference** annotates the IR with stack types
|
||||
//! 4. **Optimizer** applies transformation passes (constant folding, inlining, etc.)
|
||||
//! 5. **Codegen** translates optimized IR to WASM bytecode via `wasm-encoder`
|
||||
//! 2. **Optimizer** applies transformation passes (constant folding, inlining, etc.)
|
||||
//! 3. **Codegen** translates optimized IR to WASM bytecode via `wasm-encoder`
|
||||
|
||||
pub mod codegen;
|
||||
pub mod compiler;
|
||||
pub mod config;
|
||||
pub mod consolidate;
|
||||
pub mod dictionary;
|
||||
@@ -26,6 +23,3 @@ pub mod ir;
|
||||
pub mod memory;
|
||||
pub mod optimizer;
|
||||
pub mod outer;
|
||||
pub mod primitives;
|
||||
pub mod types;
|
||||
pub mod words;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
//! Built-in primitive words for WAFER.
|
||||
//!
|
||||
//! Primitives are the ~35 words that must be implemented in Rust because
|
||||
//! they require direct WASM instructions or host interaction.
|
||||
//! Everything else is defined in Forth (loaded from .fth files).
|
||||
|
||||
// TODO: Step 6 - Primitive word implementations
|
||||
// Each primitive provides:
|
||||
// - Its StackEffect (type signature)
|
||||
// - Its IR representation (for inlining by the optimizer)
|
||||
// - Direct WASM instruction generation
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn placeholder() {
|
||||
// Primitive tests will be added in Step 6
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
//! Type inference engine for WAFER's multi-typed stack.
|
||||
//!
|
||||
//! WAFER uses type inference to determine when values on the stack have
|
||||
//! statically known types. When types are known, codegen uses WASM's native
|
||||
//! typed operand stack and locals instead of simulating stacks in linear memory.
|
||||
|
||||
/// Types that can appear on WAFER's stack.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum StackType {
|
||||
/// 32-bit integer (default Forth cell).
|
||||
I32,
|
||||
/// 64-bit integer (double-cell).
|
||||
I64,
|
||||
/// 32-bit float.
|
||||
F32,
|
||||
/// 64-bit float (Forth floating-point).
|
||||
F64,
|
||||
/// Boolean (result of comparisons). Represented as i32 at WASM level.
|
||||
Bool,
|
||||
/// Memory address. Represented as i32 at WASM level.
|
||||
Addr,
|
||||
/// Type is unknown or cannot be determined statically.
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl StackType {
|
||||
/// Returns the WASM value type for this stack type.
|
||||
pub fn wasm_type(self) -> wasm_encoder::ValType {
|
||||
match self {
|
||||
StackType::I32 | StackType::Bool | StackType::Addr => wasm_encoder::ValType::I32,
|
||||
StackType::I64 => wasm_encoder::ValType::I64,
|
||||
StackType::F32 => wasm_encoder::ValType::F32,
|
||||
StackType::F64 => wasm_encoder::ValType::F64,
|
||||
StackType::Unknown => wasm_encoder::ValType::I32, // default to i32
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this type's WASM representation is i32.
|
||||
pub fn is_i32_compatible(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
StackType::I32 | StackType::Bool | StackType::Addr | StackType::Unknown
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the stack effect of a Forth word.
|
||||
///
|
||||
/// For example, `+` has effect `( I32 I32 -- I32 )`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct StackEffect {
|
||||
/// Types consumed from the stack (bottom to top).
|
||||
pub inputs: Vec<StackType>,
|
||||
/// Types produced on the stack (bottom to top).
|
||||
pub outputs: Vec<StackType>,
|
||||
}
|
||||
|
||||
impl StackEffect {
|
||||
/// Create a new stack effect.
|
||||
pub fn new(inputs: Vec<StackType>, outputs: Vec<StackType>) -> Self {
|
||||
Self { inputs, outputs }
|
||||
}
|
||||
|
||||
/// Number of items consumed.
|
||||
pub fn input_count(&self) -> usize {
|
||||
self.inputs.len()
|
||||
}
|
||||
|
||||
/// Number of items produced.
|
||||
pub fn output_count(&self) -> usize {
|
||||
self.outputs.len()
|
||||
}
|
||||
|
||||
/// Net stack depth change.
|
||||
pub fn depth_change(&self) -> i32 {
|
||||
self.outputs.len() as i32 - self.inputs.len() as i32
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn stack_type_wasm_mapping() {
|
||||
assert_eq!(StackType::I32.wasm_type(), wasm_encoder::ValType::I32);
|
||||
assert_eq!(StackType::F64.wasm_type(), wasm_encoder::ValType::F64);
|
||||
assert_eq!(StackType::Bool.wasm_type(), wasm_encoder::ValType::I32);
|
||||
assert_eq!(StackType::Addr.wasm_type(), wasm_encoder::ValType::I32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stack_effect_depth() {
|
||||
// DUP ( x -- x x )
|
||||
let dup = StackEffect::new(vec![StackType::I32], vec![StackType::I32, StackType::I32]);
|
||||
assert_eq!(dup.depth_change(), 1);
|
||||
|
||||
// + ( x y -- z )
|
||||
let add = StackEffect::new(vec![StackType::I32, StackType::I32], vec![StackType::I32]);
|
||||
assert_eq!(add.depth_change(), -1);
|
||||
|
||||
// DROP ( x -- )
|
||||
let drop_e = StackEffect::new(vec![StackType::I32], vec![]);
|
||||
assert_eq!(drop_e.depth_change(), -1);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//! Forth 2012 word set implementations.
|
||||
//!
|
||||
//! Each submodule implements one word set from the Forth 2012 standard.
|
||||
//! Words are implemented in Rust only when they require direct WASM instructions;
|
||||
//! most words are defined in Forth source files under `forth/`.
|
||||
|
||||
// Word set modules will be added as each set is implemented:
|
||||
// pub mod core;
|
||||
// pub mod core_ext;
|
||||
// pub mod double;
|
||||
// pub mod exception;
|
||||
// pub mod floating;
|
||||
// pub mod locals;
|
||||
// pub mod string;
|
||||
// pub mod tools;
|
||||
// pub mod memory_alloc;
|
||||
// pub mod search_order;
|
||||
// pub mod file;
|
||||
// pub mod facility;
|
||||
Reference in New Issue
Block a user