home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / h / rmacros.h < prev    next >
C/C++ Source or Header  |  1996-03-22  |  22KB  |  820 lines

  1. /*
  2.  *  Definitions for macros and manifest constants used in the compiler
  3.  *  interpreter.
  4.  */
  5.  
  6. /*
  7.  *  Definitions common to the compiler and interpreter.
  8.  */
  9.  
  10. /*
  11.  * Constants that are not likely to vary between implementations.
  12.  */
  13.  
  14. #define BitOffMask (IntBits-1)
  15. #define CsetSize (256/IntBits)    /* number of ints to hold 256 cset
  16.                  *  bits. Use (256/IntBits)+1 if
  17.                  *  256 % IntBits != 0 */
  18. #define MinListSlots        8    /* number of elements in an expansion
  19.                  * list element block  */
  20.  
  21. #define MaxCvtLen       257    /* largest string in conversions; the extra
  22.                  *  one is for a terminating null */
  23. #define MaxReadStr       512    /* largest string to read() in one piece */
  24. #define MaxIn          32767    /* largest number of bytes to read() at once */
  25. #define RandA        1103515245    /* random seed multiplier */
  26. #define RandC          453816694    /* random seed additive constant */
  27. #define RanScale 4.65661286e-10    /* random scale factor = 1/(2^31-1) */
  28.  
  29. #define Pi 3.14159265358979323846264338327950288419716939937511
  30.  
  31. /*
  32.  * File status flags in status field of file blocks.
  33.  */
  34. #define Fs_Read         01    /* read access */
  35. #define Fs_Write     02    /* write access */
  36. #define Fs_Create     04    /* file created on open */
  37. #define Fs_Append    010    /* append mode */
  38. #define Fs_Pipe        020    /* reading/writing on a pipe */
  39.  
  40. #ifdef RecordIO
  41. #define Fs_Record       040     /* record structured file */
  42. #endif                    /* RecordIO */
  43.  
  44. #ifdef StandardLib
  45. #define Fs_Reading     0100     /* last file operation was read */
  46. #define Fs_Writing     0200     /* last file operation was write */
  47. #endif                    /* StandardLib */
  48.  
  49. #ifdef Graphics
  50. #define Fs_Window      0400    /* reading/writing on a window */
  51.  
  52. #define XKey_Window 0
  53. #define XKey_Fg 1
  54.  
  55. #ifndef SHORT
  56. #define SHORT int
  57. #endif                    /* SHORT */
  58. #ifndef LONG
  59. #define LONG int
  60. #endif                    /* LONG */
  61.  
  62. #endif                    /* Graphics */
  63.  
  64. /*
  65.  * Codes returned by runtime support routines.
  66.  *  Note, some conversion routines also return type codes. Other routines may
  67.  *  return positive values other than return codes. sort() places restrictions
  68.  *  on Less, Equal, and Greater.
  69.  */
  70.  
  71. #define Less        -1
  72. #define Equal        0
  73. #define Greater        1
  74. #define CvtFail        -2
  75. #define Cvt        -3
  76. #define NoCvt        -4
  77. #define Failed        -5
  78. #define Defaulted    -6
  79. #define Succeeded        -7
  80. #define Error        -8
  81.  
  82. #define GlobalName    0
  83. #define StaticName    1
  84. #define ParamName    2
  85. #define LocalName    3
  86.  
  87. #undef ToAscii
  88. #undef FromAscii
  89. #if EBCDIC == 2
  90. #define ToAscii(e) (FromEBCDIC[e])
  91. #define FromAscii(e) (ToEBCDIC[e])
  92. #else                    /* EBCDIC == 2 */
  93. #define ToAscii(e) (e)
  94. #define FromAscii(e) (e)
  95. #endif                    /* EBCDIC == 2 */
  96.  
  97. /*
  98.  * Pointer to block.
  99.  */
  100. #define BlkLoc(d)    ((d).vword.bptr)
  101.  
  102. /*
  103.  * Check for null-valued descriptor.
  104.  */
  105. #define ChkNull(d)    ((d).dword==D_Null)
  106.  
  107. /*
  108.  * Check for equivalent descriptors.
  109.  */
  110. #define EqlDesc(d1,d2)    ((d1).dword == (d2).dword && BlkLoc(d1) == BlkLoc(d2))
  111.  
  112. /*
  113.  * Integer value.
  114.  */
  115. #define IntVal(d)    ((d).vword.integr)
  116.  
  117. /*
  118.  * Offset from top of block to value of variable.
  119.  */
  120. #define Offset(d)    ((d).dword & OffsetMask)
  121.  
  122. /*
  123.  * Check for pointer.
  124.  */
  125. #define Pointer(d)    ((d).dword & F_Ptr)
  126.  
  127. /*
  128.  * Check for qualifier.
  129.  */
  130. #define Qual(d)        (!((d).dword & F_Nqual))
  131.  
  132. /*
  133.  * Length of string.
  134.  */
  135. #define StrLen(q)    ((q).dword)
  136.  
  137. /*
  138.  * Location of first character of string.
  139.  */
  140. #define StrLoc(q)    ((q).vword.sptr)
  141.  
  142. /*
  143.  * Assign a C string to a descriptor. Assume it is reasonable to use the
  144.  *   descriptor expression more than once, but not the string expression.
  145.  */
  146. #define AsgnCStr(d,s) (StrLoc(d) = (s), StrLen(d) = strlen(StrLoc(d)))
  147.  
  148. /*
  149.  * Type of descriptor.
  150.  */
  151. #define Type(d)        (int)((d).dword & TypeMask)
  152.  
  153. /*
  154.  * Check for variable.
  155.  */
  156. #define Var(d)        ((d).dword & F_Var)
  157.  
  158. /*
  159.  * Location of the value of a variable.
  160.  */
  161. #define VarLoc(d)    ((d).vword.descptr)
  162.  
  163. /*
  164.  *  Important note:  The code that follows is not strictly legal C.
  165.  *   It tests to see if pointer p2 is between p1 and p3. This may
  166.  *   involve the comparison of pointers in different arrays, which
  167.  *   is not well-defined.  The casts of these pointers to unsigned "words"
  168.  *   (longs or ints, depending) works with all C compilers and architectures
  169.  *   on which Icon has been implemented.  However, it is possible it will
  170.  *   not work on some system.  If it doesn't, there may be a "false
  171.  *   positive" test, which is likely to cause a memory violation or a
  172.  *   loop. It is not practical to implement Icon on a system on which this
  173.  *   happens.
  174.  */
  175.  
  176. #define InRange(p1,p2,p3) ((uword)(p2) >= (uword)(p1) && (uword)(p2) < (uword)(p3))
  177.  
  178. /*
  179.  * Get floating-point number from real block.
  180.  */
  181. #ifdef Double
  182. #define GetReal(dp,res) *((struct size_dbl *)&(res)) =\
  183.       *((struct size_dbl *)&(BlkLoc(*dp)->realblk.realval))
  184. #else                    /* Double */
  185. #define GetReal(dp,res)    res = BlkLoc(*dp)->realblk.realval
  186. #endif                    /* Double */
  187.  
  188. /*
  189.  * Absolute value of x (word).
  190.  */
  191. #if (MVS || VM) && SASC
  192. #define Abs(x) __builtin_abs(x)
  193. #else                    /* SASC */
  194. #define Abs(x) (((x) < 0) ? (-(x)) : (x))
  195. #endif                    /* SASC */
  196.  
  197. /*
  198.  * Maximum of x and y.
  199.  */
  200. #define Max(x,y)        ((x)>(y)?(x):(y))
  201. #if (MVS || VM) && SASC
  202. #undef Max
  203. #define Max(x,y)     __builtin_max(x,y)
  204. #endif                    /* SASC */
  205.  
  206. /*
  207.  * Minimum of x and y.
  208.  */
  209. #define Min(x,y)        ((x)<(y)?(x):(y))
  210. #if (MVS || VM) && SASC
  211. #undef Min
  212. #define Min(x,y)     __builtin_min(x,y)
  213. #endif                    /* SASC */
  214.  
  215. /*
  216.  * Number of elements of a C array, and element size.
  217.  */
  218. #define ElemCount(a) (sizeof(a)/sizeof(a[0]))
  219. #define ElemSize(a) (sizeof(a[0]))
  220.  
  221. /*
  222.  * Some C compilers take '\n' and '\r' to be the same, so the
  223.  *  following definitions are used.
  224.  */
  225. #if EBCDIC
  226. /*
  227.  * Note that, in EBCDIC, "line feed" and "new line" are distinct
  228.  *  characters.  Icon's use of "line feed" is really "new line" in
  229.  *  C terms.
  230.  */
  231. #define LineFeed '\n' /* if really "line feed", that's 37 */
  232. #define CarriageReturn '\r'
  233. #else                    /* EBCDIC */
  234. #define LineFeed  10
  235. #define CarriageReturn 13
  236. #endif                    /* EBCDIC */
  237.  
  238. /*
  239.  * Construct an integer descriptor.
  240.  */
  241. #define MakeInt(i,dp)        do { \
  242.                       (dp)->dword = D_Integer; \
  243.                          IntVal(*dp) = (word)(i); \
  244.              } while (0)
  245.  
  246. /*
  247.  * Construct a string descriptor.
  248.  */
  249. #define MakeStr(s,len,dp)      do { \
  250.                       StrLoc(*dp) = (s); \
  251.                          StrLen(*dp) = (len); \
  252.              } while (0)
  253.  
  254. /*
  255.  * Offset in word of cset bit.
  256.  */
  257. #define CsetOff(b)    ((b) & BitOffMask)
  258. /*
  259.  * Set bit b in cset c.
  260.  */
  261. #define Setb(b,c)    (*CsetPtr(b,c) |= (01 << CsetOff(b)))
  262. /*
  263.  * Test bit b in cset c.
  264.  */
  265. #define Testb(b,c)    ((*CsetPtr(b,c) >> CsetOff(b)) & 01)
  266. /*
  267.  * Check whether a set or table needs resizing.
  268.  */
  269. #define SP(p) ((struct b_set *)p)
  270. #define TooCrowded(p) \
  271.    ((SP(p)->size > MaxHLoad*(SP(p)->mask+1)) && (SP(p)->hdir[HSegs-1] == NULL))
  272. #define TooSparse(p) \
  273.    ((SP(p)->hdir[1] != NULL) && (SP(p)->size < MinHLoad*(SP(p)->mask+1)))
  274. /*
  275.  * Definitions and declarations used for storage management.
  276.  */
  277.  
  278. #define F_Mark        0100000     /* bit for marking blocks */
  279.  
  280. /*
  281.  * Argument values for the built-in Icon user function "collect()".
  282.  */
  283. #define Static  1            /* collection is for static region */
  284. #define Strings    2            /* collection is for strings */
  285. #define Blocks    3            /* collection is for blocks */
  286.  
  287. /*
  288.  * Get type of block pointed at by x.
  289.  */
  290. #define BlkType(x)   (*(word *)x)
  291.  
  292. /*
  293.  * BlkSize(x) takes the block pointed to by x and if the size of
  294.  *  the block as indicated by bsizes[] is nonzero it returns the
  295.  *  indicated size; otherwise it returns the second word in the
  296.  *  block contains the size.
  297.  */
  298. #define BlkSize(x) (bsizes[*(word *)x & ~F_Mark] ? \
  299.              bsizes[*(word *)x & ~F_Mark] : *((word *)x + 1))
  300.  
  301. /*
  302.  * Here are the events we support (in addition to keyboard characters)
  303.  */
  304. #define MOUSELEFT    (-1)
  305. #define MOUSEMID    (-2)
  306. #define MOUSERIGHT    (-3)
  307. #define MOUSELEFTUP    (-4)
  308. #define MOUSEMIDUP    (-5)
  309. #define MOUSERIGHTUP    (-6)
  310. #define MOUSELEFTDRAG    (-7)
  311. #define MOUSEMIDDRAG    (-8)
  312. #define MOUSERIGHTDRAG    (-9)
  313. #define RESIZED        (-10)
  314. #define LASTEVENTCODE    RESIZED
  315.  
  316. /*
  317.  * Type codes (descriptors and blocks).
  318.  */
  319. #define T_String    -1    /* string -- for reference; not used */
  320. #define T_Null         0    /* null value */
  321. #define T_Integer     1    /* integer */
  322.  
  323. #ifdef LargeInts
  324. #define T_Lrgint     2    /* long integer */
  325. #endif                    /* LargeInts */
  326.  
  327. #define T_Real         3    /* real number */
  328. #define T_Cset         4    /* cset */
  329. #define T_File         5    /* file */
  330. #define T_Proc         6    /* procedure */
  331. #define T_Record     7    /* record */
  332. #define T_List         8    /* list header */
  333. #define T_Lelem         9    /* list element */
  334. #define T_Set        10    /* set header */
  335. #define T_Selem        11    /* set element */
  336. #define T_Table        12    /* table header */
  337. #define T_Telem        13    /* table element */
  338. #define T_Tvtbl        14    /* table element trapped variable */
  339. #define T_Slots        15    /* set/table hash slots */
  340. #define T_Tvsubs    16    /* substring trapped variable */
  341. #define T_Refresh    17    /* refresh block */
  342. #define T_Coexpr    18    /* co-expression */
  343. #define T_External    19    /* external block */
  344. #define T_Kywdint    20    /* integer keyword */
  345. #define T_Kywdpos    21    /* keyword &pos */
  346. #define T_Kywdsubj    22    /* keyword &subject */
  347. #define T_Kywdwin    23    /* keyword &window */
  348. #define T_Kywdstr    24    /* string keyword */
  349. #define T_Kywdevent    25    /* keyword &eventsource, etc. */
  350.  
  351. #define MaxType        26    /* maximum type number */
  352.  
  353. /*
  354.  * Definitions for keywords.
  355.  */
  356.  
  357. #define k_pos kywd_pos.vword.integr    /* value of &pos */
  358. #define k_random kywd_ran.vword.integr    /* value of &random */
  359. #define k_trace kywd_trc.vword.integr    /* value of &trace */
  360. #define k_dump kywd_dmp.vword.integr    /* value of &dump */
  361.  
  362. #ifdef FncTrace
  363. #define k_ftrace kywd_ftrc.vword.integr    /* value of &ftrace */
  364. #endif                    /* FncTrace */
  365.  
  366. /*
  367.  * Descriptor types and flags.
  368.  */
  369.  
  370. #define D_Null        (T_Null     | D_Typecode)
  371. #define D_Integer    (T_Integer  | D_Typecode)
  372.  
  373. #ifdef LargeInts
  374. #define D_Lrgint    (T_Lrgint | D_Typecode | F_Ptr)
  375. #endif                    /* LargeInts */
  376.  
  377. #define D_Real        (T_Real     | D_Typecode | F_Ptr)
  378. #define D_Cset        (T_Cset     | D_Typecode | F_Ptr)
  379. #define D_File        (T_File     | D_Typecode | F_Ptr)
  380. #define D_Proc        (T_Proc     | D_Typecode | F_Ptr)
  381. #define D_List        (T_List     | D_Typecode | F_Ptr)
  382. #define D_Lelem        (T_Lelem    | D_Typecode | F_Ptr)
  383. #define D_Table        (T_Table    | D_Typecode | F_Ptr)
  384. #define D_Telem        (T_Telem    | D_Typecode | F_Ptr)
  385. #define D_Set        (T_Set      | D_Typecode | F_Ptr)
  386. #define D_Selem        (T_Selem    | D_Typecode | F_Ptr)
  387. #define D_Record    (T_Record   | D_Typecode | F_Ptr)
  388. #define D_Tvsubs    (T_Tvsubs   | D_Typecode | F_Ptr | F_Var)
  389. #define D_Tvtbl        (T_Tvtbl    | D_Typecode | F_Ptr | F_Var)
  390. #define D_Kywdint    (T_Kywdint  | D_Typecode | F_Ptr | F_Var)
  391. #define D_Kywdpos    (T_Kywdpos  | D_Typecode | F_Ptr | F_Var)
  392. #define D_Kywdsubj    (T_Kywdsubj | D_Typecode | F_Ptr | F_Var)
  393. #define D_Refresh    (T_Refresh  | D_Typecode | F_Ptr)
  394. #define D_Coexpr    (T_Coexpr   | D_Typecode | F_Ptr)
  395. #define D_External    (T_External | D_Typecode | F_Ptr)
  396. #define D_Slots        (T_Slots    | D_Typecode | F_Ptr)
  397. #define D_Kywdwin    (T_Kywdwin  | D_Typecode | F_Ptr | F_Var)
  398. #define D_Kywdstr    (T_Kywdstr  | D_Typecode | F_Ptr | F_Var)
  399. #define D_Kywdevent    (T_Kywdevent| D_Typecode | F_Ptr | F_Var)
  400.  
  401. #define D_Var        (F_Var | F_Nqual | F_Ptr)
  402. #define D_Typecode    (F_Nqual | F_Typecode)
  403.  
  404. #define TypeMask    63    /* type mask */
  405. #define OffsetMask    (~(D_Var)) /* offset mask for variables */
  406.  
  407. /*
  408.  * "In place" dereferencing.
  409.  */
  410. #define Deref(d) if (Var(d)) deref(&d, &d)
  411.  
  412. /*
  413.  * Construct a substring trapped variable.
  414.  */
  415. #define SubStr(dest,var,len,pos)\
  416.    if ((var)->dword == D_Tvsubs)\
  417.       (dest)->vword.bptr = (union block *)alcsubs(len, (pos) +\
  418.          BlkLoc(*(var))->tvsubs.sspos - 1, &BlkLoc(*(var))->tvsubs.ssvar);\
  419.    else\
  420.       (dest)->vword.bptr = (union block *)alcsubs(len, pos, (var));\
  421.    (dest)->dword = D_Tvsubs;
  422.  
  423. /*
  424.  * Find debug struct in procedure frame, assuming debugging is enabled.
  425.  *  Note that there is always one descriptor in array even if it is not
  426.  *  being used.
  427.  */
  428. #define PFDebug(pf) ((struct debug *)((char *)(pf).tend.d +\
  429.     sizeof(struct descrip) * ((pf).tend.num ? (pf).tend.num : 1)))
  430.  
  431. /*
  432.  * Macro for initialized procedure block.
  433.  */
  434. #ifdef MultiThread
  435. #define B_IProc(n) struct {word title; word blksize; int (*ccode)();\
  436.    word nparam; word ndynam; word nstatic; word fstatic; struct progstate *p;\
  437.    struct sdescrip quals[n];}
  438. #else                    /* MultiThread */
  439. #define B_IProc(n) struct {word title; word blksize; int (*ccode)();\
  440.    word nparam; word ndynam; word nstatic; word fstatic;\
  441.    struct sdescrip quals[n];}
  442. #endif                    /* MultiThread */
  443.  
  444. #define ssize    (curstring->size)
  445. #define strbase  (curstring->base)
  446. #define strend   (curstring->end)
  447. #define strfree  (curstring->free)
  448.  
  449. #define abrsize  (curblock->size)
  450. #define blkbase  (curblock->base)
  451. #define blkend   (curblock->end)
  452. #define blkfree  (curblock->free)
  453.  
  454. #if COMPILER
  455.  
  456. #ifdef Graphics
  457. #define Poll() if (!pollctr--) pollctr = pollevent()
  458. #else                    /* Graphics */
  459. #define Poll()
  460. #endif                    /* Graphics */
  461.  
  462. #else                    /* COMPILER */
  463.  
  464. /*
  465.  * Definitions for the interpreter.
  466.  */
  467.  
  468.  
  469. /*
  470.  * Codes returned by invoke to indicate action.
  471.  */
  472. #define I_Builtin    201    /* A built-in routine is to be invoked */
  473. #define I_Fail        202    /* goal-directed evaluation failed */
  474. #define I_Continue    203    /* Continue execution in the interp loop */
  475. #define I_Vararg    204    /* A function with a variable number of args */
  476.  
  477. /*
  478.  * Generator types.
  479.  */
  480. #define G_Csusp        1
  481. #define G_Esusp        2
  482. #define G_Psusp        3
  483. #define G_Fsusp        4
  484. #define G_Osusp        5
  485.  
  486.  
  487. /*
  488.  * Evaluation stack overflow margin
  489.  */
  490.  
  491. #define PerilDelta 100
  492.  
  493. /*
  494.  * Macro definitions related to descriptors.
  495.  */
  496.  
  497. /*
  498.  * The following code is operating-system dependent [@rt.01].  Define
  499.  *  PushAval for computers that store longs and pointers differently.
  500.  */
  501.  
  502. #if PORT
  503. #define PushAVal(x) PushVal(x)
  504. Deliberate Syntax Error
  505. #endif                    /* PORT */
  506.  
  507. #if AMIGA || ARM || ATARI_ST || MACINTOSH || MVS || UNIX || VM || VMS
  508. #define PushAVal(x) PushVal(x)
  509. #endif                    /* AMIGA || ARM || ATARI_ST ... */
  510.  
  511. #if MSDOS || OS2
  512. #if HIGHC_386 || ZTC_386 || INTEL_386 || WATCOM || BORLAND_386 || SCCX_MX
  513. #define PushAVal(x) PushVal(x)
  514. #else                    /* HIGHC_386 || ZTC_386 || ... */
  515. static union {
  516.        pointer stkadr;
  517.        word stkint;
  518.    } stkword;
  519.  
  520. #define PushAVal(x)  {sp++; \
  521.             stkword.stkadr = (char *)(x); \
  522.             *sp = stkword.stkint;}
  523. #endif                    /* HIGHC_386 || ZTC_386 || ... */
  524. #endif                    /* MSDOS || OS2 */
  525.  
  526. /*
  527.  * End of operating-system specific code.
  528.  */
  529.  
  530. /*
  531.  * Macros for pushing values on the interpreter stack.
  532.  */
  533.  
  534. /*
  535.  * Push descriptor.
  536.  */
  537. #define PushDesc(d)    {*++sp = ((d).dword); sp++;*sp =((d).vword.integr);}
  538.  
  539. /*
  540.  * Push null-valued descriptor.
  541.  */
  542. #define PushNull    {*++sp = D_Null; sp++; *sp = 0;}
  543.  
  544. /*
  545.  * Push word.
  546.  */
  547. #define PushVal(v)    {*++sp = (word)(v);}
  548.  
  549. /*
  550.  * Macros related to function and operator definition.
  551.  */
  552.  
  553. /*
  554.  * Procedure block for a function.
  555.  */
  556.  
  557.  
  558. #if VMS
  559. #ifdef MultiThread
  560. #define FncBlock(f,nargs,deref) \
  561.     struct b_iproc Cat(B,f) = {\
  562.     T_Proc,\
  563.     Vsizeof(struct b_proc),\
  564.     Cat(Y,f),\
  565.     nargs,\
  566.     -1,\
  567.     deref, 0,\
  568.     0,\
  569.     {sizeof(Lit(f))-1,Lit(f)}};
  570. #else                    /* MultiThread */
  571. #define FncBlock(f,nargs,deref) \
  572.     struct b_iproc Cat(B,f) = {\
  573.     T_Proc,\
  574.     Vsizeof(struct b_proc),\
  575.     Cat(Y,f),\
  576.     nargs,\
  577.     -1,\
  578.     deref, 0,\
  579.     {sizeof(Lit(f))-1,Lit(f)}};
  580. #endif                    /* MultiThread */
  581. #else                    /* VMS */
  582. #ifdef MultiThread
  583. #define FncBlock(f,nargs,deref) \
  584.     struct b_iproc Cat(B,f) = {\
  585.     T_Proc,\
  586.     Vsizeof(struct b_proc),\
  587.     Cat(Z,f),\
  588.     nargs,\
  589.     -1,\
  590.     deref, 0,\
  591.     0,\
  592.     {sizeof(Lit(f))-1,Lit(f)}};
  593. #else                    /* MultiThread */
  594. #define FncBlock(f,nargs,deref) \
  595.     struct b_iproc Cat(B,f) = {\
  596.     T_Proc,\
  597.     Vsizeof(struct b_proc),\
  598.     Cat(Z,f),\
  599.     nargs,\
  600.     -1,\
  601.     deref, 0,\
  602.     {sizeof(Lit(f))-1,Lit(f)}};
  603. #endif                    /* MultiThread */
  604. #endif                    /* VMS */
  605.  
  606. /*
  607.  * Procedure block for an operator.
  608.  */
  609. #ifdef MultiThread
  610. #define OpBlock(f,nargs,sname,xtrargs)\
  611.     struct b_iproc Cat(B,f) = {\
  612.     T_Proc,\
  613.     Vsizeof(struct b_proc),\
  614.     Cat(O,f),\
  615.     nargs,\
  616.     -1,\
  617.     xtrargs,\
  618.     0,\
  619.     0,\
  620.     {sizeof(sname)-1,sname}};
  621. #else                    /* MultiThread */
  622. #define OpBlock(f,nargs,sname,xtrargs)\
  623.     struct b_iproc Cat(B,f) = {\
  624.     T_Proc,\
  625.     Vsizeof(struct b_proc),\
  626.     Cat(O,f),\
  627.     nargs,\
  628.     -1,\
  629.     xtrargs,\
  630.     0,\
  631.     {sizeof(sname)-1,sname}};
  632. #endif                    /* MultiThread */
  633.  
  634. /*
  635.  * Operator declaration.
  636.  */
  637. #define OpDcl(nm,n,pn) OpBlock(nm,n,pn,0) Cat(O,nm)(cargp) register dptr cargp;
  638.  
  639. /*
  640.  * Operator declaration with extra working argument.
  641.  */
  642. #define OpDclE(nm,n,pn) OpBlock(nm,-n,pn,0) Cat(O,nm)(cargp) register dptr cargp;
  643.  
  644. /*
  645.  * Agent routine declaration.
  646.  */
  647. #define AgtDcl(nm) Cat(A,nm)(cargp) register dptr cargp;
  648.  
  649. /*
  650.  * Macros to access Icon arguments in C functions.
  651.  */
  652.  
  653. /*
  654.  * n-th argument.
  655.  */
  656. #define Arg(n)         (cargp[n])
  657.  
  658. /*
  659.  * Type field of n-th argument.
  660.  */
  661. #define ArgType(n)    (cargp[n].dword)
  662.  
  663. /*
  664.  * Value field of n-th argument.
  665.  */
  666. #define ArgVal(n)    (cargp[n].vword.integr)
  667.  
  668. /*
  669.  * Specific arguments.
  670.  */
  671. #define Arg0    (cargp[0])
  672. #define Arg1    (cargp[1])
  673. #define Arg2    (cargp[2])
  674. #define Arg3    (cargp[3])
  675. #define Arg4    (cargp[4])
  676. #define Arg5    (cargp[5])
  677. #define Arg6    (cargp[6])
  678. #define Arg7    (cargp[7])
  679. #define Arg8    (cargp[8])
  680.  
  681. /* Suspend has been eliminated.  I dare not axe the Xver. */
  682.  
  683. /* Forward is no more. This is an Xfer placeholder */
  684.  
  685. /*
  686.  * Miscellaneous macro definitions.
  687.  */
  688.  
  689. #ifdef MultiThread
  690. #define kywd_err  (curpstate->Kywd_err)
  691. #define kywd_pos  (curpstate->Kywd_pos)
  692. #define kywd_prog  (curpstate->Kywd_prog)
  693. #define kywd_ran  (curpstate->Kywd_ran)
  694. #define k_eventcode (curpstate->eventcode)
  695. #define k_eventsource (curpstate->eventsource)
  696. #define k_eventvalue (curpstate->eventval)
  697. #define k_subject (curpstate->ksub)
  698. #define kywd_trc  (curpstate->Kywd_trc)
  699. #define mainhead (curpstate->Mainhead)
  700. #define code (curpstate->Code)
  701. #define records (curpstate->Records)
  702. #define ftabp (curpstate->Ftabp)
  703. #define fnames (curpstate->Fnames)
  704. #define efnames (curpstate->Efnames)
  705. #define globals (curpstate->Globals)
  706. #define eglobals (curpstate->Eglobals)
  707. #define gnames (curpstate->Gnames)
  708. #define egnames (curpstate->Egnames)
  709. #define statics (curpstate->Statics)
  710. #define estatics (curpstate->Estatics)
  711. #define n_globals (curpstate->NGlobals)
  712. #define n_statics (curpstate->NStatics)
  713. #define strcons (curpstate->Strcons)
  714. #define filenms (curpstate->Filenms)
  715. #define efilenms (curpstate->Efilenms)
  716. #define ilines (curpstate->Ilines)
  717. #define elines (curpstate->Elines)
  718. #define current_line_ptr (curpstate->Current_line_ptr)
  719.  
  720. #ifdef Graphics
  721. #define amperX   (curpstate->AmperX)
  722. #define amperY   (curpstate->AmperY)
  723. #define amperRow (curpstate->AmperRow)
  724. #define amperCol (curpstate->AmperCol)
  725. #define amperInterval (curpstate->AmperInterval)
  726. #define lastEventWin (curpstate->LastEventWin)
  727. #define lastEvFWidth (curpstate->LastEvFWidth)
  728. #define lastEvLeading (curpstate->LastEvLeading)
  729. #define lastEvAscent (curpstate->LastEvAscent)
  730. #define kywd_xwin (curpstate->Kywd_xwin)
  731. #define xmod_control (curpstate->Xmod_Control)
  732. #define xmod_shift (curpstate->Xmod_Shift)
  733. #define xmod_meta (curpstate->Xmod_Meta)
  734. #endif                    /* Graphics */
  735.  
  736. #ifdef EventMon
  737. #define linenum  (curpstate->Linenum)
  738. #define column   (curpstate->Column)
  739. #define lastline (curpstate->Lastline)
  740. #define lastcol  (curpstate->Lastcol)
  741. #endif                    /* EventMon */
  742.  
  743. #define coexp_ser (curpstate->Coexp_ser)
  744. #define list_ser  (curpstate->List_ser)
  745. #define set_ser   (curpstate->Set_ser)
  746. #define table_ser (curpstate->Table_ser)
  747.  
  748. #define curstring (curpstate->stringregion)
  749. #define curblock  (curpstate->blockregion)
  750. #define strtotal  (curpstate->stringtotal)
  751. #define blktotal  (curpstate->blocktotal)
  752.  
  753. #define coll_tot  (curpstate->colltot)
  754. #define coll_stat (curpstate->collstat)
  755. #define coll_str  (curpstate->collstr)
  756. #define coll_blk  (curpstate->collblk)
  757.  
  758. #define lastop    (curpstate->Lastop)
  759.  
  760. #define xargp     (curpstate->Xargp)
  761. #define xnargs    (curpstate->Xnargs)
  762.  
  763. #define k_errornumber (curpstate->K_errornumber)
  764. #define k_errortext   (curpstate->K_errortext)
  765. #define k_errorvalue  (curpstate->K_errorvalue)
  766. #define have_errval   (curpstate->Have_errval)
  767. #define t_errornumber (curpstate->T_errornumber)
  768. #define t_have_val    (curpstate->T_have_val)
  769. #define t_errorvalue  (curpstate->T_errorvalue)
  770.  
  771. #define k_main        (curpstate->K_main)
  772. #define k_errout      (curpstate->K_errout)
  773. #define k_input       (curpstate->K_input)
  774. #define k_output      (curpstate->K_output)
  775.  
  776. #define ENTERPSTATE(p) if (((p)!=NULL)) { curpstate = (p); }
  777. #endif                    /* MultiThread */
  778.  
  779. #endif                    /* COMPILER */
  780. /*
  781.  * Constants controlling expression evaluation.
  782.  */
  783. #if COMPILER
  784. #define A_Resume    -1    /* expression failed: resume a generator */
  785. #define A_Continue      -2    /* expression returned: continue execution */
  786. #define A_FallThru      -3      /* body function: fell through end of code */
  787. #define A_Coact        1    /* co-expression activation */
  788. #define A_Coret        2    /* co-expression return */
  789. #define A_Cofail    3    /* co-expression failure */
  790. #else                    /* COMPILER */
  791. #define A_Resume    1        /* routine failed */
  792. #define A_Pret_uw    2        /* interp unwind for Op_Pret */
  793. #define A_Unmark_uw    3        /* interp unwind for Op_Unmark */
  794. #define A_Pfail_uw    4        /* interp unwind for Op_Pfail */
  795. #define A_Lsusp_uw    5        /* interp unwind for Op_Lsusp */
  796. #define A_Eret_uw    6        /* interp unwind for Op_Eret */
  797. #define A_Continue    7        /* routine returned */
  798. #define A_Coact        8        /* co-expression activated */
  799. #define A_Coret        9        /* co-expression returned */
  800. #define A_Cofail    10        /* co-expression failed */
  801. #ifdef MultiThread
  802. #define A_MTEvent    11        /* multithread event */
  803. #endif                    /* MultiThread */
  804. #endif                    /* COMPILER */
  805.  
  806. /*
  807.  * Address of word containing cset bit b (c is a struct descrip of type Cset).
  808.  */
  809. #define CsetPtr(b,c)    (BlkLoc(c)->cset.bits + (((b)&0377) >> LogIntBits))
  810.  
  811. #if MSDOS
  812. #if (MICROSOFT && defined(M_I86HM)) || (TURBO && defined(__HUGE__))
  813. #define ptr2word(x) ((uword)((char huge *)x - (char huge *)zptr))
  814. #define word2ptr(x) ((char huge *)((char huge *)zptr + (uword)x))
  815. #else                    /* MICROSOFT ... */
  816. #define ptr2word(x) (uword)x
  817. #define word2ptr(x) ((char *)x)
  818. #endif                    /* MICROSOFT ... */
  819. #endif                    /* MSDOS */
  820.