\ * === rexx/storage.f ==================================================
\ *
\ * Copyright (c) 1986, 1987 by William S. Hawes (All Rights Reserved)
\ *
\ * =====================================================================
\ * Header file to define ARexx data structures.
\ */

find REXX_STORAGE_F not
IFTRUE  : REXX_STORAGE_F ;
		." Compiling rexx/storage.f " CR
OTHERWISE prior.stream
IFEND


find EXEC_TYPES_F not
IFTRUE include exec/types.f
IFEND

find EXEC_NODES_F not
IFTRUE include exec/nodes.f
IFEND

find EXEC_LISTS_F not
IFTRUE include exec/lists.f
IFEND

find EXEC_PORTS_F not
IFTRUE include exec/ports.f
IFEND

find EXEC_LIBRARIES_F not
IFTRUE include exec/libraries.f
IFEND


\ /* The RexxStr structure is used to maintain the internal strings in REXX.
\  * It includes the buffer area for the string and associated attributes.
\  * This is actually a variable-length structure; it is allocated for a
\  * specific length string, and the length is never modified thereafter
\  * (since it's used for recycling).
\  */

structure NexxStr
   LONG:     +ns_Ivalue               \ /* integer value                 */
   SHORT:    +ns_Length               \ /* length in bytes (excl null)   */
   BYTE:    +ns_Flags                \ /* attribute flags               */
   BYTE:    +ns_Hash                 \ /* hash code                     */
8  BYTES:     +ns_Buff              \ /* buffer area for strings       */
structure.end                         \ /* size: 16 bytes (minimum)      */

9 CONSTANT  NXADDLEN                  \ /* offset plus null byte         */
: IVALUE ( nsptr \ value )   +ns_Ivalue @ ;

\ /* String attribute flag bit definitions                                 */
0 CONSTANT NSB_KEEP                    \  /* permanent string?             */
1 CONSTANT NSB_STRING                  \  /* string form valid?            */
2 CONSTANT NSB_NOTNUM                  \  /* non-numeric?                  */
3 CONSTANT NSB_NUMBER                  \  /* a valid number?               */
4 CONSTANT NSB_BINARY                  \  /* integer value saved?          */
5 CONSTANT NSB_FLOAT                   \  /* floating point format?        */
6 CONSTANT NSB_EXT                     \  /* an external string?           */
7 CONSTANT NSB_SOURCE                  \  /* part of the program source?   */

\ /* The flag form of the string attributes                               */
1 NSB_KEEP   SCALE  CONSTANT NSF_KEEP 
1 NSB_STRING SCALE  CONSTANT NSF_STRING 
1 NSB_NOTNUM SCALE  CONSTANT NSF_NOTNUM 
1 NSB_NUMBER SCALE  CONSTANT NSF_NUMBER 
1 NSB_BINARY SCALE  CONSTANT NSF_BINARY 
1 NSB_FLOAT  SCALE  CONSTANT NSF_FLOAT
1 NSB_EXT    SCALE  CONSTANT NSF_EXT
1 NSB_SOURCE SCALE  CONSTANT NSF_SOURCE

\ /* Combinations of flags                                                */
NSF_NUMBER  NSF_BINARY | NSF_STRING |				CONSTANT NSF_INTNUM   
NSF_NUMBER  NSF_FLOAT  |							CONSTANT NSF_DPNUM    
NSF_NOTNUM  NSF_STRING |							CONSTANT NSF_ALPHA    
NSF_SOURCE  NSF_EXT    | NSF_KEEP   |				CONSTANT NSF_OWNED    
NSF_STRING  NSF_SOURCE | NSF_NOTNUM |				CONSTANT KEEPSTR      
NSF_STRING  NSF_SOURCE | NSF_NUMBER | NSF_BINARY |	CONSTANT KEEPNUM      

