home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / lib / arrays.4th next >
Encoding:
Text File  |  1994-05-20  |  1.5 KB  |  41 lines

  1. \
  2. \ library.4th ---    Library code for pfe.
  3. \
  4. \ (duz 22May94)
  5. \
  6.  
  7. \ =======================================================================
  8. \ multi-dimensional array type
  9. \ =======================================================================
  10.  
  11. \ Multi-dimensional arrays are supported by two primitives in the kernel
  12. \ doing the multiplication work:
  13. \    BUILD-ARRAY \ n1 n2 ... nX X --- n
  14. \        takes a list of upper bounds plus the dimension of the array,
  15. \        writes those upper bounds to the dictionary, returns their
  16. \        product.
  17. \    ACCESS-ARRAY \ i1 i2 ... iX addr1 --- addr2 offset
  18. \        addr1 points to a list generated by BUILD-ARRAY.
  19. \        Multiplies the actual indices i with the registered bounds
  20. \        pointed to by addr1.
  21. \        Returns the offset in items of the accessed element,
  22. \        addr2 points to just after the list of upper bounds.
  23. \        Indices start with 0, highest index iY is nY - 1.
  24. \        On index out of range ACCESS-ARRAY throws -2051.
  25. \ Usage is simple and demonstrated below with an array of Cells:
  26.  
  27. : CELL-ARRAY    CREATE    \ n1 n2 ... nX X --- ; X is dimension of ARRAY
  28.             BUILD-ARRAY        \ --- size in items
  29.             CELLS            \ --- size in address units
  30.             HERE OVER ALLOT        \ allocate space
  31.             SWAP ERASE        \ and wipe it
  32.         DOES>    \ i1 i2 ... iX --- addr
  33.             ACCESS-ARRAY        \ addr item-offset
  34.             CELLS + ;
  35.  
  36. \ =======================================================================
  37. \ end of arrays.4th
  38. \ =======================================================================
  39.  
  40. CR .( Array types loaded. )
  41.