Implement complete Floating-Point word set, 70+ float words

Separate float stack with fsp global, IEEE 754 double precision.
Stack ops: FDROP FDUP FSWAP FOVER FROT FDEPTH
Arithmetic: F+ F- F* F/ FNEGATE FABS FMAX FMIN FSQRT FLOOR FROUND F**
Comparisons: F0= F0< F= F< F~
Memory: F@ F! SF@ SF! DF@ DF! FLOAT+ FLOATS FALIGNED FALIGN
Conversions: D>F F>D S>F F>S
Trig: FSIN FCOS FTAN FASIN FACOS FATAN FATAN2 FSINCOS
Exp/Log: FEXP FEXPM1 FLN FLNP1 FLOG FALOG
Hyperbolic: FSINH FCOSH FTANH FASINH FACOSH FATANH
I/O: F. FE. FS. REPRESENT >FLOAT PRECISION SET-PRECISION
Defining: FVARIABLE FCONSTANT FVALUE FLITERAL
Float literal parsing (1E, 1.5E2, -3.14E0 format)
299 unit tests + 11 compliance tests, 0 errors on float test suite
This commit is contained in:
2026-04-01 20:38:48 +02:00
parent 3e7f92b7ef
commit eb79c40c69
4 changed files with 2870 additions and 20 deletions
+22 -1
View File
@@ -29,6 +29,10 @@ const DSP: u32 = 0;
/// Index of the `$rsp` global (return stack pointer).
const RSP: u32 = 1;
/// Index of the `$fsp` global (float stack pointer).
#[allow(dead_code)]
const FSP: u32 = 2;
/// Index of the imported function table.
const TABLE: u32 = 0;
@@ -795,6 +799,15 @@ pub fn compile_word(
shared: false,
}),
);
imports.import(
"env",
"fsp",
EntityType::Global(GlobalType {
val_type: ValType::I32,
mutable: true,
shared: false,
}),
);
imports.import(
"env",
"table",
@@ -871,7 +884,7 @@ mod tests {
use super::*;
use crate::dictionary::WordId;
use crate::ir::IrOp;
use crate::memory::{DATA_STACK_TOP, RETURN_STACK_TOP};
use crate::memory::{DATA_STACK_TOP, FLOAT_STACK_TOP, RETURN_STACK_TOP};
fn default_config() -> CodegenConfig {
CodegenConfig {
@@ -1133,6 +1146,13 @@ mod tests {
)
.unwrap();
let fsp = Global::new(
&mut store,
wasmtime::GlobalType::new(ValType::I32, Mutability::Var),
Val::I32(FLOAT_STACK_TOP as i32),
)
.unwrap();
let table = Table::new(
&mut store,
wasmtime::TableType::new(RefType::FUNCREF, 16, None),
@@ -1152,6 +1172,7 @@ mod tests {
memory.into(),
dsp.into(),
rsp.into(),
fsp.into(),
table.into(),
],
)
+6
View File
@@ -111,6 +111,12 @@ impl Dictionary {
Ok(WordId(fn_index))
}
/// Reserve a function index without creating a dictionary entry.
/// Used for anonymous host functions (e.g., float literals during compilation).
pub fn reserve_fn_index(&mut self) {
self.next_fn_index += 1;
}
/// Reveal the most recent word (remove HIDDEN flag).
/// Called after `: ... ;` completes compilation.
pub fn reveal(&mut self) {
+1952 -19
View File
File diff suppressed because it is too large Load Diff