feat(boot): add -ROT <= >= gforth extensions
CI / check (push) Has been cancelled

Non-standard but ubiquitous words; absence aborted otherwise-valid
gforth programs with unknown-word errors.
This commit is contained in:
Oleksandr Kozachuk
2026-07-18 15:40:39 +02:00
parent d5acdc0e7b
commit 35b78193fd
2 changed files with 33 additions and 0 deletions
+13
View File
@@ -72,6 +72,19 @@
1- 1-
REPEAT ; REPEAT ;
\ ---------------------------------------------------------------
\ Common extensions (not in Forth 2012, gforth-compatible)
\ ---------------------------------------------------------------
\ -ROT ( x1 x2 x3 -- x3 x1 x2 ) rotate top item to third place
: -ROT ROT ROT ;
\ <= ( n1 n2 -- flag ) true if n1 <= n2 (signed)
: <= > 0= ;
\ >= ( n1 n2 -- flag ) true if n1 >= n2 (signed)
: >= < 0= ;
\ --------------------------------------------------------------- \ ---------------------------------------------------------------
\ Phase 2: Double-cell arithmetic \ Phase 2: Double-cell arithmetic
\ --------------------------------------------------------------- \ ---------------------------------------------------------------
+20
View File
@@ -7462,6 +7462,12 @@ mod tests {
assert_eq!(eval_stack("1 2 3 ROT"), vec![1, 3, 2]); assert_eq!(eval_stack("1 2 3 ROT"), vec![1, 3, 2]);
} }
#[test]
fn test_minus_rot() {
// ( 1 2 3 -- 3 1 2 ) top-first: [2, 1, 3]
assert_eq!(eval_stack("1 2 3 -ROT"), vec![2, 1, 3]);
}
// -- Comparison -- // -- Comparison --
#[test] #[test]
@@ -7482,6 +7488,20 @@ mod tests {
assert_eq!(eval_stack("3 5 >"), vec![0]); assert_eq!(eval_stack("3 5 >"), vec![0]);
} }
#[test]
fn test_less_or_equal() {
assert_eq!(eval_stack("3 5 <="), vec![-1]);
assert_eq!(eval_stack("5 5 <="), vec![-1]);
assert_eq!(eval_stack("5 3 <="), vec![0]);
}
#[test]
fn test_greater_or_equal() {
assert_eq!(eval_stack("5 3 >="), vec![-1]);
assert_eq!(eval_stack("5 5 >="), vec![-1]);
assert_eq!(eval_stack("3 5 >="), vec![0]);
}
// -- Logic -- // -- Logic --
#[test] #[test]