176116Sdcs\ #if (FICL_WANT_OOP) 240843Smsmith\ ** ficl/softwords/classes.fr 340843Smsmith\ ** F I C L 2 . 0 C L A S S E S 440843Smsmith\ john sadler 1 sep 98 540843Smsmith\ Needs oop.fr 660959Sdcs\ 760959Sdcs\ $FreeBSD$ 840843Smsmith 940843Smsmithalso oop definitions 1040843Smsmith 1140843Smsmith\ REF subclass holds a pointer to an object. It's 1240843Smsmith\ mainly for aggregation to help in making data structures. 1340843Smsmith\ 1440843Smsmithobject subclass c-ref 1540843Smsmith cell: .class 1640843Smsmith cell: .instance 1740843Smsmith 1840843Smsmith : get ( inst class -- refinst refclass ) 1940843Smsmith drop 2@ ; 2040843Smsmith : set ( refinst refclass inst class -- ) 2140843Smsmith drop 2! ; 2240843Smsmithend-class 2340843Smsmith 2440843Smsmithobject subclass c-byte 2540843Smsmith char: .payload 2640843Smsmith 2740843Smsmith : get drop c@ ; 2840843Smsmith : set drop c! ; 2940843Smsmithend-class 3040843Smsmith 3140843Smsmithobject subclass c-2byte 3240843Smsmith 2 chars: .payload 3340843Smsmith 3440843Smsmith : get drop w@ ; 3540843Smsmith : set drop w! ; 3640843Smsmithend-class 3740843Smsmith 3840843Smsmithobject subclass c-4byte 3961149Sdcs 4 chars: .payload 4061149Sdcs 4176116Sdcs : get drop q@ ; 4276116Sdcs : set drop q! ; 4361149Sdcsend-class 4461149Sdcs 4576116Sdcs 4661149Sdcsobject subclass c-cell 4740843Smsmith cell: .payload 4840843Smsmith 4940843Smsmith : get drop @ ; 5040843Smsmith : set drop ! ; 5140843Smsmithend-class 5240843Smsmith 5340843Smsmith 5440843Smsmith\ ** C - P T R 5540843Smsmith\ Base class for pointers to scalars (not objects). 5640843Smsmith\ Note: use c-ref to make references to objects. C-ptr 5740843Smsmith\ subclasses refer to untyped quantities of various sizes. 5840843Smsmith 5940843Smsmith\ Derived classes must specify the size of the thing 6040843Smsmith\ they point to, and supply get and set methods. 6140843Smsmith 6240843Smsmith\ All derived classes must define the @size method: 6340843Smsmith\ @size ( inst class -- addr-units ) 6440843Smsmith\ Returns the size in address units of the thing the pointer 6540843Smsmith\ refers to. 6640843Smsmithobject subclass c-ptr 6761149Sdcs c-cell obj: .addr 6840843Smsmith 6940843Smsmith \ get the value of the pointer 7040843Smsmith : get-ptr ( inst class -- addr ) 7161149Sdcs c-ptr => .addr 7261149Sdcs c-cell => get 7340843Smsmith ; 7440843Smsmith 7540843Smsmith \ set the pointer to address supplied 7640843Smsmith : set-ptr ( addr inst class -- ) 7761149Sdcs c-ptr => .addr 7861149Sdcs c-cell => set 7940843Smsmith ; 8040843Smsmith 8160959Sdcs \ force the pointer to be null 8260959Sdcs : clr-ptr 8361149Sdcs 0 -rot c-ptr => .addr c-cell => set 8460959Sdcs ; 8560959Sdcs 8660959Sdcs \ return flag indicating null-ness 8760959Sdcs : ?null ( inst class -- flag ) 8860959Sdcs c-ptr => get-ptr 0= 8960959Sdcs ; 9060959Sdcs 9140843Smsmith \ increment the pointer in place 9240843Smsmith : inc-ptr ( inst class -- ) 9340843Smsmith 2dup 2dup ( i c i c i c ) 9440843Smsmith c-ptr => get-ptr -rot ( i c addr i c ) 9540843Smsmith --> @size + -rot ( addr' i c ) 9640843Smsmith c-ptr => set-ptr 9740843Smsmith ; 9840843Smsmith 9940843Smsmith \ decrement the pointer in place 10040843Smsmith : dec-ptr ( inst class -- ) 10140843Smsmith 2dup 2dup ( i c i c i c ) 10240843Smsmith c-ptr => get-ptr -rot ( i c addr i c ) 10340843Smsmith --> @size - -rot ( addr' i c ) 10440843Smsmith c-ptr => set-ptr 10540843Smsmith ; 10640843Smsmith 10740843Smsmith \ index the pointer in place 10876116Sdcs : index-ptr { index 2:this -- } 10976116Sdcs this --> get-ptr ( addr ) 11076116Sdcs this --> @size index * + ( addr' ) 11176116Sdcs this --> set-ptr 11240843Smsmith ; 11340843Smsmith 11440843Smsmithend-class 11540843Smsmith 11640843Smsmith 11740843Smsmith\ ** C - C E L L P T R 11861149Sdcs\ Models a pointer to cell (a 32 or 64 bit scalar). 11940843Smsmithc-ptr subclass c-cellPtr 12061149Sdcs : @size 2drop 1 cells ; 12140843Smsmith \ fetch and store through the pointer 12240843Smsmith : get ( inst class -- cell ) 12340843Smsmith c-ptr => get-ptr @ 12440843Smsmith ; 12540843Smsmith : set ( value inst class -- ) 12640843Smsmith c-ptr => get-ptr ! 12740843Smsmith ; 12840843Smsmithend-class 12940843Smsmith 13040843Smsmith 13176116Sdcs\ ** C - 4 B Y T E P T R 13276116Sdcs\ Models a pointer to a quadbyte scalar 13361149Sdcsc-ptr subclass c-4bytePtr 13461149Sdcs : @size 2drop 4 ; 13561149Sdcs \ fetch and store through the pointer 13661149Sdcs : get ( inst class -- value ) 13776116Sdcs c-ptr => get-ptr q@ 13861149Sdcs ; 13961149Sdcs : set ( value inst class -- ) 14076116Sdcs c-ptr => get-ptr q! 14161149Sdcs ; 14276116Sdcs end-class 14376116Sdcs 14440843Smsmith\ ** C - 2 B Y T E P T R 14540843Smsmith\ Models a pointer to a 16 bit scalar 14640843Smsmithc-ptr subclass c-2bytePtr 14740843Smsmith : @size 2drop 2 ; 14840843Smsmith \ fetch and store through the pointer 14940843Smsmith : get ( inst class -- value ) 15040843Smsmith c-ptr => get-ptr w@ 15140843Smsmith ; 15240843Smsmith : set ( value inst class -- ) 15340843Smsmith c-ptr => get-ptr w! 15440843Smsmith ; 15540843Smsmithend-class 15640843Smsmith 15740843Smsmith 15840843Smsmith\ ** C - B Y T E P T R 15940843Smsmith\ Models a pointer to an 8 bit scalar 16040843Smsmithc-ptr subclass c-bytePtr 16140843Smsmith : @size 2drop 1 ; 16240843Smsmith \ fetch and store through the pointer 16340843Smsmith : get ( inst class -- value ) 16440843Smsmith c-ptr => get-ptr c@ 16540843Smsmith ; 16640843Smsmith : set ( value inst class -- ) 16740843Smsmith c-ptr => get-ptr c! 16840843Smsmith ; 16940843Smsmithend-class 17040843Smsmith 17140843Smsmith 17240843Smsmithprevious definitions 17376116Sdcs\ #endif 174