Fix DU<, register 2VARIABLE/2CONSTANT callable — double 27→3

- DU< had same comparison order bug as D< (comparing d2-hi < d1-hi
  instead of d1-hi < d2-hi). Fixed with SWAP U<.
- 2VARIABLE and 2CONSTANT were handled as special tokens but not
  registered in the dictionary, so they couldn't be called from
  compiled code (e.g., : CD4 2VARIABLE ;). Added pending codes 9/10.
This commit is contained in:
2026-04-08 11:03:14 +02:00
parent 7ec1d3692f
commit 41df5f90d0
2 changed files with 32 additions and 1 deletions
+2 -1
View File
@@ -118,7 +118,8 @@
: M+ S>D D+ ; : M+ S>D D+ ;
\ DU< ( ud1 ud2 -- flag ) unsigned double-cell less-than \ DU< ( ud1 ud2 -- flag ) unsigned double-cell less-than
: DU< ROT 2DUP = IF 2DROP U< ELSE U< NIP NIP THEN ; \ Compare high cells (unsigned); if equal, compare low cells unsigned.
: DU< ROT 2DUP = IF 2DROP U< ELSE SWAP U< NIP NIP THEN ;
\ --------------------------------------------------------------- \ ---------------------------------------------------------------
\ Phase 3: Mixed arithmetic (built on M* and UM/MOD host primitives) \ Phase 3: Mixed arithmetic (built on M* and UM/MOD host primitives)
+30
View File
@@ -4264,6 +4264,34 @@ impl ForthVM {
self.register_host_primitive("CREATE", false, func)?; self.register_host_primitive("CREATE", false, func)?;
} }
// 2CONSTANT: sets pending_define to 9
{
let pending = Arc::clone(&self.pending_define);
let func = Func::new(
&mut self.store,
FuncType::new(&self.engine, [], []),
move |_caller, _params, _results| {
*pending.lock().unwrap() = 9;
Ok(())
},
);
self.register_host_primitive("2CONSTANT", false, func)?;
}
// 2VARIABLE: sets pending_define to 10
{
let pending = Arc::clone(&self.pending_define);
let func = Func::new(
&mut self.store,
FuncType::new(&self.engine, [], []),
move |_caller, _params, _results| {
*pending.lock().unwrap() = 10;
Ok(())
},
);
self.register_host_primitive("2VARIABLE", false, func)?;
}
Ok(()) Ok(())
} }
@@ -4422,6 +4450,8 @@ impl ForthVM {
6 => self.interpret_find(), 6 => self.interpret_find(),
7 => self.interpret_parse(), 7 => self.interpret_parse(),
8 => self.interpret_parse_name(), 8 => self.interpret_parse_name(),
9 => self.define_2constant(),
10 => self.define_2variable(),
_ => Ok(()), _ => Ok(()),
} }
} }