aw / fiveforths

32-bit RISC-V Forth for microcontrollers
https://fiveforths.a1w.ca
MIT License
66 stars 3 forks source link

Allow numbers to be added to word definitions #5

Closed aw closed 1 year ago

aw commented 1 year ago

Numbers are added to the stack by the outer interpreter, and they can be used just fine in execute mode, but this doesn't get reflected in a colon definition. A word such as LIT (literal handler) is probably needed to force the interpreter to add the stack number to memory when it sees the lit word.. or something like that. It might need to be immediate as well.

aw commented 1 year ago

With this change, it is now possible to define words such as:

: add5 ( x -- n ) 5 + ; \ add 5 to the current stack number
5 add5   ok

The top of the stack would then contain the number 10.