home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / PcodeStack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  4.2 KB  |  107 lines  |  [TEXT/KAHL]

  1. /* PcodeStack.h */
  2.  
  3. #ifndef Included_PcodeStack_h
  4. #define Included_PcodeStack_h
  5.  
  6. /* PcodeStack module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12.  
  13. /* these are the various things you can have on the stack */
  14. typedef enum
  15.     {
  16.         esScalar EXECUTE(= -18351),
  17.         esArray,
  18.         esReturnAddress
  19.     } StackTypes;
  20.  
  21. struct StackElement;
  22. typedef struct StackElement StackElement;
  23.  
  24. /* this record is one entry in the stack */
  25. /* this is public for those who need to quickly access stack elements */
  26. #ifdef SHOW_ME_STACKELEMENT
  27. struct StackElement
  28.     {
  29.         union StackThangPlace
  30.             {
  31.                 long                            Integer;
  32.                 float                            Float;
  33.                 double                        Double;
  34.                 void*                            Array;
  35.                 struct
  36.                     {
  37.                         union OpcodeRec*    Procedure;
  38.                         long                            Index;
  39.                     }                                ReturnAddress;
  40.             }                                Data;
  41.         StackTypes                ElementType;
  42.         /* the padding assumes that it won't add up to 16 bytes.  On the Macintosh, */
  43.         /* double is either 8 or 12 bytes and enums are 2 bytes --> 14 bytes, which */
  44.         /* makes padding 2 bytes.  On most systems where enums are 4 bytes, doubles */
  45.         /* are 8 bytes --> 12 bytes, which makes padding 4 bytes.  We may run into */
  46.         /* trouble on systems with 8-byte pointers, which will make ReturnAddress */
  47.         /* 12 bytes and ElementType (probably) 4 bytes; if this happens, then just */
  48.         /* delete the padding.  The whole reason for padding the structure out to 16 */
  49.         /* bytes is to encourage compilers to do strength reduction on array accesses */
  50.         /* to the stack. */
  51.         char                            Padding[16 - (sizeof(union StackThangPlace) + sizeof(StackTypes))];
  52.     };
  53. #endif
  54.  
  55. struct ParamStackRec;
  56. typedef struct ParamStackRec ParamStackRec;
  57.  
  58. /* create a list of parameters that will lead to a function call */
  59. ParamStackRec*        NewParamStack(void);
  60.  
  61. /* this should be called when the parameter list is completely finished to */
  62. /* dispose of all arrays that might still be stored in it */
  63. void                            DisposeParamStack(ParamStackRec* Stack);
  64.  
  65. /* this is a utility routine that disposes of an array on top of stack if it */
  66. /* isn't anywhere else on the stack.  It's used if you are about to pop the top */
  67. /* element so that you don't leave orphaned arrays floating around in memory. */
  68. /* StackPtr is the index of the top element of the stack. */
  69. void                            DisposeIfNotOnStack(StackElement* Stack, long StackPtr);
  70.  
  71. /* this is a utility routine to dispose of an array in the stack somewhere if it */
  72. /* doesn't occur in the stack anywhere else.  It's used if you are about to make */
  73. /* an assignment to the array slot to make sure arrays get disposed of properly. */
  74. /* StackPtr is the index of the top element of the stack.  Where is the index */
  75. /* of the element that is being checked. */
  76. void                            DisposeIfOnStackOnlyOnce(StackElement* Stack, long StackPtr, long Where);
  77.  
  78. /* this is a utility routine to update the address of an array when it has been */
  79. /* resized. */
  80. void                            UpdateStackArrayRefs(StackElement* Stack, long StackPtr,
  81.                                         void* OriginalArrayRef, void* NewArrayRef);
  82.  
  83. /* add a parameter to the parameter stack.  If the data has to */
  84. /* be allocated dynamically, a copy is made.  True is returned if successful. */
  85. MyBoolean                    AddIntegerToStack(ParamStackRec* Stack, long IntegerValue);
  86. MyBoolean                    AddFloatToStack(ParamStackRec* Stack, float FloatValue);
  87. MyBoolean                    AddDoubleToStack(ParamStackRec* Stack, double DoubleValue);
  88. /* the ACTUAL array is added, so you no longer own it after this! */
  89. MyBoolean                    AddArrayToStack(ParamStackRec* Stack, void* Array);
  90.  
  91. /* routines for reading data from a parameter stack */
  92. long                            GetStackInteger(ParamStackRec* Stack, long Index);
  93. float                            GetStackFloat(ParamStackRec* Stack, long Index);
  94. double                        GetStackLongDouble(ParamStackRec* Stack, long Index);
  95. void*                            GetStackArray(ParamStackRec* Stack, long Index);
  96.  
  97. /* routines for obtaining internal stuff for the stack */
  98. StackElement*            GetStackBase(ParamStackRec* Stack);
  99. long                            GetStackInitialSize(ParamStackRec* Stack);
  100. long                            GetStackNumElements(ParamStackRec* Stack);
  101.  
  102. /* routine for restoring changed information to stack */
  103. void                            SetStackInformation(ParamStackRec* Stack, long NewTotalSize,
  104.                                         long NewNumElements, StackElement* NewStackAddress);
  105.  
  106. #endif
  107.