home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 223_02 / cc.def < prev    next >
Text File  |  1989-02-23  |  11KB  |  374 lines

  1. /*
  2. ** Small-C Compiler Version 2.7    (modified by Fred A. Scacchitti 3/26/86)
  3. **
  4. ** Copyright 1982, 1983 J. E. Hendrix
  5. **
  6. **
  7. **
  8. **
  9. ** Version 2.6 -> 2.7 Changes           F. A. Scacchitti 3/25/86
  10. **
  11. **
  12. ** - New runtime library (RDRTL) for use with compiler and to support
  13. **   redirected output to a file. ( write > and append >> modes )
  14. **   Supports  8 - 1k file buffers.
  15. **   Misc. bugs cleared up.
  16. **
  17. ** - New I/O library (CLIB) improved size/performance with new
  18. **   available features. (statics and ? : operator)
  19. **   Added getkbd(), putcrt() to get around redirection if desired.
  20. **   Misc. bugs cleared up inc. JEH's #60
  21. **
  22. **   added nested include files, up to 6 deep
  23. **    - CC1.C  int input2[6], inclevel
  24. **    - CC11.C main()
  25. **    - CC12.C doinclude()
  26. **    - CC2.C  extern int input2[6], inclevel
  27. **    - CC21.C inline()
  28. **
  29. **   fixed minor bug in doasm() undid JEH's 49
  30. **    - CC13.C doasm()
  31. **
  32. **
  33. ** Version 2.5 -> 2.6 Changes           F. A. Scacchitti 3/21/86
  34. **
  35. **
  36. ** - added global multidimensional arrays  eg. ara[5] [5], c[4] [3] [5] 
  37. **     - CC.DEF Multidimmensional Array Macros
  38. **               added AINDEX to symbol table macros
  39. **     - CC1.C added *sarrptr, *arrptr, *arrcount, to track and
  40. **              control array usage
  41. **     - CC11.C main()
  42. **     - CC12.C declglb(), newfunc()
  43. **     - CC3.C ext int *sarrptr, *arrptr, arrcount
  44. **     - CC32.C hier14()
  45. **    - CC41.C swap2() eliminate bad optimization for MDA's
  46. **     - CC42.C getmd()  the code generator
  47. ** 
  48. ** - upgraded main() syntax to optimize compiler operation
  49. **     - CC1.C changed argvs[MAXARGS] to argvs
  50. **     - CC11.C main() installed standard syntax
  51. **
  52. **
  53. ** Version 2.4 -> 2.5 Changes        F. A. Scacchitti 3/6/86
  54. **
  55. **
  56. ** - added arrays of pointers eg. *argv[], ***ptr[]
  57. **     - CC12.C declglb(), decloc(), doargs(), newfunc()
  58. **     - CC12.C removed paerror()  (undid JEH's #53)
  59. ** 
  60. ** - added octal and hex constants eg 0377, 0777, 0xff, 0X12ab
  61. **     - CC33.C number()
  62. **
  63. **
  64. ** Version 2.3 -> 2.4 Changes        F. A. Scacchitti 3/4/86
  65. **
  66. **
  67. ** - added type FILE
  68. **     - stdio.h
  69. ** - restore original type at end of pointer queue for type char
  70. **     - CC1.C char explevel
  71. **     - CC12.C doargs()
  72. **     - CC3.C ext char explevel()
  73. **     - CC31.C expression(), hier12()
  74. **     - CC4.C ext char explevel()
  75. **     - CC41.C indirect(), putstk()
  76. **
  77. **
  78. ** Version 2.2 -> 2.3 Changes        F. A. Scacchitti 2/24/86
  79. **
  80. **
  81. ** - added J. E. Hendrix's fixes 
  82. **     - #61 Increase number and size of allowed macros
  83. ** 
  84. ** - added mutiple levels of indirection eg. **argv, ***ptr
  85. **     - CC.DEF modified symbol table format (added LEVEL, ITYPE)
  86. **     - CC1.C char level, itype
  87. **     - CC12.C declglb(), decloc(), doargs(), newfunc()
  88. **     - CC13.C addlabel()
  89. **     - CC21.C addsym()
  90. **     - CC3.C ext char level, itype
  91. **     - CC32.C primary()
  92. **     -    NOT 100% for lowest level for type char
  93. **
  94. **
  95. ** Version 2.1 -> 2.2 Changes        F. A. Scacchitti 2/17/86
  96. **
  97. **
  98. ** - changed the following to better conform to CP/M environment
  99. **   to conform to my runtime environment
  100. **     - newline character back to CR (undid 45)
  101. **     - new ask()
  102. **     - new openin() & xgets() replaces openfile() & mustopen()
  103. **     - new doinclude()
  104. **     - allow listfp to display listings (undid 48)
  105. **
  106. ** - added -i option to initialize to zero only when directed
  107. **     - CC1.C char iflag, CC11.C ask(), dumpzero()
  108. **     - CC4.C ext char iflag
  109. ** 
  110. ** - added -n option to allow return to CCP if desired
  111. **     - CC1.C char nbflg, CC11.C ask()
  112. **     - CC4.C ext char nbflg, CC41.C trailer()
  113. ** 
  114. ** - added TYPE statics to allow nonglobal static variables
  115. **     - CC1.C char m80flg, CC11.C ask(), parse()
  116. **     - CC4.C ext char m80flg, CC41.C entry()
  117. ** 
  118. ** - added the conditional operator {exp1 ? exp2 : exp3}
  119. **     - CC31.C hier1(), ducon()
  120. **
  121. ** - added J. E. Hendrix's newsletter fixes 
  122. **     - #59 CC32.C fix optimize error
  123. **     - #64 CC31.C fix assignment error
  124. **
  125. **
  126. ** Version 2.0 -> 2.1 Change Record
  127. **     (primed numbers keyed to text)
  128. ** 01' fix bogus label generated by "continue" within "switch"
  129. **     (A. Macpherson)
  130. ** 02' fix problem of "peephole" missing end of staging buffer
  131. **     (E. Payne & A. Macpherson)
  132. ** 03' permit (*func)() syntax for functions as arguments
  133. **     (E. Payne)
  134. ** 04  change spelling of "heir" to "hier"
  135. ** 05  change spelling of "plunge" to "plnge"
  136. ** 06  always compile function "upper"
  137. ** 07' allow smaller NAMEMAX/NAMESIZE w/o truncating keywords
  138. **     (E. Payne)
  139. ** 08' disallow local declarations inside "switch" statements
  140. ** 09' make "outdec" handle the constant 32768 properly
  141. ** 10  change CCALLOC() to calloc()
  142. ** 11  change CCAVAIL() to avail()
  143. ** 12  change CCPOLL() to poll()
  144. ** 13' install (*func)() syntax
  145. ** 14' correct extraneous operand fetch in expressions
  146. **     like (i+5)();
  147. ** 15' make expressions like (&ia[...] - &ia[...]) scale
  148. **     properly to give the number of objects lying between
  149. ** 16' eliminate "DW 0" generated by "int (*func)();"
  150. ** 17' "fclose" should return NULL or ERR like UNIX
  151. ** 18' "fflush" should return NULL or EOF like UNIX
  152. ** 19' "fgets" should return the newline like UNIX
  153. ** 20' remove redundant loop from "inline"  (E. Payne)
  154. ** 21  rename functions (e.g., or(), and(),
  155. **     ret(), call(), etc.) to avoid M80 reserved words
  156. ** 22  shorten CCDDPDPI and CCDDPDPC to 6 characters
  157. **     to satisfy L80 and LIB
  158. ** 23' use NEWLINE symbol for newline value
  159. ** 24' fix pstr() end-of-line problem
  160. **     (A. Macpherson & M. Grundy)
  161. ** 25' allocate space for local pointer declared as ptr[]
  162. **     (A. Macpherson)
  163. ** 26' make primary() recognize expression strings
  164. **     (A. Macpherson)
  165. ** 27  alter code generation for M80, L80
  166. ** 28' use double colon to declare entry points
  167. ** 29  employ standard functions isalpha(), isdigit(),
  168. **     and toupper()
  169. ** 30' drop bad optimizing case from peephole(),
  170. **     per Paul West (DDJ #81)
  171. ** 31' supply argument for avail() to abort on stack
  172. **     overflow
  173. ** 32' prevent preprocess() from taking newline as
  174. **     white space
  175. ** 33' always declare "_link" external in LINK mode
  176. **     to force loading of required library functions
  177. ** 34' restrict doubling of constants operating on
  178. **     integer addresses to add and subtract operators
  179. ** 35' use XRA A to pass an argument count of zero
  180. **     per Paul West (DDJ #81)
  181. ** 36' improve indirect function calls per Paul West (DDJ #81)
  182. ** 37' automatically declare undeclared functions to be
  183. **     external
  184. ** 38  drop support of sequential macro and global table
  185. **     searching
  186. ** 39' provide a default extension of .C to input file
  187. **     names, and assume an output .MAC file if stdout
  188. **     has not been redirected to a disk file
  189. ** 40  drop support of parameter prompting and drop
  190. **     CMD_LINE
  191. ** 41  drop external function declarations from
  192. **     cc1.c, cc2.c, cc3.c, and cc4.c
  193. ** 42' begin execution at main() rather than first function
  194. ** 43  drop tabs from the output
  195. ** 44  always compile calls to poll() in the compiler
  196. ** 47' accept #include "...." or <....> constructs
  197. ** 48' show even #asm input in the listing and prevent an
  198. **     extra ";" at the end of the output from commenting
  199. **     out the first EXT
  200. ** 49' correct double spacing in the output during
  201. **     #asm ... #endasm intervals
  202. ** 50' correct lingering problem with correctly performing
  203. **     operand fetches for indirect function calls
  204. ** 51' correct bad syntax in trailer() if LINK not defined
  205. ** 52' init locptr before first function so something like
  206. **     "int ia[x];" where x is not #defined won't hang
  207. ** 53' generate error on attempt to declare pointer arrays
  208. ** 54' generate "EXT _link" only if "main()" is defined
  209. ** 55' eliminate redundant code generated at the end of a
  210. **     compound statement
  211. ** 56  change system global names from leading _ to U to
  212. **     accommodate users with pre 3.44 MACRO-80 packages
  213. **
  214. */
  215.  
  216. /*
  217. ** compile options
  218. */
  219. #define NOCCARGC /* no argument counts */
  220. #define SEPARATE /* compile separately */
  221. #define OPTIMIZE /* compile output optimizer */
  222. #define DYNAMIC  /* allocate memory dynamically */
  223. #define COL      /* terminate labels with a colon */
  224. /* #define UPPER    /* force symbols to upper case */
  225. #define LINK     /* will use with linking loader */
  226.  
  227. /*
  228. ** machine dependent parameters
  229. */
  230. #define BPW     2   /* bytes per word */
  231. #define LBPW    1   /* log2(BPW) */
  232. #define SBPC    1   /* stack bytes per character */
  233. #define ERRCODE 7   /* op sys return code */
  234.  
  235. /*
  236. ** symbol table format
  237. */
  238. #define IDENT    0
  239. #define TYPE     1
  240. #define CLASS    2
  241. #define LEVEL    3                    /* fas 2.3 */
  242. #define ITYPE    4                    /* fas 2.3 */
  243. #define AINDEX   5                    /* fas 2.6 */
  244. #define OFFSET   6                    /* fas 2.6 */
  245. #define NAME     8                    /* fas 2.6 */
  246. #define OFFSIZE (NAME-OFFSET)                
  247. #define SYMAVG  15                    /* fas 2.6 */
  248. #define SYMMAX  17                    /* fas 2.6 */
  249.  
  250. /*
  251. ** symbol table parameters
  252. */
  253. #define NUMLOCS   25
  254. #define STARTLOC  symtab
  255. #define ENDLOC   (symtab+(NUMLOCS*SYMAVG))
  256. #define NUMGLBS   200
  257. #define STARTGLB  ENDLOC
  258. #define ENDGLB   (ENDLOC+((NUMGLBS-1)*SYMMAX))
  259. #define SYMTBSZ   3775  /* NUMLOCS*SYMAVG + NUMGLBS*SYMMAX   fas 2.4 */ 
  260.  
  261. /*
  262. ** multidimensional array  parameters            fas 2.6
  263. */
  264. #define MAXELMNTS   8
  265. #define MAXARRAYS   10 + 1         /* 1 dummy */
  266. #define ARRINDEX    MAXELMNTS
  267. #define MDASIZE     MAXELMNTS * MAXARRAYS 
  268.  
  269. /*
  270. ** System wide name size (for symbols)
  271. */
  272. #define NAMESIZE 9
  273. #define NAMEMAX  8
  274.  
  275. /*
  276. ** possible entries for "IDENT"
  277. */
  278. #define LABEL    0
  279. #define VARIABLE 1
  280. #define ARRAY    2
  281. #define POINTER  3
  282. #define FUNCTION 4
  283.  
  284. /*
  285. ** possible entries for "TYPE" or "ITYPE"
  286. **    low order 2 bits make type unique within length
  287. **    high order bits give length of object
  288. */
  289. /*      LABEL   0 */
  290. #define CCHAR   (1<<2)
  291. #define CINT    (BPW<<2)
  292.  
  293. /*
  294. ** possible entries for "CLASS"
  295. */
  296. /*      LABEL     0 */
  297. #define STATIC    1
  298. #define AUTOMATIC 2
  299. #define EXTERNAL  3
  300. #define AUTOEXT   4         /*37*/
  301.  
  302. /*
  303. ** "switch" table
  304. */
  305.  
  306. #define SWSIZ   (2*BPW)
  307. #define SWTABSZ (60*SWSIZ)
  308.  
  309. /*
  310. ** "while" statement queue
  311. */
  312. #define WQTABSZ  30
  313. #define WQSIZ     3
  314. #define WQMAX   (wq+WQTABSZ-WQSIZ)
  315.  
  316. /*
  317. ** entry offsets in while queue
  318. */
  319. #define WQSP    0
  320. #define WQLOOP  1
  321. #define WQEXIT  2
  322.  
  323. /*
  324. ** literal pool
  325. */
  326. #define LITABSZ 800
  327. #define LITMAX  (LITABSZ-1)
  328.  
  329. /*
  330. ** input line
  331. */
  332. #define LINEMAX  127
  333. #define LINESIZE 128
  334.  
  335. /*
  336. ** output staging buffer size
  337. */
  338. #define STAGESIZE   800
  339. #define STAGELIMIT  (STAGESIZE-1)
  340.  
  341. /*
  342. ** macro (define) pool
  343. */
  344. #define MACNBR   130
  345. #define MACNSIZE (MACNBR*(NAMESIZE+2))
  346. #define MACNEND  (macn+MACNSIZE)
  347. #define MACQSIZE (MACNBR*7)
  348. #define MACMAX  (MACQSIZE-1)
  349.  
  350. /*
  351. ** statement types
  352. */
  353. #define STIF      1
  354. #define STWHILE   2
  355. #define STRETURN  3
  356. #define STBREAK   4
  357. #define STCONT    5
  358. #define STASM     6
  359. #define STEXPR    7
  360. #define STDO      8 /* compile "do" logic */
  361. #define STFOR     9 /* compile "for" logic */
  362. #define STSWITCH 10 /* compile "switch/case/default" logic */
  363. #define STCASE   11
  364. #define STDEF    12
  365. #define STGOTO   13 /* compile "goto" logic */
  366. #define STLABEL  14 /*55*/
  367.  
  368. /*
  369. ** command line
  370. */
  371.  
  372. #define MAXARGS 24
  373.  
  374.