Author: | Charles Childers |
---|---|
Version: | 2009.12.21 |
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
( useful things ) | |
: dictionary.find/xt ( string:name - xt ) find [ @d->xt ] [ drop #0 ] if ; | |
: getc:internal ( -c ) &getc 2 + @ do ; | |
: __$ keepString 1 , , &dictionary.find/xt , ; parsing | |
( keymap ) | |
9 variable: prefix:CHAR | |
create prefix:TABLE 256 allot | |
( We will lookup the keymap by name, to allow for per-application maps ) |
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
9 variable: prefix:CHAR | |
create prefix:TABLE | |
256 allot | |
: getc:internal ( -c ) &getc 2 + @ do ; | |
[ dup @prefix:CHAR == | |
[ drop getc:internal | |
"prefix:TABLE" find drop @d->xt + @ dup 0 <> |
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
chain: stringBuffer' | |
{{ | |
tib variable: buffer | |
@buffer variable: pointer | |
: terminate ( - ) 0 @pointer ! ; | |
: bs? ( c-cf ) dup 8 = ; | |
: remove ( c- ) drop pointer -- @pointer @buffer <if @buffer !pointer then terminate ; | |
: add ( c- ) @pointer ! pointer ++ terminate ; | |
---reveal--- | |
: addToBuffer ( c- ) bs? if remove else add then ; |
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
chain: stringBuffer' | |
{{ | |
tib variable: buffer | |
@buffer variable: pointer | |
: terminate ( - ) 0 @pointer ! ; | |
---reveal--- | |
: addToBuffer ( c- ) @pointer ! pointer ++ terminate ; | |
: getFromBuffer ( -c ) pointer -- @pointer @ terminate ; | |
: endOfBuffer ( -a ) repeat @pointer dup @ 0; 2drop pointer ++ again ; | |
: sizeOfBuffer ( -n ) @pointer @buffer - ; |
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
with quotes' | |
( compare two strings from the beginning and return how many ) | |
( similar characters there are before the strings diverge. ) | |
: ^match ( $$-n ) | |
0 -rot repeat @+ [ swap @+ ] dip =if rot 1+ -rot else 2drop ;then again ; | |
( test each word in the dictionary for similarity. if similar up ) | |
( to the current point, add to the suggestions queue. ) | |
create list here , 100 allot |
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
variable this | |
variable that | |
: chain create here !that 0 , here !this 2 allot ; | |
: +link here push @this , @last , pop !this @@last !last ; | |
: seal @this @that ! ; | |
variable flag | |
variable xt | |
variable str | |
: zdrop ( n-n | nz-z ) dup 0 =if 2drop 0 then ; |
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
: append ( $$-$ ) | |
swap | |
here push | |
here over getLength dup allot copy | |
here over getLength dup allot copy | |
0 , pop ; | |
: paren-wrap s" (" swap append s" )" append ; |
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
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. |
NewerOlder