User Tools

Site Tools


en:pfw:library

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:library [2024-08-25 13:32] – [A little extra] willemen:pfw:library [2024-09-04 13:16] (current) – [The viewer] willem
Line 17: Line 17:
   * ''%%NEEDED%%''  ''%%( a b -- i*x )%%'' Make sure that name represented by the string a b is present in the dictionary. If not, load it from a library. If name already exists, do nothing.   * ''%%NEEDED%%''  ''%%( a b -- i*x )%%'' Make sure that name represented by the string a b is present in the dictionary. If not, load it from a library. If name already exists, do nothing.
   * ''%%.LIB%%''  ''%%( -- )%%'' Show all section/chapter headers of the current library in one or more columns   * ''%%.LIB%%''  ''%%( -- )%%'' Show all section/chapter headers of the current library in one or more columns
 +  * ''%%VIEW%%'' ''%%( "name" -- )%%'' View the code from the libary, that belongs to "name".
  
 ===== Pseudo code ===== ===== Pseudo code =====
Line 34: Line 35:
 Function: .LIB     ( -- ) Function: .LIB     ( -- )
     Print all chapter headers in a human readable form.     Print all chapter headers in a human readable form.
 +    
 +Function: VIEW     ( "name" --)
 +    When the keyword "name" is found view the source code chapter,
 +    otherwise issue an error message
          
 Function: FROM     ( "name" -- ) Function: FROM     ( "name" -- )
Line 95: Line 100:
 : 2TUCK   2swap 2over ;     ( x1 x2 x3 x4 -- x3 x4 x1 x2 x3 x4 )<0D> : 2TUCK   2swap 2over ;     ( x1 x2 x3 x4 -- x3 x4 x1 x2 x3 x4 )<0D>
 <09> <09>
- 
 \ 2ROT<0D> \ 2ROT<0D>
 \ Rotate third double to top of stack<0D> \ Rotate third double to top of stack<0D>
 : 2ROT    2>r 2swap  2r> 2swap ;<0D> : 2ROT    2>r 2swap  2r> 2swap ;<0D>
 <09> <09>
- 
 \ -2ROT<0D> \ -2ROT<0D>
 \ Rotate top double to third double position on the stack<0D> \ Rotate top double to third double position on the stack<0D>
Line 273: Line 276:
 </code> </code>
  
 +===== A viewer for the library =====
 +
 +This viewer shows 16 or less lines at a time.
 +It stops at a <09> character, prints a divider line and waits for user input.
 +When the spacebar was hit, it goes on displaying the next chapter.
 +Any other key leaves the viewer.
 +
 +<code forth>
 +( A library consists of 09 {tab}, 0D {cr} and ASCII chars )
 +( ranging from blank to ~ others chars are not allowed )
 +\ Show the library source code of a chapter
 +: .LINE     ( a1 -- a2 ch ) begin c@+ dup BL < 0= while emit repeat ;
 +: .DIVIDER  ( -- )          cr  10 0 do ." -- " loop  cr ;
 +
 +: LIBTYPE   ( a -- )
 +    begin
 +        10 0 do                         \ Max. 16 lines at a time
 +            cr .line 09 =               \ End of source chapter?
 +            if  .divider leave  then    \ Show divider & ready
 +        loop
 +    dup libhere < while                 \ More library source to be done?
 +        key BL <> if drop exit then     \ Yes, ask key, stop on non space
 +    repeat  drop ;
 +
 +: VIEW      ( "name" -- )       bl word count  lib-find libtype ;
 +
 +</code>
 ===== A sample library source ===== ===== A sample library source =====
 This examples shows how many different code parts can be used inside the library.\\ This examples shows how many different code parts can be used inside the library.\\
Line 291: Line 321:
 chapter RESTORE-LIB chapter RESTORE-LIB
 v: inside   \ Restore LIBHERE in case it got lost v: inside   \ Restore LIBHERE in case it got lost
-    libhere hx 40000 +  lib   hx FF scan  nip to libhere+    lib hx 50000 +  lib   hx FF scan  nip to libhere
     cr .( Libhere ) libhere u.     cr .( Libhere ) libhere u.
     cr .( Size ) libhere lib - dm . .( bytes )     cr .( Size ) libhere lib - dm . .( bytes )
-    freeze 
 v: fresh v: fresh
 %% %%
Line 350: Line 379:
 cr .( Size is about 174 kBytes ) cr .( Size is about 174 kBytes )
  
-<09>\ RESTORE-LIB+    \ RESTORE-LIB
 v: inside   \ Restore LIBHERE in case it got lost v: inside   \ Restore LIBHERE in case it got lost
-    libhere hx 40000 +  lib   hx FF scan  nip to libhere+    lib hx 50000 +  lib   hx FF scan  nip to libhere
     cr .( Libhere ) libhere u.     cr .( Libhere ) libhere u.
     cr .( Size ) libhere lib - dm . .( bytes )     cr .( Size ) libhere lib - dm . .( bytes )
-    freeze 
 v: fresh v: fresh
  
-<09>\ VIEW+    \ VIEW
 ( 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 379: Line 407:
 v: fresh v: fresh
  
-<09>\ PIN SQUERY+    \ PIN SQUERY
 ( GPIO -- ) \ Change GPIO pin for S? ( GPIO -- ) \ Change GPIO pin for S?
 need [IF] need [IF]
Line 388: Line 416:
 cr .( Test S? ) s? . cr .( Test S? ) s? .
  
-<09>\ 12MHZ+    \ 12MHZ
 \ change clock frequency \ change clock frequency
 dm 12       0 cfg ! \ Set frequency in MHz dm 12       0 cfg ! \ Set frequency in MHz
Line 397: Line 425:
 ==== A little extra ==== ==== A little extra ====
  
-Loading a lot of library functions in one go. it is used like this: ''%%need( -rot -2rot d- )%%''\\ +Loading a lot of library code in one go. it is used like this: ''%%need( -rot -2rot d- asm\ )%%''\\ 
-Note that ''%%@INPUT%%'' ''%%!INPUT%%'' are primitives for the ANSI words  ''%%SAVE-INPUT%%'' ''%%RESTORE-INPUT%%''.+Note that ''%%BL-WORD%%'' is a typical noForth word that uses ''%%REFILL%%'' inside, so it can load multiple lines of library words when you need too.
  
 <code forth> <code forth>
 v: inside v: inside
-: NEED(     ccc0 .. cccn -- ) +: NEED(     keyw-0 .. keyw-n -- ) 
-    ch ) parse              \ Read line with keywords until closing paren +    begin  bl-word count    \ Read next keyword 
-    @input >r 2> 0 !input \ Save & set input stream data +           2dup s" )" s<>   \ Not the closing paren? 
-    begin  bl parse ?dup    \ Read next keyword +    while  needed  repeat   Ok, perform NEEDED on the keyword 
-    while  needed  repeat   When found perform NEEDED +    2drop                 Ready
-    drop  2r> r> !input   Not found restore input stream+
 v: fresh v: fresh
 </code> </code>
en/pfw/library.1724585576.txt.gz · Last modified: 2024-08-25 13:32 by willem