Shi
Loading...
Searching...
No Matches
Extensions

Shi adds a couple of non-ANS words to Forth.

h!
Like ! but stores a halfword (16bit value).

"42 var h!"_s;

h@
Like @ but fetches a halfword (16bit value).

"var h@"_s;

inline
Make the most recent definition an inline word.

": add + ; inline"_s;

>text?, >data?
text? and data? can be used to check if Shi is currently compiling to ram or flash memory.

"data?"_s; // ( -- true | false )
"text?"_s; // ( -- true | false )

>text, >data
By default (and after initialization) Shi compiles to ram (data). It is possible to compile definitions to flash (text) by wrapping them in a >text ... >data block.

// All following definitions get compiled to text
">text"_s;
": six 6 ;"_s;
": seven six 1+ ;"_s;
">data"_s;

The actual flash write takes place once the block ends with >data. Until then everything between >text and >data is stored in data. Implementing the flash write is the users responsibility. Shi anticipates a callback with the symbol shi_write_text which takes 3 arguments:

  1. Begin of block to write
  2. End of block to write
  3. Begin of text area to write to

A reference implementation for the STM32 F4-Discovery board can be found in the ./src/test folder. After the call to shi_write_text data gets cleared till the beginning of the current block.

Warning
Make sure you passed the right text-alignment during initialization. E.g., flash memory on the STM32 F4-Discovery board can only be written in double-words, so the init call must adjust .text_p2align like this:
shi::init({.data_begin = (uint32_t)(begin(data)),
.data_end = (uint32_t)(end(data)),
.text_begin = FLASH_END - 32 * 1024,
.text_end = FLASH_END,
.text_p2align = 3});
void init(Init s)
Definition shi.hpp:708