home *** CD-ROM | disk | FTP | other *** search
Null Bytes Alternating | 1995-05-19 | 12.6 KB | 159 lines |
- \ oopsobjs.utf .. test objects for multioop.utf
- \ ANS Forth compliant source code is Copyright (c)1992-1994 by
- \ Jack J. Woehr, P.O. Box 51, Golden, Colorado 80402-0051
- \ jax@well.sf.ca.us 72203.1320@compuserve.com
- \ SYSOP RCFB (303) 278-0364 2400/9600/14400
- \ All Rights Reserved
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- \ This is free software and can be modified and redistributed under
- \ certain conditions described in the file COPYING.TXT. The
- \ Disclaimer of Warranty and License for this free software are also
- \ contained in the file COPYING.TXT.
- \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- \ $Revision: 1.1 $
- \
- \ Dependencies:
- \ Object extensions loaded from file MULTIOOP.UTF
- \ TUCK from CORE EXT
- \ A Standard System still exists after this code is loaded.
-
- \ Test Code for MULTIOOP.
- \ Remember, all methods are passed the object address automatically
- \ (here designated thusly: [o])
-
- : PROVIDES ( c-addr u "ccc< >" --)
- BL WORD FIND NIP 0=
- IF INCLUDED ELSE 2DROP THEN ;
-
- S" UTILS\UTILS.UTF" PROVIDES .(
- S" OBJ4TH\MULTIOOP.UTF" PROVIDES CLASS
-
- .( Loading test objects for Multioop.) CR
-
- MARKER multioop.utf
- BASE @ HEX
-
- \ Class OBJECT is essentially a one-dimensional array.
- CELL CLASS: OBJECT
- M: `TO' ( value index [o] --)
- 3 ?ENOUGH \ -- value index [o]
- OVER 0< ABORT" Negative index." \ -- value index [o]
- 2DUP SIZEOF 1- \ -- value index [o] index n
- > ABORT" Index too large." \ -- value index [o]
- TUCK TYPEOF \ -- value [o] index n
- * \ -- value [o] offset
- SWAP DATAOF \ -- value offset data-addr
- + \ -- value address
- ! \ --
- ;M
-
- M: `AT' ( index [o] -- value)
- 2 ?ENOUGH \ -- index [o]
- OVER 0< ABORT" Negative index." \ -- index [o]
- 2DUP SIZEOF 1- \ -- index [o] index n
- > ABORT" Index too large." \ -- index [o]
- TUCK TYPEOF \ -- [o] index n
- * \ -- [o] offset
- SWAP DATAOF \ -- offset data-addr
- + \ -- address
- @ \ -- value
- ;M
- ;CLASS
-
- \ Class ARRAY adds the method of summing all its entries.
- CELL CLASS: ARRAY
- INHERITS OBJECT
-
- M: `SUM' ( [o] -- sum)
- 0 SWAP \ dummy to hold result
- DUP SIZEOF \ number of entries in object
- 0 ?DO
- I `AT' 2 PICK \ get contents
- DO-OBJ
- ROT + SWAP \ add to dummp
- LOOP
- DROP \ discard object address
- ;M
-
- ;CLASS
-
- \ Class BOOLEAN adds some boolean methods for mask manipulation.
- \ The entries are operated upon and results are both returned upon
- \ the data stack and stored into the original entry.
- CELL CLASS: BOOLEAN
- INHERITS OBJECT
-
- M: `NOT!' ( index [o] -- x)
- 2 ?ENOUGH \ check stack
- 2DUP `AT' SWAP DO-OBJ \ get value
- INVERT DUP >R \ INVERT and save
- ROT ROT `TO' SWAP DO-OBJ \ store to entry
- R> \ return result
- ;M
-
- M: `AND!' ( bitmask index [o] -- x)
- 3 ?ENOUGH \ check stack
- ROT >R \ put bitmask where handy
- 2DUP `AT' SWAP DO-OBJ \ get value
- R> AND DUP >R \ AND and save
- ROT ROT `TO' SWAP DO-OBJ \ store to entry
- R> \ return result
- ;M
-
- M: `OR!' ( bitmask index [o] -- x)
- 3 ?ENOUGH \ check stack
- ROT >R \ put bitmask where handy
- 2DUP `AT' SWAP DO-OBJ \ get value
- R> OR DUP >R \ OR and save
- ROT ROT `TO' SWAP DO-OBJ \ store to entry
- R> \ return result
- ;M
-
- ;CLASS
-
- \ Class CHAR-ARRAY (address-unit array) has ARRAY's SUM method and
- \ BOOLEAN's methods but has to use its own `AT' and `TO' since
- \ we are talking characters, not cells here ( note C@ and C!).
- 1 CHARS CLASS: CHAR-ARRAY
-
- M: `TO' ( value index [o] --)
- 3 ?ENOUGH \ -- value index [o]
- OVER 0< ABORT" Negative index." \ -- value index [o]
- 2DUP SIZEOF 1- \ -- value index [o] index n
- > ABORT" Index too large." \ -- value index [o]
- TUCK TYPEOF \ -- value [o] index n
- * \ -- value [o] offset
- SWAP DATAOF \ -- value offset data-addr
- + \ -- value address
- C! \ --
- ;M
-
- M: `AT' ( index [o] -- value)
- 2 ?ENOUGH \ -- index [o]
- OVER 0< ABORT" Negative index." \ -- index [o]
- 2DUP SIZEOF 1- \ -- index [o] index n
- > ABORT" Index too large." \ -- index [o]
- TUCK TYPEOF \ -- [o] index n
- * \ -- [o] offset
- SWAP DATAOF \ -- offset data-addr
- + \ -- address
- C@ \ -- value
- ;M
-
- M: `CHECKSUM' ( [o] -- checksum)
- `SUM' SWAP DO-OBJ \ SUM from ARRAY class
- 0FF AND 0FF SWAP - \ subtract from 0xff
- ;M
-
- INHERITS ARRAY
- INHERITS BOOLEAN
-
- ;CLASS
-
- BASE !
-
- \ ~~~~~~~~~~~~~~~~~~~
- \ End of OOPSOBJS.UTF
- \ ~~~~~~~~~~~~~~~~~~~
-
-