Charles Childers
Administrator
Sr. Member
    
Karma: +2/-0
Offline
Posts: 745
|
I've made a few significant changes to the internal design of RetroForth over the last few days. Those who follow the blog ("news" link in the header) will already be aware of these, but many will not.
The dictionary header is now:
dd link_to_previous_entry dd address_of_word dd class_of_word db length_of_name db '....name....'
The change here is the addition of dd class_of_word. More on this in a minute.
The second change: As a result of the change to the dictionary format, the separate macro dictionary has been removed.
The third change: All colon definitions are now vectored. (This will mean little to most people, suffice it to say that in 99% of cases no code needs to be altered as a result of this)
The fourth change: the interactive interpreter is now decoupled from the rest of the core. Again, this won't matter to most people, except those writing new ports.
Back to the dictionary changes. Instead of two dictionaries, we now make use of word classes, a concept I first learned of from Helmar. Three classes of words are provided in the basic system:
forth (normal forth words, work as before) macro (compiler macros, work as before) self (new class, always called, never compiled. Can do separate actions for compiling and interpreting by checking the 'state' of the environment)
You can define new classes as well (an 'inline' class follows at the end of this post). Changing the class of an existing word is possible, and supported directly. All in all, it's really a nice set of changes. Much redundancy in the core has been eliminated, and new options for optimization are now possible. If anyone has questions, please ask them here and I'll try to explain things better.
And now for the example of an inline class:
loc: : copy repeat dup c@ dup $c3 =if 2drop ;; then 1, 1+ again ; : inline state @ if copy ;; then execute ; :: ['] inline class ! ; ;loc alias inline
| Now let's make some definitions inline themselves when | used in a definition. | | Definitions that call other words can't be inlined with the | above code.
inline reclass: dup reclass: drop reclass: swap reclass: 1+ reclass: 1- reclass: true reclass: false reclass: @ reclass: ! reclass: w! reclass: c! reclass: - reclass: nip reclass: >> reclass: << forth
|