Compiler macros are often used to lay down code in the calling word. You'll see something like:
: foo ['] + compile ['] . compile ; immediate
This is fine, but sometimes you need to deal with other macros:
here ] dup 9 =if drop 32 ;; then dup 10 =if drop 32 ;; then dup 13 =if drop 32 then ; is (remap-keys) | |
here ] is ok | |
here ] clear ; is boot | |
\ some evil code from crc (ala retro-forth) | |
\ ------------------------------------------------------------------------ | |
\ : skip-colon-start | |
\ r> 9 + >r ; | |
\ | |
\ : :: | |
\ compile skip-colon-start | |
\ [compile] [ reveal | |
\ head, ,call nest ] ; immediate |
on run | |
set info to "Nothing Playing!" | |
tell application "System Events" | |
set num to count (every process whose name is "PandoraBoy") | |
end tell | |
if num > 0 then | |
tell application "PandoraBoy" | |
if player state is playing then | |
set who to artist of current track | |
set what to name of current track |
Original from docl: | |
: :: here ] ; | |
: nv-key ['] key 2 + compile ; immediate ( unvectored key ) | |
:: nv-key dup 27 =if nv-key dup . nip ;then ; is key | |
Rather than "nv-key", a more generic word to get the default (non-vectored) definition can be used: | |
: default: ' drop which @ d->xt @ 2 + compile ; immediate |
Compiler macros are often used to lay down code in the calling word. You'll see something like: | |
: foo ['] + compile ['] . compile ; immediate | |
This is fine, but sometimes you need to deal with other macros: | |
: bar 1 literal, 2 literal, ['] foo execute ; immediate | |
This approach has one problem: keeping track of what words need to be compiled and which need to be called. Plus, with Retro's use of word classes, you may have other words that are handled in other ways. |
Compiler macros are often used to lay down code in the calling word. You'll see something like:
: foo ['] + compile ['] . compile ; immediate
This is fine, but sometimes you need to deal with other macros:
It's sometimes useful to be able to create an empty stub which will be pointed to a real definition later. | |
The simple solution is just to do: | |
: foo ; | |
This creates a new defintion ("foo"), with no runtime action. In Retro all colon definitions can be revectored, so this is all that is strictly required. It does have a downside with regard to readability. We can address this by defining a new word specifically to create stubs. | |
: stub ( "- ) create 0 , 0 , 9 , ['] .word last @ d->class ! ; |
In a standard Retro system, the following is an example of how code is compiled: | |
: foo 10 20 + 1+ . ; | |
foo: | |
lit 10 | |
lit 20 | |
call + | |
call 1+ | |
call . |
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
( This contains a set of words I find useful while debugging ) | |
( code. ) | |
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) | |
{{ | |
variable addr | |
: pad ( - ) | |
addr @ @ | |
dup 1000000 <if 32 emit then |