home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mc / mm.h < prev    next >
C/C++ Source or Header  |  1995-01-14  |  5KB  |  158 lines

  1. /* mm.h : stuff for the Mutt machine
  2.  */
  3.  
  4. /* Craig Durland    Public Domain
  5.  *   Distributed "as is", without warranties of any kind, but comments,
  6.  *     suggestions and bug reports are welcome.
  7.  */
  8.  
  9. #ifndef __MM_H_INCLUDED
  10. #define __MM_H_INCLUDED
  11.  
  12. /* ******************************************************************** */
  13. /* ******** Stuff you can modify (but probably don't need to) ********* */
  14. /* ******************************************************************** */
  15.  
  16. #define INTELCPU 0    /* such as 8086, 80286, etc.  0 if anything else */
  17.  
  18. #define RSIZ 300    /* max size of result string */
  19.  
  20. #define OSTACKSIZ 30    /* max operators on op stack */
  21. #define ASTACKSIZ 200    /* max args on arg stack */
  22. #define VSTACKSIZ 1500    /* number of bytes for stack frames, local vars ... */
  23.  
  24.     /* A Mutt code identifier and version controller */
  25. #define MM_MAGIC_NUMBER 0xB1
  26.  
  27. /* ******************************************************************** */
  28. /* ******** You should NOT modify anything below this line ************ */
  29. /* ******************************************************************** */
  30.  
  31.     /* types inbedded in MUTT code */
  32. typedef uint16 address;            /* used to create pc offsets */
  33. typedef uint8  *maddr;            /* MUTT machine address */
  34.  
  35.    /* MMDatum types:  one byte.
  36.     * Used in Mutt programing so be careful if you change the order!
  37.     */
  38. #define VOID      0x01
  39. #define STRING      0x02        /* string constant */
  40. #define NUMBER      0x03
  41. #define REAL      0x04
  42. #define BOOLEAN   0x05
  43. #define BLOB      0x06
  44. #define FCNPTR      0x07
  45. #define OSTRING      0x08        /* string object */
  46. #define LIST      0x09        /* list of objects */
  47. #define CHARACTER 0x0A        /* Don't use! This is a place holder */
  48.  
  49. /* ??? get rid of blob and have: */
  50. #if 0
  51. /* arrays and (asc) might cause problems */
  52. /* would have to implement (cast) */
  53. #define PSTRING      0x10
  54. #define PNUMBER      0x11
  55. #define PREAL      0x12
  56. #define PBOOLEAN  0x13
  57. #endif
  58.  
  59.     /* subtypes (not MMDatums) */
  60. #define INT8      0x81
  61. #define INT16      0x82
  62. #define INT32      0x83
  63.     /* op code types */
  64. #define OPMASK      0xC0    /* to select one of the op cmds */
  65. #define OPADDRESS 0xC0
  66. #define OPNAME       0xC1
  67. #define OPTOKEN      0xC2
  68. #define OPXTOKEN  0xC3
  69. #define OPONAME   0xC4        /* same as OPNAME except name is a OSTRING */
  70.  
  71. typedef struct            /* MM's basic datum structure */
  72. {
  73.   uint8 type;
  74.   union
  75.   {
  76.     char *str;
  77.     int32 num;
  78.     uint8 *blob;
  79.     maddr addr;
  80.     void *object;
  81.   } val;
  82. } MMDatum;
  83.  
  84. typedef struct MMStkFrame        /* a Mutt Machine stack frame */
  85. {
  86.   maddr pc;
  87.   int startframe,
  88.       abase,        /* where the args start */
  89.       vbase,        /* where the local vars start */
  90.       vsptr,
  91.       numargs;        /* number of args in this frame */
  92.   uint8 *gvars;        /* where the global variables are */
  93.   struct MMStkFrame *prev_stkframe;
  94.  
  95.   int block_id;
  96.  
  97.   int lobj_max, lobj_start;
  98.   void *global_object_table;
  99. } MMStkFrame;
  100.  
  101. /* ******************************************************************** */
  102. /* ********************* Code File Header Format ********************** */
  103. /* ******************************************************************** */
  104.  
  105. #define H_ENTRY_POINT         0    /* 2 bytes */
  106. #define H_BYTES_OF_CODE         2    /* 2 bytes */
  107. #define H_NAME_TABLE_OFFSET     4    /* 2 bytes */
  108. #define H_NUMBER_OF_PGMS     6    /* 2 bytes */
  109. #define H_BYTES_OF_GVARS     8    /* 2 bytes */
  110. #define H_MAGIC_NUMBER        10    /* 1 bytes */
  111. #define H_NUM_GLOBAL_OBJECTS    11    /* 2 bytes */
  112.  
  113. #define BYTES_IN_HEADER        13
  114.  
  115. /* ******************************************************************** */
  116. /* ******************************************************************** */
  117. /* ******************************************************************** */
  118.  
  119.     /* pc is a (uint8 *) */
  120. #define GET_UINT8(pc)    *(pc)
  121. #define PUT_UINT8(pc,n)    *(pc) = (n)
  122.  
  123. #if INTELCPU
  124.  
  125. #define GET_INT16(pc)    *(int16 *) (pc)
  126. #define GET_UINT16(pc)    *(uint16 *)(pc)
  127. #define GET_INT32(pc)    *(int32 *) (pc)
  128.  
  129. #define PUT_INT16(pc,n)     *(int16 *) (pc) = (n)
  130. #define PUT_UINT16(pc,n) *(uint16 *)(pc) = (n)
  131. #define PUT_INT32(pc,n)  *(int32 *) (pc) = (n)
  132.  
  133. #else    /* everybody else */
  134.  
  135. #define GET_INT16(pc)    (int16) (*(pc) | (*((pc)+1)<<8))
  136. #define GET_UINT16(pc)    (uint16)(*(pc) | (*((pc)+1)<<8))
  137. #define GET_INT32(pc)    \
  138.     (int32)(*(pc) | ((int32)*((pc)+1)<<8) |\
  139.     ((int32)*((pc)+2)<<16) | ((int32)*((pc)+3)<<24))
  140.  
  141. #define PUT_INT16(pc,n)   (*(pc) = (n) & 0xFF, *((pc)+1) = ((n)>>8) & 0xFF)
  142. #define PUT_UINT16(pc,n)  (*(pc) = (n) & 0xFF, *((pc)+1) = ((n)>>8) & 0xFF)
  143. #define PUT_INT32(pc,n)      \
  144.     (*(pc) = (n) & 0xFF, *((pc)+1) = ((n)>>8) & 0xFF, \
  145.     *((pc)+2) = ((n)>>16) & 0xFF, *((pc)+3) = ((n)>>24) & 0xFF)
  146.  
  147. #endif
  148.  
  149. #define GET_ADDRESS(pc)      GET_UINT16(pc)
  150. #define PUT_ADDRESS(pc,n) PUT_UINT16(pc,n)
  151.  
  152. #ifndef TRUE
  153. #define FALSE   0
  154. #define TRUE    1
  155. #endif
  156.  
  157. #endif    /* __MM_H_INCLUDED */
  158.