en:pfw:library
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:pfw:library [2025-03-20 16:35] – [A sample library source] willem | en:pfw:library [2025-04-01 15:56] (current) – [noForth t library use] willem | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== A library for Forth ====== | + | ====== A library for (no)Forth ====== |
| - | *W.O.* | + | *W.O. 2025* |
| Line 14: | Line 14: | ||
| An optional word as suggested by Ulrich Hoffmann | An optional word as suggested by Ulrich Hoffmann | ||
| - | * '' | + | * '' |
| Optional words as suggested by Willem Ouwerkerk | Optional words as suggested by Willem Ouwerkerk | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| ===== Pseudo code ===== | ===== Pseudo code ===== | ||
| Line 161: | Line 161: | ||
| <code forth> | <code forth> | ||
| create KEYWORD | create KEYWORD | ||
| - | 1008, | + | 1008, |
| LIB value LIBHERE | LIB value LIBHERE | ||
| - | : LIB-FIND | + | : FIND-CHAPTER |
| - | keyword place \ Save keyword | + | |
| - | | + | libhere lib |
| - | libhere | + | |
| - | begin | + | |
| - | | + | 2dup < throw |
| - | 0D scan nip over 1+ \ Get line with keywords, skip \ | + | dup c@ r@ c@ = until |
| - | | + | dup 2r@ over s<> 0= until \ Name ok? |
| - | 2dup > while | + | |
| - | bl skip dup >r \ Skip leading spaces | + | |
| - | bl scan \ After keyword | + | |
| - | r@ over r> - \ Keyword length | + | |
| - | keyword count s<> 0= \ Keyword found, leave source address | + | |
| - | if 2drop nip exit | + | |
| - | then | + | |
| - | | + | |
| - | 2drop 09 scan 1+ \ Find library section, skip 09 | + | |
| - | | + | |
| : LIB-REFILL | : LIB-REFILL | ||
| Line 200: | Line 192: | ||
| : NEEDED | : NEEDED | ||
| ['] lib-refill | ['] lib-refill | ||
| - | | + | |
| and lib-load ; | and lib-load ; | ||
| Line 263: | Line 255: | ||
| : OPEN-LIB | : OPEN-LIB | ||
| - | libhere lib <> if | + | libhere lib <> if |
| - | libhere 100 /mod 100 * | + | libhere 100 /mod 100 * |
| - | dup to libhere | + | dup to libhere |
| buffer 100 move to ptr {w exit \ Read uncomplete sector to buffer, open flash | buffer 100 move to ptr {w exit \ Read uncomplete sector to buffer, open flash | ||
| - | then 0 to ptr 09 lc, | + | then 0 to ptr |
| : CLOSE-LIB | : CLOSE-LIB | ||
| Line 303: | Line 295: | ||
| repeat | repeat | ||
| - | : LOOK-AT | + | : LOOK-AT |
| </ | </ | ||
| Line 374: | Line 366: | ||
| ===== The library is just bare ASCII ===== | ===== The library is just bare ASCII ===== | ||
| - | When displayed | + | When opened in an editor |
| <code forth> | <code forth> | ||
| - | \ VERSION VERSIE VSN | + | |
| cr .( NEED version 0.33 ) | cr .( NEED version 0.33 ) | ||
| cr .( | cr .( | ||
| Line 389: | Line 381: | ||
| v: fresh | v: fresh | ||
| - | \ VIEW | + | \ LOOK-AT |
| ( A library consists of 09 {tab}, 0D {cr} and ASCII chars ) | ( A library consists of 09 {tab}, 0D {cr} and ASCII chars ) | ||
| ( ranging from blank to ~ others chars are not allowed ) | ( ranging from blank to ~ others chars are not allowed ) | ||
| Line 407: | Line 399: | ||
| v: extra definitions | v: extra definitions | ||
| - | : VIEW | + | : LOOK-AT |
| v: fresh | v: fresh | ||
| Line 426: | Line 418: | ||
| </ | </ | ||
| - | ==== A little extra ==== | + | ==== Optional additions |
| Loading a lot of library code in one go. It must be used like this: '' | Loading a lot of library code in one go. It must be used like this: '' | ||
| Line 433: | Line 425: | ||
| <code forth> | <code forth> | ||
| v: inside | v: inside | ||
| - | : NEED( ( keyw-0 .. keyw-n -- ) | + | : NEED( |
| begin bl-word count \ Read next keyword | begin bl-word count \ Read next keyword | ||
| 2dup s" )" s<> | 2dup s" )" s<> | ||
| Line 439: | Line 431: | ||
| 2drop ; \ Ready | 2drop ; \ Ready | ||
| v: fresh | v: fresh | ||
| + | </ | ||
| + | |||
| + | Loading and viewing a code chapter from any library.\\ | ||
| + | This function has two strings as parameter, therefore you can select the library where to code is taken from too.\\ | ||
| + | This is just a sample implementation: | ||
| + | |||
| + | <code forth> | ||
| + | : NEED-FROM | ||
| + | lib libhere 2> | ||
| + | ['] need catch \ Load code from that library, catch errors | ||
| + | 2r> to libhere to lib throw ; \ Restore saved library & throw error number | ||
| + | </ | ||
| + | |||
| + | Viewing code chapter from any library. It needs the library name as string parameter.\\ | ||
| + | |||
| + | <code forth> | ||
| + | : CHAPTERS-FROM ( " | ||
| + | lib libhere 2> | ||
| + | chapters | ||
| + | 2r> to libhere to lib ; \ Restore saved library | ||
| </ | </ | ||
en/pfw/library.1742484934.txt.gz · Last modified: 2025-03-20 16:35 by willem