Shi
Loading...
Searching...
No Matches
Variables

There are a couple of states Shi needs to track internally. When evaluating the total ram usage these variables have to be taken into consideration and added to the user-defined stack size. The table below contains them all including a short description and their size in bytes.

Symbol Description Size [b]
shi_stack_begin Stack begin user-defined + 4
shi_stack_end Stack end
shi_context Context (dsp and lfp) 8
to_text_begin Pointer to current ram begin which is going to end in flash 4
data_begin Pointer to ram begin 4
data_end Pointer to ram end, used for reserving ram for variables 4
text_begin Pointer to flash begin 4
text_end Pointer to flash end 4
csp

Inside loop: points to leave addresses from the current loop on the stack
Inside case: points to endof addresses from the current case on the stack | 4 | | link | Contains address of link of the last definition in ram | 4 | | status | Current state (state is taken as word)
false: interpret, true: compile | 4 | | src | Source (address and length) | 8 | | in | Index in terminal input buffer | 4 | | radix | Determine current numerical base (base is taken as word) | 4 | | text_align | User defined alignment for flash | 1 | | leave_lvl | Current nesting level of do...loop | 1 | | case_lvl | Current nesting level of case...of...endof...endcase | 1 |

Most variables should be more or less evident with some exceptions:

shi_context
Shi maps the top-of-stack, the data-space-pointer and the literal-folding-pointer directly to registers. Those registers must be restored and saved upon entry and exit. The top-of-stack gets pushed or popped to the internal data-stack and the pointers get stored in an own variable called shi_context.

data_begin, data_end, text_begin, text_end
Usually Forth system have a single continuous data-space but Shi supports compilation to two different data-spaces (data and text aka ram and flash). The variables data_begin, data_end, text_begin and text_end keep track of the addresses of the data-spaces passed in by the user at initialization. Writing to data or text advances those data-space pointers.

to_text_begin
Shi does not write directly to flash but first stores new definitions in ram before a special word calls an extern function which then takes care of copying the definitions over. to_text_begin marks the beginning of the memory which should be written into flash.

text_align
Most flash memories have alignment restrictions and can only write to 4-, 8- or even 16-byte aligned addresses. This alignment requirements are stored as power of 2 in text_align and can be set by the user at initialization.

leave_lvl, case_lvl
The control-flow words endof and leave can nest an arbitrary number of times and even mix with other control-flow words. To allow that Shi has to internally track the current nesting level of loop- and case-sys.