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 [2025-03-20 17:13] – [The idea] willemen: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 19: Line 19:
   * ''%%NEEDED%%''  ''%%( i*x a b -- j*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%%''  ''%%( i*x a b -- j*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.
   * ''%%RUN%%'' ''%%( i*x "name" -- j*x )%%'' Find "name" in the library and load & run the script from a library.   * ''%%RUN%%'' ''%%( i*x "name" -- j*x )%%'' Find "name" in the library and load & run the script from a library.
-  * ''%%CHAPTERS%%''  ''%%( -- )%%'' Show all section/chapter headers of the current library in one or more columns +  * ''%%CHAPTERS%%''  ''%%( -- )%%'' Show all chapter headers of the current library 
-  * ''%%LOOK-AT%%'' ''%%( "name" -- )%%'' Look at the code chapter from the library, that belongs to "name".+  * ''%%LOOK-AT%%'' ''%%( "name" -- )%%'' Look at the code of chapter “name” from the active library.
  
 ===== Pseudo code ===== ===== Pseudo code =====
Line 164: Line 164:
   LIB value LIBHERE         \ Current end address of library   LIB value LIBHERE         \ Current end address of library
  
-LIB-FIND    a +n –sa ) \ a,+n=name, sa=begin-source-section +FIND-CHAPTER adr len -- chap-adr )  Find chapter start address (A.N.) 
-    keyword place           Save keyword +    >r >r 
-    keyword count upper     \ Convert to uppercase +    libhere lib 
-    libhere  lib            \ Library address range +    begin begin begin 
-    begin +        scan                      To begin chapter 
-        2dup > 0= throw 2dup \ Nothing found? +        2dup < throw                    End library
-        0D scan nip over 1+ \ Get line with keywords, skip \ +        dup c@ r@ c@ = until            First letter ok? 
-        begin +        dup 2r@ over s<> 0= until       Name ok? 
-        2dup > while        Line not done+        dup 2r@ drop c@ ch ! < until  Length ok? 
-            bl skip dup > \ Skip leading spaces +    nip  2 - rdrop  rdrop ;
-            bl scan         After keyword +
-            r over r> -   \ Keyword length +
-            keyword count s<> 0= \ Keyword found, leave source address +
-            if  2drop nip exit +
-            then +
-        repeat +
-        2drop  09 scan  1+  \ Find library section, skip 09 +
-    again ;+
  
 : LIB-REFILL  ( source-id –- f )  : LIB-REFILL  ( source-id –- f ) 
Line 200: Line 192:
 : NEEDED      ( a +n –- i*x )  : NEEDED      ( a +n –- i*x ) 
     ['] lib-refill  to 'refill   \ Add library REFILL     ['] lib-refill  to 'refill   \ Add library REFILL
-    LIB-FIND keyword find nip 0= \ in the current forth search order+    find-chapter keyword find nip 0= \ in the current forth search order
     and lib-load ;     and lib-load ;
  
Line 303: Line 295:
     repeat  drop ;     repeat  drop ;
  
-: LOOK-AT   ( "name" -- )       bl word count  lib-find libtype ;+: LOOK-AT   ( "name" -- )       bl word count  find-chapter libtype ;
  
 </code> </code>
en/pfw/library.1742487193.txt.gz · Last modified: 2025-03-20 17:13 by willem