\ /* The RexxArg structure is identical to the NexxStr structure, but
\  * is allocated from system memory rather than from internal storage.
\  * This structure is used for passing arguments to external programs.
\  * It is usually passed as an "argstring", a pointer to the string buffer.
\  */
structure RexxArg
   LONG:    +ra_Size                 \ /* total allocated length        */
   SHORT:   +ra_Length               \ /* length of string              */
   BYTE:   +ra_Flags                \ /* attribute flags               */
   BYTE:   +ra_Hash                 \ /* hash code                     */
8  BYTES:   +ra_Buff              \ /* buffer area                   */
structure.end                        \ /* size: 16 bytes (minimum)      */

\ /* The RexxMsg structure is used for all communications with Rexx programs.
\  * It is an EXEC message with a parameter block appended.
\  */

structure RexxMsg
   Message 	struct: +rm_Node          \ /* EXEC message structure        */
           	PTR:   +rm_TaskBlock     \ /* pointer to global structure   */
   			PTR:   +rm_LibBase       \ /* library base                  */
   			LONG:   +rm_Action        \ /* command (action) code         */
   			LONG:   +rm_Result1       \ /* primary result (return code)  */
   			LONG:   +rm_Result2       \ /* secondary result              */
   16		PTRS:   +rm_Args	      \ /* argument block (ARG0-ARG15)   */

   			PTR:	+rm_PassPort      \ /* forwarding port               */
   			PTR:    +rm_CommAddr      \ /* host address (port name)      */
   			PTR:    +rm_FileExt       \ /* file extension                */
   			LONG:   +rm_Stdin         \ /* input stream (filehandle)     */
   			LONG:   +rm_Stdout        \ /* output stream (filehandle)    */
   			LONG:   +rm_avail         \ /* future expansion              */
structure.end                         \ /* size: 128 bytes               */

\ /* Field definitions                                                    */
: ARG0 ( rmp -- arg0 )  +rm_Args @ ;
: ARG1 ( rmp -- arg1 )  +rm_Args 4+ @ ; 
: ARG2 ( rmp -- arg2 )  +rm_Args 8+ @ ; 

15 CONSTANT MAXRMARG                  \ /* maximum arguments             */

\ /* Command (action) codes for message packets                           */
HEX
01000000 CONSTANT RXCOMM    \ /* a command-level invocation    */
02000000 CONSTANT RXFUNC    \ /* a function call               */
03000000 CONSTANT RXCLOSE   \ /* close the port                */
04000000 CONSTANT RXQUERY   \ /* query for information         */
07000000 CONSTANT RXADDFH   \ /* add a function host           */
08000000 CONSTANT RXADDLIB  \ /* add a function library        */
09000000 CONSTANT RXREMLIB  \ /* remove a function library     */
0A000000 CONSTANT RXADDCON  \ /* add/update a ClipList string  */
0B000000 CONSTANT RXREMCON  \ /* remove a ClipList string      */
0C000000 CONSTANT RXTCOPN   \ /* open the trace console        */
0D000000 CONSTANT RXTCCLS   \ /* close the trace console       */
DECIMAL

\ /* Command modifier flag bits                                           */
16 CONSTANT RXFB_NOIO    \ /* suppress I/O inheritance?     */
17 CONSTANT RXFB_RESULT  \ /* result string expected?       */
18 CONSTANT RXFB_STRING  \ /* program is a "string file"?   */
19 CONSTANT RXFB_TOKEN   \ /* tokenize the command line?    */
20 CONSTANT RXFB_NONRET  \ /* a "no-return" message?        */

\ /* Modifier flags                                                       */
1 RXFB_RESULT SCALE CONSTANT  RXFF_RESULT 
1 RXFB_STRING SCALE CONSTANT  RXFF_STRING
1 RXFB_TOKEN  SCALE CONSTANT  RXFF_TOKEN
1 RXFB_NONRET SCALE CONSTANT  RXFF_NONRET

HEX
0FF CONSTANT RXCODEMASK
00F CONSTANT RXARGMASK
DECIMAL

\ /* The RexxRsrc structure is used to manage global resources.
\  * The name string for each node is created as a RexxArg structure,
\  * and the total size of the node is saved in the "rr_Size" field.
\  * Functions are provided to allocate and release resource nodes.
\  * If special deletion operations are required, an offset and base can
\  * be provided in "rr_Func" and "rr_Base", respectively.  This function
\  * will be called with the base in register A6 and the node in A0.
\  */

