en:pfw:base-ffbase
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:pfw:base-ffbase [2023-09-04 18:11] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | en:pfw:base-ffbase [2024-10-20 23:31] (current) – Ausdruck etwas klarer hier und da. mka | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{pfw: | ||
+ | ====== BASE change temporarily -- FFBASE ====== | ||
+ | |||
+ | ===== The idea ===== | ||
+ | |||
+ | Quite often a programmer needs to switch the numerical base for just a word or a number. In the worst case this involves saving the old BASE, setting BASE to the wanted value and then restoring the old BASE. A lot of code for just one word/ | ||
+ | |||
+ | The routine FFBASE enables the creation of precursor words which, just for the next definition or number, temporarily set the base to another. | ||
+ | |||
+ | So, for instance: | ||
+ | |||
+ | <code forth> | ||
+ | 16 FFBASE HX | ||
+ | </ | ||
+ | |||
+ | Creates a word, called '' | ||
+ | |||
+ | The name '' | ||
+ | |||
+ | It should be mentioned that in this phrase '' | ||
+ | |||
+ | ===== Pseudo code ===== | ||
+ | |||
+ | < | ||
+ | Function: (BASE) ( XT temporary_base -- ) | ||
+ | execute an XT using a temporary base - used by FFBASE | ||
+ | | ||
+ | Function: FFBASE | ||
+ | CREATE: ( base ccc -- ) create a precursor word ' | ||
+ | DOES>: ( ccc -- ) | ||
+ | {get base from definition} | ||
+ | {find ccc in dictionary} | ||
+ | {get state} | ||
+ | IF compiling and ccc=not_immediate | ||
+ | {compile XT and temp_base as literals and postpone (BASE) | ||
+ | IF interpreting or ccc=immediate | ||
+ | {call (BASE) with XT and temp_base on stack} | ||
+ | IF not found in dictionary | ||
+ | {convert to number using temp_base and put on stack} | ||
+ | </ | ||
+ | |||
+ | ===== Generic Forth ===== | ||
+ | |||
+ | Definitions assumed to be available in your Forth: '' | ||
+ | |||
+ | === Generic Forth implementation === | ||
+ | |||
+ | See separate file: [[https:// | ||
+ | |||
+ | ===== Implementations ===== | ||
+ | |||
+ | The generic Forth version should run on the majority of Forth implementations. It is successfully tested on iForth and wabiForth. However in the present form it does not run on MeCrisp for reasons unknown to me. | ||
+ | |||
+ | ==== Contributions ==== | ||
+ | |||
+ | < | ||
+ | |||