-
-
Save crcx/246027 to your computer and use it in GitHub Desktop.
Altered version of docl's 'key' handler with commentary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This uses a couple of tricks: | |
' drop ::: Find a word and discard the XT | |
which @ ::: Get the dictionary header of the most recently found word | |
d->xt @ ::: Get the XT from the dictionary header | |
2 + ::: Skip past the vector prefix to the default definition | |
compile ::: Compile a call to the default definition | |
OR: | |
: default ' 2 + compile ; immediate | |
' ::: Find a word and get the XT | |
2 + ::: Skip past the vector prefix to the default definition | |
compile ::: Compile a call to the default definition | |
With this, the the code becomes: | |
: :: here ] ; | |
:: default: key dup 27 =if drop default: key dup . then ; is key | |
(Note slight restructuring to generate slightly more optimal code: only one return point, and 'drop' is faster than 'nip') | |
Overall, with stack comments: | |
: default: ( "- ) ' drop which @ d->xt @ 2 + compile ; immediate | |
: :: ( -a ) here ] ; | |
:: ( -c ) default: key dup 27 =if drop default: key dup . then ; is key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ok : :: here ] ; | |
ok : nv-key ['] key 2 + compile ; | |
ok immediate | |
ok ( unvectored key ) | |
ok :: nv-key dup 27 =if nv-key dup . nip ;then ; | |
ok is key | |
ok 119 w111 o114 r100 d115 s32 nv-key :: compile-only .compiler see show dump set-blocks e new i ia n p x d s v (ia) (e) (v) (line) (block) block blk line-ending offset #-block-size #-blocks does> find binary octal hex decimal reclass forget ." < > <> = ;then if FALSE TRUE ` immediate fill copy constant variable variable: allot }} ---reveal--- {{ } { <list> -- ++ >in base whitespace which heap #mem fh fw fb update tib compiler last ( next for ['] pop push 0; again repeat then !if <if >if =if ;; ; [ s" >tib isNumber? listen ok >number save notfound reset depth boot d->name d->xt d->class .data .macro .word with-class (remap-keys) bye getLength keepString redraw tempString literal, compile devector is :devector :is -! +! !+ @+ ' wait compare " . execute neg mod / off on 2dup tuck -rot rot not 2drop over key words clear type emit cr later : create ] , here accept out in dup nip >> << /mod * - + ! @ xor or and drop swap 1- 1+ | |
ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment