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:
@@ -118,7 +118,8 @@
|
||||
: M+ S>D D+ ;
|
||||
|
||||
\ 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)
|
||||
|
||||
@@ -4264,6 +4264,34 @@ impl ForthVM {
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -4422,6 +4450,8 @@ impl ForthVM {
|
||||
6 => self.interpret_find(),
|
||||
7 => self.interpret_parse(),
|
||||
8 => self.interpret_parse_name(),
|
||||
9 => self.define_2constant(),
|
||||
10 => self.define_2variable(),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user