structure RexxRsrc
   Node	struct: +rr_Node
   		SHORT:   +rr_Func            \ /* "auto-delete" offset          */
   		PTR:   +rr_Base            \ /* "auto-delete" base            */
   		LONG:   +rr_Size            \ /* total size of node            */
   		LONG:   +rr_Arg1            \ /* available ...                 */
   		LONG:   +rr_Arg2            \ /* available ...                 */
structure.end                        \ /* size: 32 bytes                */

\ /* Resource node types                                                  */
0 CONSTANT RRT_ANY               \ /* any node type ...             */
1 CONSTANT RRT_LIB               \ /* a function library            */
2 CONSTANT RRT_PORT              \ /* a public port                 */
3 CONSTANT RRT_FILE              \ /* a file IoBuff                 */
4 CONSTANT RRT_HOST              \ /* a function host               */
5 CONSTANT RRT_CLIP              \ /* a Clip List node              */

\ /* The RexxTask structure holds the fields used by REXX to communicate with
\  * external processes, including the client task.  It includes the global
\  * data structure (and the base environment).  The structure is passed to
\  * the newly-created task in its "wake-up" message.
\  */

200 CONSTANT GLOBALSZ  \ /* total size of GlobalData      */

structure RexxTask
   GLOBALSZ		BYTES:	+rt_Global     \ /* global data structure         */
   MsgPort		struct:	+rt_MsgPort    \ /* global message port           */
   				BYTE:	+rt_Flags      \ /* task flag bits                */
   				BYTE:	+rt_SigBit     \ /* signal bit                    */

   				PTR:	+rt_ClientID   \ /* the client's task ID
   				PTR:	+rt_MsgPkt     \ /* the packet being processed
   				PTR:	+rt_TaskID     \ /* our task ID
   				PTR:	+rt_RexxPort   \ /* the REXX public port

   				PTR:	+rt_ErrTrap    \ /* Error trap address
   				PTR:	+rt_StackPtr   \ /* stack pointer for traps

   List 		struct:	+rt_Header1    \ /* Environment list              */
   List 		struct:	+rt_Header2    \ /* Memory freelist               */
   List 		struct:	+rt_Header3    \ /* Memory allocation list        */
   List 		struct:	+rt_Header4    \ /* Files list                    */
   List 		struct:	+rt_Header5    \ /* Message Ports List            */
structure.end

\ /* Definitions for RexxTask flag bits                                   */
0 CONSTANT RTFB_TRACE                   \ /* external trace flag           */
1 CONSTANT RTFB_HALT                    \ /* external halt flag            */
2 CONSTANT RTFB_SUSP                    \ /* suspend task?                 */
3 CONSTANT RTFB_TCUSE                   \ /* trace console in use?         */
6 CONSTANT RTFB_WAIT                    \ /* waiting for reply?            */
7 CONSTANT RTFB_CLOSE                   \ /* task completed?               */

\ /* Definitions for memory allocation constants                          */
16 CONSTANT MEMQUANT  \ /* quantum of memory space       */
HEX
FFFFFFF0 CONSTANT MEMMASK   \ /* mask for rounding the size    */
DECIMAL

1  0  SCALE CONSTANT MEMQUICK  \ /* EXEC flags: MEMF_PUBLIC       */
1 16 SCALE CONSTANT  MEMCLEAR  \ /* EXEC flags: MEMF_CLEAR        */

\ /* The SrcNode is a temporary structure used to hold values destined for a
\  * segment array.  It is also used to maintain the memory freelist.
\  */

structure SrcNode
   			PTR:	+sn_Succ    \   /* next node                     */
   			PTR:	+sn_Pred
   			PTR:   +sn_Ptr     \   /* pointer value                 */
   			LONG:   +sn_Size    \   /* size of object                */
structure.end					\   /* size: 16 bytes                */

