cref.doc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. .ll 72
  2. .nr ID 4
  3. .de hd
  4. 'sp 2
  5. 'tl ''-%-''
  6. 'sp 3
  7. ..
  8. .de fo
  9. 'bp
  10. ..
  11. .tr ~
  12. . TITLE
  13. .de TL
  14. .sp 15
  15. .ce
  16. \\fB\\$1\\fR
  17. ..
  18. . AUTHOR
  19. .de AU
  20. .sp 15
  21. .ce
  22. by
  23. .sp 2
  24. .ce
  25. \\$1
  26. ..
  27. . DATE
  28. .de DA
  29. .sp 3
  30. .ce
  31. ( Dated \\$1 )
  32. ..
  33. . INSTITUTE
  34. .de VU
  35. .sp 3
  36. .ce 4
  37. Wiskundig Seminarium
  38. Vrije Universteit
  39. De Boelelaan 1081
  40. Amsterdam
  41. ..
  42. . PARAGRAPH
  43. .de PP
  44. .sp
  45. .ti +\n(ID
  46. ..
  47. .nr CH 0 1
  48. . CHAPTER
  49. .de CH
  50. .nr SH 0 1
  51. .bp
  52. .in 0
  53. \\fB\\n+(CH.~\\$1\\fR
  54. .PP
  55. ..
  56. . SUBCHAPTER
  57. .de SH
  58. .sp 3
  59. .in 0
  60. \\fB\\n(CH.\\n+(SH.~\\$1\\fR
  61. .PP
  62. ..
  63. . INDENT START
  64. .de IS
  65. .sp
  66. .in +\n(ID
  67. ..
  68. . INDENT END
  69. .de IE
  70. .in -\n(ID
  71. .sp
  72. ..
  73. .de PT
  74. .ti -\n(ID
  75. .ta \n(ID
  76. .fc " @
  77. "\\$1@"\c
  78. .fc
  79. ..
  80. . DOUBLE INDENT START
  81. .de DS
  82. .sp
  83. .in +\n(ID
  84. .ll -\n(ID
  85. ..
  86. . DOUBLE INDENT END
  87. .de DE
  88. .ll +\n(ID
  89. .in -\n(ID
  90. .sp
  91. ..
  92. . EQUATION START
  93. .de EQ
  94. .sp
  95. .nf
  96. ..
  97. . EQUATION END
  98. .de EN
  99. .fi
  100. .sp
  101. ..
  102. . ITEM
  103. .de IT
  104. .sp
  105. .in 0
  106. \\fB~\\$1\\fR
  107. .ti +5
  108. ..
  109. .de CS
  110. .br
  111. ~-~\\
  112. ..
  113. .br
  114. .fi
  115. .TL "Ack-C reference manual"
  116. .AU "Ed Keizer"
  117. .DA "September 12, 1983"
  118. .VU
  119. .wh 0 hd
  120. .wh 60 fo
  121. .CH "Introduction"
  122. The C frontend included in the Amsterdam Compiler Kit
  123. translates UNIX-V7 C into compact EM code [1].
  124. The language accepted is described in [2] and [3].
  125. This document describes which implementation dependent choices were
  126. made in the Ack-C frontend and
  127. some restrictions and additions.
  128. .CH "The language"
  129. .PP
  130. Under the same heading as used in [2] we describe the
  131. properties of the Ack-C frontend.
  132. .IT "2.2 Identifiers"
  133. External identifiers are unique up to 7 characters and allow
  134. both upper and lower case.
  135. .IT "2.4.3 Character constants"
  136. The ASCII-mapping is used when a character is converted to an
  137. integer.
  138. .IT "2.4.4 Floating constants"
  139. To prevent loss of precision the compiler does not perform
  140. floating point constant folding.
  141. .IT "2.6 Hardware characteristics"
  142. The size of objects of the several arithmetic types and the two
  143. pointer types depend on the EM-implementation used.
  144. The ranges of the arithmetic types depend on the size used,
  145. the C-frontend assumes two's complement representation for the
  146. integral types. All sizes are multiples of bytes.
  147. The calling program \fIack\fP[4] passes information about the
  148. size of the types to the compiler proper.
  149. .br
  150. However, a few general remarks must be made:
  151. .sp 1
  152. .IS
  153. .PT (a)
  154. Two different pointer types exist: pointers to data and
  155. pointers to functions.
  156. The latter type is twice as large as the former.
  157. Pointers to functions use the same format as Pascal procedure
  158. parameters, thereby allowing C to use Pascal procedure
  159. parameters and vice-versa.
  160. The extra information passed indicates the scope level of the
  161. procedure.
  162. .PT (b)
  163. The size of pointers to data is a multiple of
  164. (or equal to) the size of an \fIint\fP.
  165. .PT (c)
  166. The following relations exist for the sizes of the types
  167. mentioned:
  168. .br
  169. .ti +5
  170. \fIchar<=short<=int<=long\fP
  171. .PT (d)
  172. Objects of type \fIchar\fP use one 8-bit byte of storage,
  173. although several bytes are allocated sometimes.
  174. .PT (e)
  175. All sizes are in multiples of bytes.
  176. .PT (f)
  177. Most EM implementations use 4 bytes for floats and 8 bytes
  178. for doubles, but exceptions to this rule occur.
  179. .IE
  180. .IT "6.1 Characters and integers"
  181. Objects of type \fIchar\fP are unsigned and do not cause
  182. sign-extension when converted to \fIint\fP.
  183. The range of characters values is from 0 to 255.
  184. .IT "6.3 Floating and integral"
  185. Floating point numbers are truncated towards zero when
  186. converted to the integral types.
  187. .IT "6.4 Pointers and integers"
  188. When a \fIlong\fP is added to or subtracted from a pointer and
  189. longs are larger then data pointers the \fIlong\fP is converted to an
  190. \fIint\fP before the operation is performed.
  191. .IT "8.5 Structure and union declarations"
  192. The only type allowed for fields is \fIint\fP.
  193. Fields with exactly the size of \fIint\fP are signed,
  194. all other fields are unsigned.
  195. .br
  196. The size of any single structure must be less then 4096 bytes.
  197. .IT "8.6 Initialization"
  198. Initialization of structures containing bit fields is not
  199. allowed.
  200. There is one restriction when using an 'address expression' to initialize
  201. an integral variable.
  202. The integral variable must have the size of a data pointer.
  203. Conversions altering the size of the address expression are not allowed.
  204. .IT "10.1 External function definitions"
  205. The total amount for storage used for parameters
  206. in any function must be less then 4096 bytes.
  207. The same holds for the total amount of storage occupied by the
  208. automatic variables declared inside any function.
  209. .sp
  210. Using formal parameters whose size is smaller the the size of an int
  211. is less efficient on several machines.
  212. At procedure entry these parameters are converted from integer to the
  213. declared type, because the compiler doesn't know where the least
  214. significant bytes are stored in the int.
  215. .IT "11.2 Scope of externals"
  216. Most C compilers are rather lax in enforcing the restriction
  217. that only one external definition without the keyword
  218. \fIextern\fP is allowed in a program.
  219. The Ack-C frontend is very strict in this.
  220. The only exception is that declarations of arrays with a
  221. missing first array bounds expression are regarded to have an
  222. explicit keyword \fIextern\fP.
  223. .IT "14.4 Explicit pointer conversions"
  224. Pointers may be larger the ints, thus assigning a pointer to an
  225. int and back will not always result in the same pointer.
  226. The process mentioned above works with integrals
  227. of the same size or larger as pointers in all EM implementations
  228. having such integrals.
  229. Note that pointers to functions have
  230. twice the size of pointers to data.
  231. When converting data pointers to an integral type or vice-versa,
  232. the pointers is seen as an unsigned with the same size a data-pointer.
  233. When converting function pointers to anything else the static link part
  234. of the pointer is discarded,
  235. the resulting value is treated as if it were a data pointer.
  236. When converting a data pointer or object of integral type to a function pointer
  237. a static link with the value 0 is added to complete the function pointer.
  238. .br
  239. EM guarantees that any object can be placed at a word boundary,
  240. this allows the C-programs to use \fIint\fP pointers
  241. as pointers to objects of any type not smaller than an \fIint\fP.
  242. .CH "Frontend options"
  243. The C-frontend has a few options, these are controlled
  244. by flags:
  245. .IS
  246. .PT -V
  247. This flag is followed by a sequence of letters each followed by
  248. positive integers. Each letter indicates a
  249. certain type, the integer following it specifies the size of
  250. objects of that type. One letter indicates the wordsize used.
  251. .IS
  252. .sp 1
  253. .TS
  254. center tab(:);
  255. l l16 l l.
  256. letter:type:letter:type
  257. w:wordsize:i:int
  258. s:short:l:long
  259. f:float:d:double
  260. p:pointer::
  261. .TE
  262. .sp 1
  263. All existing implementations use an integer size equal to the
  264. wordsize.
  265. .IE
  266. The calling program \fIack\fP[4] provides the frontend with
  267. this flag, with values depending on the machine used.
  268. .sp 1
  269. .PT -l
  270. The frontend normally generates code to keep track of the line
  271. number and source file name at runtime for debugging purposes.
  272. Currently a pointer to a
  273. string containing the filename is stored at a fixed place in
  274. memory at each function
  275. entry and the line number at the start of every expression.
  276. At the return from a function these memory locations are not reset to
  277. the values they had before the call.
  278. Most library routines do not use this feature and thus do not
  279. ruin the current line number and filename when called.
  280. However, you are really unlucky when your program crashes due
  281. to a bug in such a library function, because the line number
  282. and filename do not indicate that something went wrong inside
  283. the library function.
  284. .br
  285. Providing the flag -l to the frontend tells it not to generate
  286. the code updating line number and file name.
  287. This is, for example, used when translating the stdio library.
  288. .br
  289. When the \fIack\fP[4] is called with the -L flag it provides
  290. the frontend with this flag.
  291. .sp 1
  292. .PT -Xp
  293. When this flag is present the frontend generates a call to
  294. the function \fBprocentry\fP at each function entry and a
  295. call to \fBprocexit\fP at each function exit.
  296. Both functions are provided with one parameter,
  297. a pointer to a string containing the function name.
  298. .br
  299. When \fIack\fP is called with the -p flag it provides the
  300. frontend with this flag.
  301. .IE
  302. .CH References
  303. .IS
  304. .PT [1]
  305. A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan
  306. Stevenson \fIDescription of a machine architecture for use with
  307. block structured languages\fP Informatica report IR-81.
  308. .sp 1
  309. .PT [2]
  310. B.W. Kernighan and D.M. Ritchie, \fIThe C Programming
  311. language\fP, Prentice-Hall, 1978
  312. .PT [3]
  313. D.M. Ritchie, \fIC Reference Manual\fP
  314. .sp
  315. .PT [4]
  316. UNIX manual ack(I).