pcref.doc 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. .\" $Id$
  2. .\" tbl pcref.doc | troff
  3. .ds OF \\fBtest~off:~\\fR
  4. .ds ON \\fBtest~on:~~\\fR
  5. .ds AL \\fBtest~all:~\\fR
  6. .ll 72n
  7. .wh 0 hd
  8. .wh 60 fo
  9. .de hd
  10. 'sp 5
  11. ..
  12. .de fo
  13. 'bp
  14. ..
  15. .tr ~
  16. . TITLE
  17. .de TL
  18. .sp 10
  19. .ce
  20. \\fB\\$1\\fR
  21. .sp 10
  22. ..
  23. . AUTHOR
  24. .de AU
  25. .ce
  26. by
  27. .sp 2
  28. .ce
  29. \\$1
  30. ..
  31. . OTHER AUTHOR
  32. .de OA
  33. .sp 2
  34. .ce
  35. (revised)
  36. .sp 2
  37. .ce
  38. \\$1
  39. ..
  40. . DATE
  41. .de DA
  42. .sp 1
  43. .ce
  44. ( \\$1 )
  45. ..
  46. . INSTITUTE
  47. .de VU
  48. .sp 3
  49. .ce 4
  50. Vakgroep Informatica
  51. Vrije Universiteit
  52. De Boelelaan 1081
  53. Amsterdam
  54. ..
  55. . PARAGRAPH
  56. .de PP
  57. .sp
  58. .ti +5
  59. ..
  60. .nr CH 0 1
  61. . CHAPTER
  62. .de CH
  63. .nr SH 0 1
  64. .bp
  65. .in 0
  66. \\fB\\n+(CH.~\\$1\\fR
  67. .PP
  68. ..
  69. . SUBCHAPTER
  70. .de SH
  71. .sp 3
  72. .in 0
  73. \\fB\\n(CH.\\n+(SH.~\\$1\\fR
  74. .PP
  75. ..
  76. . INDENT START
  77. .de IS
  78. .sp
  79. .in +5
  80. ..
  81. . INDENT END
  82. .de IE
  83. .in -5
  84. .sp
  85. ..
  86. . DOUBLE INDENT START
  87. .de DS
  88. .sp
  89. .in +5
  90. .ll -5
  91. ..
  92. . DOUBLE INDENT END
  93. .de DE
  94. .ll +5
  95. .in -5
  96. .sp
  97. ..
  98. . EQUATION START
  99. .de EQ
  100. .sp
  101. .nf
  102. ..
  103. . EQUATION END
  104. .de EN
  105. .fi
  106. .sp
  107. ..
  108. . ITEM
  109. .de IT
  110. .sp
  111. .in 0
  112. \\fBBS~\\$1:\\fR~\\
  113. ..
  114. .de CS
  115. .br
  116. ~-~\\
  117. ..
  118. .br
  119. .fi
  120. .TL "Amsterdam Compiler Kit-Pascal reference manual"
  121. .AU "Johan W. Stevenson"
  122. .DA "January 4, 1983"
  123. .OA "Hans van Eck"
  124. .DA "May 1, 1989"
  125. .VU
  126. .CH "Introduction"
  127. This document refers to the (1982) BSI standard for Pascal [1].
  128. Ack-Pascal complies with the requirements of level 1 of BS 6192: 1982, with
  129. the exceptions as listed in this document.
  130. .PP
  131. The standard requires an accompanying document describing the
  132. implementation-defined and implementation-dependent features,
  133. the reaction on errors and the extensions to standard Pascal.
  134. These four items will be treated in the rest of this document,
  135. each in a separate chapter.
  136. The other chapters describe the deviations from the standard and
  137. the list of options recognized by the compiler.
  138. .PP
  139. The Ack-Pascal compiler produces code for an EM machine as defined in [2].
  140. It is up to the implementor of the EM machine to decide whether errors like
  141. integer overflow, undefined operand and range bound error are recognized or not.
  142. .PP
  143. There does not (yet) exist a hardware EM machine.
  144. Therefore, EM programs must be interpreted, or translated into
  145. instructions for a target machine.
  146. The Ack-Pascal compiler is currently available for use with the VAX,
  147. Motorola MC68020, Motorola MC68000,
  148. PDP-11, and Intel 8086 code-generators.
  149. For the 8086, MC68000, and MC68020,
  150. floating point emulation is used. This is made available with the \fI-fp\fP
  151. option, which must be passed to \fIack\fP[3].
  152. .IE
  153. .CH "Implementation-defined features"
  154. For each implementation-defined feature mentioned in the BSI standard
  155. we give the section number, the quotation from that section and the definition.
  156. First we quote the definition of implementation-defined:
  157. .DS
  158. Possibly differing between processors, but defined for any particular
  159. processor.
  160. .DE
  161. .IT 6.1.7
  162. Each string-character shall denote an implementation-defined value of the
  163. required char-type.
  164. .IS
  165. All 7-bits ASCII characters except linefeed LF (10) are allowed.
  166. .IE
  167. .IT 6.4.2.2
  168. The values of type real shall be an implementation-defined subset
  169. of the real numbers denoted as specified by 6.1.5 bu signed real.
  170. .IS
  171. The format of reals is not defined in EM.
  172. Even the size of reals depends on the EM-implementation.
  173. The compiler can be instructed, by the V-option, to use a different
  174. size for real values.
  175. The size of reals is preset by the calling program \fIack\fP
  176. [3] to the proper size.
  177. .IE
  178. .IT 6.4.2.2
  179. The type char shall be the enumeration of a set of implementation-defined
  180. characters, some possibly without graphic representations.
  181. .IS
  182. The 7-bits ASCII character set is used, where LF (10) denotes the
  183. end-of-line marker on text-files.
  184. .IT 6.4.2.2
  185. The ordinal numbers of the character values shall be values of integer-type,
  186. that are implementation-defined, and that are determined by mapping
  187. the character values on to consecutive non-negative integer values
  188. starting at zero.
  189. .IS
  190. The normal ASCII ordering is used: ord('0')=48, ord('A')=65, ord('a')=97, etc.
  191. .IE
  192. .IT 6.6.5.2
  193. The post-assertions imply corresponding activities on the external entities,
  194. if any, to which the file-variables are bound. These activities, and the
  195. point at which they are actually performed, shall be
  196. implementation-defined.
  197. .IS
  198. The reading and writing writing of objects on files is buffered.
  199. This means that when a program terminates abnormally, IO may be
  200. unfinished. Terminal IO is unbuffered.
  201. Files are closed whenever they are rewritten or reset, or on
  202. program termination.
  203. .IT 6.7.2.2
  204. The predefined constant maxint shall be of integer-type and shall denote
  205. an implementation-defined value, that satisfies the following conditions:
  206. .sp 1
  207. .in +5
  208. .ti -4
  209. (a)~All integral values in the closed interval from -maxint to +maxint
  210. shall be values of the integer-type.
  211. .ti -4
  212. (b)~Any monadic operation performed on an integer value in this interval
  213. shall be correctly performed according to the mathematical rules for
  214. integer arithmetic.
  215. .ti -4
  216. (c)~Any dyadic integer operation on two integer values in this same interval
  217. shall be correctly performed according to the mathematical rules for
  218. integer arithmetic, provided that the result is also in this interval.
  219. .ti -4
  220. (d)~Any relational operation on two integer values in this same interval
  221. shall be correctly performed according to the mathematical rules for
  222. integer arithmetic.
  223. .in -5
  224. .IS
  225. The representation of integers in EM is a \fIn\fP*8-bit word using
  226. two's complement arithmetic.
  227. Where \fIn\fP is called wordsize.
  228. The range of available integers depends on the EM implementation:
  229. For 2-byte machines, the integers range from -32767 to +32767. For 4-byte
  230. machines, the integers range from -2147483647 to 2147483647.
  231. The number -maxint-1 may be used to indicate 'undefined'.
  232. .IE
  233. .IT 6.7.2.2
  234. The result of the real arithmetic operators and functions shall be
  235. approximations to the corresponding mathematical results. The accuracy of
  236. this approximation shall be implementation-defined
  237. .IS
  238. Since EM doesn't specify floating point format, it is not possible to
  239. specify the accuracy. When the floating point emulation is used, and the
  240. default size of reals is 8 bytes, the accuracy is 11 bits for the exponent,
  241. and 53 bits for the mantissa. This gives an accuracy of about 16 digits,
  242. and exponents ranging from -309 to +307.
  243. .IE
  244. .IT 6.9.3.1
  245. The default TotalWidth values for integer, Boolean and real types
  246. shall be implementation-defined.
  247. .IS
  248. The defaults are:
  249. integer 6 for 2-byte machines, 11 for 4-byte machines
  250. Boolean 5
  251. real 14
  252. .IT 6.9.3.4.1
  253. ExpDigits, the number of digits written in an exponent part of a real,
  254. shall be implementation-defined.
  255. .IS
  256. ExpDigits is defined as 3. This is sufficient for all implementations
  257. currently available. When the representation would need more than 3
  258. digits, then the string '***' replaces the exponent.
  259. .IT 6.9.3.4.1
  260. The character written as part of the representation of
  261. a real to indicate the beginning of the exponent part shall be
  262. implementation-defined, either 'E' or 'e'.
  263. .IS
  264. The exponent part starts with 'e'.
  265. .IT 6.9.3.5
  266. The case of the characters written as representation of the
  267. Boolean values shall be implementation-defined.
  268. .IS
  269. The representations of true and false are 'true' and 'false'.
  270. .IT 6.9.5
  271. The effect caused by the standard procedure page
  272. on a text file shall be implementation-defined.
  273. .IS
  274. The ASCII character form feed FF (12) is written.
  275. .IT 6.10
  276. The binding of the variables denoted by the program-parameters
  277. to entities external to the program shall be implementation-defined if
  278. the variable is of a file-type.
  279. .IS
  280. The program parameters must be files and all, except input and output,
  281. must be declared as such in the program block.
  282. .PP
  283. The program parameters input and output, if specified, will correspond
  284. with the UNIX streams 'standard input' and 'standard output'.
  285. .PP
  286. The other program parameters will be mapped to the argument strings
  287. provided by the caller of this program.
  288. The argument strings are supposed to be path names of the files to be
  289. opened or created.
  290. The order of the program parameters determines the mapping:
  291. the first parameter is mapped onto the first argument string etc.
  292. Note that input and output are ignored in this mapping.
  293. .PP
  294. The mapping is recalculated each time a program parameter
  295. is opened for reading or writing by a call to the standard procedures
  296. reset or rewrite.
  297. This gives the programmer the opportunity to manipulate the list
  298. of string arguments using the external procedures argc, argv and argshift
  299. available in libpc [6].
  300. .IT 6.10
  301. The effect of an explicit use of reset or rewrite
  302. on the standard textfiles input or output shall be implementation-defined.
  303. .IS
  304. The procedures reset and rewrite are no-ops
  305. if applied to input or output.
  306. .CH "Implementation-dependent features"
  307. For each implementation-dependent feature mentioned in the BSI standard,
  308. we give the section number, the quotation from that section and the way
  309. this feature is treated by the Ack-Pascal system.
  310. First we quote the definition of 'implementation-dependent':
  311. .DS
  312. Possibly differing between processors and not necessarily defined for any
  313. particular processor.
  314. .DE
  315. .IT 6.7.2.1
  316. The order of evaluation of the operands of a dyadic operator
  317. shall be implementation-dependent.
  318. .IS
  319. Operands are always evaluated, so the program part
  320. .EQ
  321. if (p<>nil) and (p^.value<>0) then
  322. .EN
  323. is probably incorrect.
  324. .PP
  325. The left-hand operand of a dyadic operator is almost always evaluated
  326. before the right-hand side.
  327. Some peculiar evaluations exist for the following cases:
  328. .IS
  329. .ti -3
  330. 1.~\
  331. the modulo operation is performed by a library routine to
  332. check for negative values of the right operand.
  333. .sp
  334. .ti -3
  335. 2.~\
  336. the expression
  337. .EQ
  338. set1 <= set2
  339. .EN
  340. where set1 and set2 are compatible set types is evaluated in the
  341. following steps:
  342. .IS
  343. .CS
  344. evaluate set2
  345. .CS
  346. evaluate set1
  347. .CS
  348. compute set2+set1
  349. .CS
  350. test set2 and set2+set1 for equality
  351. .IE
  352. .sp
  353. .ti -3
  354. 3.~\
  355. the expression
  356. .EQ
  357. set1 >= set2
  358. .EN
  359. where set1 and set2 are compatible set types is evaluated in the following steps:
  360. .IS
  361. .CS
  362. evaluate set1
  363. .CS
  364. evaluate set2
  365. .CS
  366. compute set1+set2
  367. .CS
  368. test set1 and set1+set2 for equality
  369. .IE
  370. .IE
  371. .IT 6.7.3
  372. The order of evaluation, accessing and binding
  373. of the actual-parameters for functions
  374. shall be implementation-dependent.
  375. .IS
  376. The order of evaluation is from right to left.
  377. .IT 6.8.2.2
  378. The decision as to the order of accessing the variable and evaluating
  379. the expression in an assignment-statement, shall be
  380. implementation-dependent.
  381. .IS
  382. The expression is evaluated first.
  383. .IT 6.8.2.3
  384. The order of evaluation and binding of the actual-parameters for procedures
  385. shall be implementation-dependent.
  386. .IS
  387. The same as for functions.
  388. .IT 6.9.5
  389. The effect of inspecting a text file to which the page
  390. procedure was applied during generation is
  391. implementation-dependent.
  392. .IS
  393. The formfeed character written by page is
  394. treated like a normal character, with ordinal value 12.
  395. .IT 6.10
  396. The binding of the variables denoted by the program-parameters
  397. to entities external to the program shall be implementation-dependent unless
  398. the variable is of a file-type.
  399. .IS
  400. Only variables of a file-type are allowed as program parameters.
  401. .IE
  402. .CH "Error handling"
  403. There are three classes of errors to be distinguished.
  404. In the first class are the error messages generated by the compiler.
  405. The second class consists of the occasional errors generated by the other
  406. programs involved in the compilation process.
  407. Errors of the third class are the errors as defined in the standard by:
  408. .DS
  409. An error is a violation by a program of the requirements of this standard
  410. that a processor is permitted to leave undetected.
  411. .DE
  412. .SH "Compiler errors"
  413. Error are written on the standard error output. Each line has the form:
  414. .br
  415. <file>, line <number>: <description>
  416. .br
  417. Every time the compiler detects an error that does not have influence
  418. on the code produced by the compiler or on the syntax decisions, a warning
  419. messages is given.
  420. If only warnings are generated, compilation proceeds and probably results
  421. in a correctly compiled program.
  422. .PP
  423. Sometimes the compiler produces several errors for the same line. They are
  424. only shown up to a maximum of 5 errors per line. Warning are also shown up
  425. to a maximum of 5 per line.
  426. .PP
  427. Extensive treatment of these errors is outside the scope of this manual.
  428. .SH "Runtime errors"
  429. Errors detected at run time cause an error message to be generated on the
  430. diagnostic output stream (UNIX file descriptor 2).
  431. The message consists of the name of the program followed by a message
  432. describing the error, possibly followed by the source line number.
  433. Unless the -L-option is turned on, the compiler generates code to keep track
  434. of which source line causes which EM instructions to be generated.
  435. It depends on the EM implementation whether these LIN instructions
  436. are skipped or executed.
  437. .PP
  438. For each error mentioned in the standard we give the section number,
  439. the quotation from that section and the way it is processed by the
  440. Pascal-compiler or runtime system.
  441. .PP
  442. For detected errors the corresponding message
  443. and trap number are given.
  444. Trap numbers are useful for exception-handling routines.
  445. Normally, each error causes the program to terminate.
  446. By using exception-handling routines one can
  447. ignore errors or perform alternate actions.
  448. Only some of the errors can be ignored
  449. by restarting the failing instruction.
  450. These errors are marked as non-fatal,
  451. all others as fatal.
  452. A list of errors with trap number between 0 and 63
  453. (EM errors) can be found in [2].
  454. Errors with trap number between 64 and 127 (Pascal errors) are listed in [7].
  455. .IT 6.4.6
  456. It shall be an error if a value of type T2 must be
  457. assignment-compatible with type T1, while
  458. T1 and T2 are compatible ordinal-types and the value of
  459. type T2 is not in the closed interval specified by T1.
  460. .IS
  461. The compiler distinguishes between array-index expressions and the other
  462. places where assignment-compatibility is required.
  463. .PP
  464. Array subscripting is done using the EM array instructions.
  465. These instructions have three arguments: the array base address,
  466. the index and the address of the array descriptor.
  467. An array descriptor describes one dimension by three values:
  468. the lower bound on the index, the number of elements minus one and the
  469. element-size.
  470. It depends on the EM implementation whether these bounds are checked. Since
  471. most implementations don't, an extra compiler flag is added to force these
  472. checks.
  473. .br
  474. The other places where assignment-compatibility is required are:
  475. .IS
  476. .CS
  477. assignment
  478. .CS
  479. value parameters
  480. .CS
  481. procedures read and readln
  482. .CS
  483. the final value of the for-statement
  484. .IE
  485. For these places the compiler generates an EM range check instruction, except
  486. when the R-option is turned on, or when the range of values of T2
  487. is enclosed in the range of T1.
  488. If the expression consists of a single variable and if that variable
  489. is of a subrange type,
  490. then the subrange type itself is taken as T2, not its host-type.
  491. Therefore, a range instruction is only generated if T1 is a subrange type
  492. and if the expression is a constant, an expression with two or more
  493. operands, or a single variable with a type not enclosed in T1.
  494. If a constant is assigned, then the EM optimizer removes the range check
  495. instruction, except when the value is out of bounds.
  496. .PP
  497. It depends on the EM implementation whether the range check instruction
  498. is executed or skipped.
  499. .IT 6.4.6
  500. It shall be an error if a value of type T2 must be
  501. assignment-compatible with type T1, while T1 and T2 are compatible
  502. set-types and any member of the value of type T2
  503. is not in the closed interval specified by the base-type
  504. of the type T1.
  505. .IS
  506. This error is not detected.
  507. .IT 6.5.3.3
  508. It shall be an error if a component of a variant-part of a variant,
  509. where the selector of the variant-part is not a field,
  510. is accessed unless the variant is active for the entirety of each
  511. reference and access to each component of the variant.
  512. .IS
  513. This error is not detected.
  514. .IT 6.5.4
  515. It shall be an error if
  516. the pointer-variable of an identified-variable either denotes a
  517. nil-value or is undefined.
  518. .IS
  519. The EM definition does not specify the binary representation of pointer
  520. values, so that it is not possible to choose an otherwise illegal
  521. binary representation for the pointer value NIL.
  522. Rather arbitrary the compiler uses the integer value zero to represent NIL.
  523. For all current implementations this does not cause problems.
  524. .PP
  525. The size of pointers depends on the implementation and is
  526. preset in the compiler by \fIack\fP [3].
  527. The compiler can be instructed, by the V-option, to use
  528. another size for pointer objects.
  529. NIL is represented here by the appropriate number of zero words.
  530. .PP
  531. It depends on the EM implementation whether de-referencing of a pointer
  532. with value NIL causes an error.
  533. .IE
  534. .IT 6.5.4
  535. It shall be an error to remove the identifying-value of an identified
  536. variable from its pointer-type when a reference to the variable exists.
  537. .IS
  538. When the identified variable is an element of the record-variable-list of
  539. a with_statement, a warning is given at compile-time. Otherwise, this error
  540. is not detected.
  541. .IT 6.5.5
  542. It shall be an error to alter the value of a file-variable f when a
  543. reference to the buffer-variable f^ exists.
  544. .IS
  545. When f is altered when it is an element of the record-variable-list of a
  546. with-statement, a warning is given. When a buffer-variable is used as a
  547. variable-parameter, an error is given. This is done at compile-time.
  548. .IT 6.6.5.2
  549. It shall be an error if
  550. the stated pre-assertion does not hold immediately
  551. prior to any use of the file handling procedures
  552. rewrite, put, reset and get.
  553. .IS
  554. For each of these four operations the pre-assertions
  555. can be reformulated as:
  556. .sp
  557. rewrite(f):~no pre-assertion.
  558. .br
  559. put(f):~~~~~f is opened for writing and f^ is not undefined.
  560. .br
  561. reset(f):~~~f exists.
  562. .br
  563. get(f):~~~~~f is opened for reading and eof(f) is false.
  564. .sp
  565. The following errors are detected for these operations:
  566. .sp
  567. rewrite(f):
  568. .in +10
  569. .ti -5
  570. more args expected, trap 64, fatal:
  571. .br
  572. f is a program-parameter and the corresponding
  573. file name is not supplied by the caller of the program.
  574. .ti -5
  575. rewrite error, trap 101, fatal:
  576. .br
  577. the caller of the program lacks the necessary
  578. access rights to create the file in the file system
  579. or operating system problems like table overflow
  580. prevent creation of the file.
  581. .in -10
  582. .sp
  583. put(f):
  584. .in +10
  585. .ti -5
  586. file not yet open, trap 72, fatal:
  587. .br
  588. reset or rewrite are never applied to the file.
  589. The checks performed by the run time system are not foolproof.
  590. .ti -5
  591. not writable, trap 96, fatal:
  592. .br
  593. f is opened for reading.
  594. .ti -5
  595. write error, trap 104, fatal:
  596. .br
  597. probably caused by file system problems.
  598. For instance, the file storage is exhausted.
  599. Because IO is buffered to improve performance,
  600. it might happen that this error occurs if the
  601. file is closed.
  602. Files are closed whenever they are rewritten or reset, or on
  603. program termination.
  604. .in -10
  605. .sp
  606. reset(f):
  607. .in +10
  608. .ti -5
  609. more args expected, trap 64, fatal:
  610. .br
  611. same as for rewrite(f).
  612. .ti -5
  613. reset error, trap 100, fatal:
  614. .br
  615. f does not exist, or the caller has insufficient access rights, or
  616. operating system tables are exhausted.
  617. .in -10
  618. .sp
  619. get(f):
  620. .in +10
  621. .ti -5
  622. file not yet open, trap 72, fatal:
  623. .br
  624. as for put(f).
  625. .ti -5
  626. not readable, trap 97, fatal:
  627. .br
  628. f is opened for writing.
  629. .ti -5
  630. end of file, trap 98, fatal:
  631. .br
  632. eof(f) is true just before the call to get(f).
  633. .ti -5
  634. read error, trap 103, fatal:
  635. .br
  636. unlikely to happen. Probably caused by hardware problems
  637. or by errors elsewhere in the program that destroyed
  638. the file information maintained by the run time system.
  639. .ti -5
  640. truncated, trap 99, fatal:
  641. .br
  642. the file is not properly formed by an integer
  643. number of file elements.
  644. For instance, the size of a file of integer is odd.
  645. .ti -5
  646. non-ASCII char read, trap 106, non-fatal:
  647. .br
  648. the character value of the next character-type
  649. file element is out of range (0..127).
  650. Only for text files.
  651. .in -10
  652. .IT 6.6.5.3
  653. It shall be an error if a variant of a variant-part within the new
  654. variable becomes active and a different variant of the variant-part is
  655. one of the specified variants.
  656. .IS
  657. This error is not detected.
  658. .IT 6.6.5.3
  659. It shall be an error to use dispose(q) if the identifying variable has been
  660. allocated using the form new(p,c1,...,cn).
  661. .IS
  662. This error is not detected. However, this error can cause more memory
  663. to be freed then was allocated.
  664. Dispose causes a fatal trap 73 when memory already on the free
  665. list is freed again.
  666. .IT 6.6.5.3
  667. It shall be an error to use dispose(q,k1,...,km) if the identifying
  668. variable has been allocated using the form new(p,c1,...,cn) and m is not
  669. equal to n.
  670. .IS
  671. This error is not detected. However, this error can cause more memory
  672. to be freed then was allocated.
  673. Dispose causes a fatal trap 73 when memory already on the free
  674. list is freed again.
  675. .IT 6.6.5.3
  676. It shall be an error if the variants of a variable to be disposed
  677. are different from those specified by the case-constants to dispose.
  678. .IS
  679. This error is not detected.
  680. .IT 6.6.5.3
  681. It shall be an error if the value of the pointer parameter of dispose has
  682. nil-value or is undefined.
  683. .IS
  684. The same comments apply as for de-referencing NIL or undefined pointers.
  685. .IT 6.6.5.3
  686. It shall be an error if a variable created using the second form of new is
  687. accessed by the identified variable of the variable-access of a factor,
  688. of an assignment-statement, or of an actual-parameter.
  689. .IS
  690. This error is not detected.
  691. .IT 6.6.6.2
  692. It shall be an error if the value of sqr(x) does not exist.
  693. .IS
  694. This error is detected for real-type arguments (real overflow,
  695. trap 4, non-fatal).
  696. .IT 6.6.6.2
  697. It shall be an error if x in ln(x) is smaller than or equal to 0.
  698. .IS
  699. This error is detected (error in ln, trap 66, non-fatal)
  700. .IT 6.6.6.2
  701. It shall be an error if x in sqrt(x) is smaller than 0.
  702. .IS
  703. This error is detected (error in sqrt, trap 67, non-fatal)
  704. .sp
  705. In addition to these errors, overflow in the expression exp(x) is
  706. detected (error in exp, trap 65, non-fatal; real overflow, trap 4, non-fatal)
  707. .sp
  708. .IT 6.6.6.3
  709. It shall be an error if
  710. the integer value of trunc(x) does not exist.
  711. .IS
  712. It depends on the implementations whether this error is detected.
  713. The floating-point emulation detects this error (conversion error,
  714. trap 10, non-fatal).
  715. .IT 6.6.6.3
  716. It shall be an error if
  717. the integer value of round(x) does not exist.
  718. .IS
  719. It depends on the implementations whether this error is detected.
  720. The floating-point emulation detects this error (conversion error,
  721. trap 10, non-fatal).
  722. .IT 6.6.6.4
  723. It shall be an error if
  724. the integer value of ord(x) does not exist.
  725. .IS
  726. This error can not occur, because the compiler will not allow
  727. such ordinal types.
  728. .IT 6.6.6.4
  729. It shall be an error if
  730. the character value of chr(x) does not exist.
  731. .IS
  732. Except when the R-option is off, the compiler generates an EM
  733. range check instruction. The effect of this instruction depends on the
  734. EM implementation.
  735. .IT 6.6.6.4
  736. It shall be an error if the value of succ(x) does not exist.
  737. .IS
  738. Same comments as for chr(x).
  739. .IT 6.6.6.4
  740. It shall be an error if the value of pred(x) does not exist.
  741. .IS
  742. Same comments as for chr(x).
  743. .IT 6.6.6.5
  744. It shall be an error if f in eof(f) is undefined.
  745. .IS
  746. This error is detected (file not yet open, trap 72, fatal).
  747. .IT 6.6.6.5
  748. It shall be an error if
  749. f in eoln(f) is undefined, or if eof(f) is true at that time.
  750. .IS
  751. The following errors may occur:
  752. .IS
  753. file not yet open, trap 72, fatal;
  754. .br
  755. not readable, trap 97, fatal;
  756. .br
  757. end of file, trap 98, fatal.
  758. .IE
  759. .IT 6.7.1
  760. It shall be an error if a variable-access used as an operand
  761. in an expression is undefined at the time of its use.
  762. .IS
  763. The compiler performs some limited checks to see if identifiers are
  764. used before they are set. Since it can not always be sure (one could, for
  765. instance, jump out of a loop), only a warning is generated. When an
  766. expression contains a function-call, an error occur if the
  767. function is not assigned at run-time.
  768. .IT 6.7.2.2
  769. A term of the form x/y shall be an error if y is zero.
  770. .IS
  771. It depends on the EM implementation whether this error is detected. On some
  772. machines, a trap may occur.
  773. .IT 6.7.2.2
  774. It shall be an error if j is zero in 'i div j'.
  775. .IS
  776. It depends on the EM implementation whether this error is detected. On some
  777. machines, a trap may occur.
  778. .IE
  779. .IT 6.7.2.2
  780. It shall be an error if
  781. j is zero or negative in i MOD j.
  782. .IS
  783. This error is detected (only positive j in 'i mod j', trap 71, non-fatal).
  784. .IT 6.7.2.2
  785. It shall be an error if the result of any operation on integer
  786. operands is not performed according to the mathematical
  787. rules for integer arithmetic.
  788. .IS
  789. The reaction depends on the EM implementation. Most implementations,
  790. however, will not notice integer overflow.
  791. .IT 6.8.3.5
  792. It shall be an error if none of the case-constants is equal to the
  793. value of the case-index upon entry to the case-statement.
  794. .IS
  795. This error is detected (case error, trap 20, fatal).
  796. .IT 6.9.1
  797. It shall be an error if the sequence of characters read looking for an
  798. integer does not form a signed-integer as specified in 6.1.5.
  799. .IS
  800. This error is detected (digit expected, trap 105, non-fatal).
  801. .IT 6.9.1
  802. It shall be an error if the sequence of characters read looking for a
  803. real does not form a signed-number as specified in 6.1.5.
  804. .IS
  805. This error is detected (digit expected, trap 105, non-fatal).
  806. .IT 6.9.1
  807. When read is applied to f, it shall be an error if the buffer-variable f^
  808. is undefined or the pre-assertions for get do not hold.
  809. .IS
  810. This error is detected (see get(f)).
  811. .IT 6.9.3
  812. When write is applied to a textfile f, it shall be an error if f is
  813. undefined or f is opened for reading.
  814. .IS
  815. This error is detected (see put(f)). Furthermore, this error is also
  816. detected when f is not a textfile.
  817. .IT 6.9.3.1
  818. The values of TotalWidth or FracDigits shall be greater than or equal to
  819. one; it shall be an error if either value is less then one.
  820. .IS
  821. When either value is less than zero, an error (illegal field width, trap
  822. 75, non-fatal) occurs. Zero values are allowed, in order to maintain some
  823. compatibility with the old Ack-Pascal compiler.
  824. .IT 6.9.5
  825. It shall be an error if the pre-assertion required for writeln(f) doe not
  826. hold prior to the invocation of page(f);
  827. .IS
  828. This error is detected (see put(f)).
  829. .CH "Extensions to the standard"
  830. .IS
  831. .ti -3
  832. 1.~\
  833. External routines
  834. .sp
  835. Except for the required directive 'forward' the Ack-Pascal compiler recognizes
  836. the directive 'extern'.
  837. This directive tells the compiler that the procedure block of this
  838. procedure will not be present in the current program.
  839. The code for the body of this procedure must be included at a later
  840. stage of the compilation process.
  841. .PP
  842. This feature allows one to build libraries containing often used routines.
  843. These routines do not have to be included in all the programs using them.
  844. Maintenance is much simpler if there is only one library module to be
  845. changed instead of many Pascal programs.
  846. .PP
  847. Another advantage is that these library modules may be written in a different
  848. language, for instance C or the EM assembly language.
  849. This is useful for accessing some specific EM instructions not generated
  850. by the Pascal compiler. Examples are the system call routines and some
  851. floating point conversion routines.
  852. Another motive could be the optimization of some time-critical program parts.
  853. .PP
  854. The use of external routines, however, is dangerous.
  855. The compiler normally checks for the correct number and type of parameters
  856. when a procedure is called and for the result type of functions.
  857. If an external routine is called these checks are not sufficient,
  858. because the compiler can not check whether the procedure heading of the
  859. external routine as given in the Pascal program matches the actual routine
  860. implementation.
  861. It should be the loader's task to check this.
  862. However, the current loaders are not that smart.
  863. Another solution is to check at run time, at least the number of words
  864. for parameters. Some EM implementations check this.
  865. .PP
  866. For those who wish the use the interface between C and Pascal we
  867. give an incomplete list of corresponding formal parameters in C and Pascal.
  868. .sp 1
  869. .TS
  870. l l.
  871. Pascal C
  872. a:integer int a
  873. a:char int a
  874. a:boolean int a
  875. a:real double a
  876. a:^type type *a
  877. var a:type type *a
  878. procedure a(pars) struct {
  879. void (*a)() ;
  880. char *static_link ;
  881. }
  882. function a(pars):type struct {
  883. type (*a)() ;
  884. char *static_link ;
  885. }
  886. .TE
  887. The Pascal runtime system uses the following algorithm when calling
  888. function/procedures passed as parameters.
  889. .TS
  890. l l.
  891. if ( static_link ) (*a)(static_link,pars) ;
  892. else (*a)(pars) ;
  893. .TE
  894. .ti -3
  895. 2.~\
  896. Separate compilation.
  897. .sp
  898. The compiler is able to (separately) compile a collection of declarations,
  899. procedures and functions to form a library.
  900. The library may be linked with the main program, compiled later.
  901. The syntax of these modules is
  902. .EQ
  903. module = [constant-definition-part]
  904. [type-definition-part]
  905. [var-declaration-part]
  906. [procedure-and-function-declaration-part]
  907. .EN
  908. The compiler accepts a program or a module:
  909. .EQ
  910. unit = program | module
  911. .EN
  912. All variables declared outside a module must be imported
  913. by parameters, even the files input and output.
  914. Access to a variable declared in a module is only possible
  915. using the procedures and functions declared in that same module.
  916. By giving the correct procedure/function heading followed by the
  917. directive 'extern' procedures and functions declared in
  918. other units may be used.
  919. .sp
  920. .ti -3
  921. 3.~\
  922. Assertions.
  923. .sp
  924. When the s-option is off, Ack-Pascal compiler recognizes an additional
  925. statement, the assertion. Assertions can be used as an aid in debugging
  926. and documentation. The syntax is:
  927. .EQ
  928. assertion = 'assert' Boolean-expression
  929. .EN
  930. An assertion is a simple-statement, so
  931. .EQ
  932. simple-statement = [assignment-statement |
  933. procedure-statement |
  934. goto-statement |
  935. assertion
  936. ]
  937. .EN
  938. An assertion causes an error if the Boolean-expression is false.
  939. That is its only purpose.
  940. It does not change any of the variables, at least it should not.
  941. Therefore, do not use functions with side-effects in the Boolean-expression.
  942. If the a-option is turned on, then assertions are skipped by the
  943. compiler. 'assert' is not a word-symbol (keyword) and may be used as identifier.
  944. However, assignment to a variable and calling of a procedure with that
  945. name will be impossible.
  946. If the s-option is turned on, the compiler will not know a thing about
  947. assertions, so using assertions will then give a parse error.
  948. .sp
  949. .ti -3
  950. 4.~\
  951. Additional procedures.
  952. .sp
  953. Three additional standard procedures are available:
  954. .IS
  955. .IS
  956. .ti -8
  957. halt:~~~a call of this procedure is equivalent to jumping to the
  958. end of the program. It is always the last statement executed.
  959. The exit status of the program may be supplied
  960. as optional argument. If not, it will be zero.
  961. .ti -8
  962. release:
  963. .ti -8
  964. mark:~~~for most applications it is sufficient to use the heap as second stack.
  965. Mark and release are suited for this type of use, more suited than dispose.
  966. mark(p), with p of type pointer, stores the current value of the
  967. heap pointer in p. release(p), with p initialized by a call
  968. of mark(p), restores the heap pointer to its old value.
  969. All the heap objects, created by calls of new between the call of
  970. mark and the call of release, are removed and the space they used
  971. can be reallocated.
  972. Never use mark and release together with dispose!
  973. .sp
  974. .in -10
  975. .ti -3
  976. 5.~\
  977. UNIX interfacing.
  978. .sp
  979. If the c-option is turned on, then some special features are available
  980. to simplify an interface with the UNIX environment.
  981. First of all, the compiler allows for a different type
  982. of string constants.
  983. These string constants are delimited by double quotes ('"').
  984. To put a double quote into these strings, the double quote must be repeated,
  985. like the single quote in normal string constants.
  986. These special string constants are terminated by a zero byte (chr(0)).
  987. The type of these constants is a pointer to a packed array of characters,
  988. with lower bound 1 and unknown upper bound.
  989. .br
  990. Secondly, the compiler predefines a new type identifier 'string' denoting
  991. this just described string type.
  992. .PP
  993. These features are only useful for declaration of
  994. constants and variables of type 'string'.
  995. String objects may not be allocated on the heap and string pointers
  996. may not be de-referenced.
  997. Still these strings are very useful in combination with external routines.
  998. The procedure write is extended to print these zero-terminated
  999. strings correctly.
  1000. .sp
  1001. .ti -3
  1002. 6.~\
  1003. Double length (32 bit) integers.
  1004. .sp
  1005. If the d-option is turned on, then the additional type 'long' is known
  1006. to the compiler.
  1007. By default, long variables have integer values in the
  1008. range -2147483647..+2147483647, but this can be changed with the -V option
  1009. (if the backend can support this).
  1010. Long constants can not be declared.
  1011. Longs can not be used as control-variables.
  1012. It is not allowed to form subranges of type long.
  1013. All operations allowed on integers are also
  1014. allowed on longs and are indicated by the same
  1015. operators: '+', '-', '*', '/', 'div', 'mod'.
  1016. The procedures read and write have been extended to handle long
  1017. arguments correctly. It is possible to read longs from a file of integers
  1018. and vice-versa, but only if longs and integers have the same size.
  1019. The default width for longs is 11.
  1020. The standard procedures 'abs' and 'sqr' have been extended to work
  1021. on long arguments.
  1022. Conversion from integer to long, long to real,
  1023. real to long and long to integer are automatic, like the conversion
  1024. from integer to real.
  1025. These conversions may cause a
  1026. .IS
  1027. conversion error, trap 10, non-fatal
  1028. .IE
  1029. .sp
  1030. .ti -3
  1031. 7.~\
  1032. Underscore as letter.
  1033. .sp
  1034. The character '_' may be used in forming identifiers, if the u- or U-option
  1035. is turned on. It is forbidden to start identifiers with underscores, since
  1036. this may cause name-clashes with run-time routines.
  1037. .sp
  1038. .ti -3
  1039. 8.~\
  1040. Zero field width in write.
  1041. .sp
  1042. Zero TotalWidth arguments are allowed. No characters are written for
  1043. character, string or Boolean type arguments then. A zero FracDigits
  1044. argument for fixed-point representation of reals causes the fraction and
  1045. the character '.' to be suppressed.
  1046. .sp
  1047. .ti -3
  1048. 9.~\
  1049. Pre-processing.
  1050. .sp
  1051. If the very first character of a file containing a Pascal
  1052. program is the sharp ('#', ASCII 23(hex)) the file is preprocessed
  1053. in the same way as C programs.
  1054. Lines beginning with a '#' are taken as preprocessor command lines
  1055. and not fed to the Pascal compiler proper.
  1056. C style comments, /*......*/, are removed by the C preprocessor,
  1057. thus C comments inside Pascal programs are also removed when they
  1058. are fed through the preprocessor.
  1059. .CH "Deviations from the standard"
  1060. Ack-Pascal deviates from the standard proposal in the following ways:
  1061. .IS
  1062. .ti -3
  1063. 1.~\
  1064. Standard procedures and functions are not allowed as parameters in Ack-Pascal.
  1065. The same result can be obtained with negligible loss of performance
  1066. by declaring some user routines like:
  1067. .EQ
  1068. function sine(x:real):real;
  1069. begin
  1070. sine:=sin(x)
  1071. end;
  1072. .EN
  1073. .sp
  1074. .ti -3
  1075. 2.~\
  1076. The standard procedures read, readln, write and writeln are implemented as
  1077. word-symbols, and can therefore not be redeclared.
  1078. .CH "Compiler options"
  1079. Some options of the compiler may be controlled by using "{$....}".
  1080. Each option consists of a lower case letter followed by +, - or an unsigned
  1081. number.
  1082. Options are separated by commas.
  1083. The following options exist:
  1084. .in 8
  1085. .sp
  1086. .ti -8
  1087. a~+/-~~~\
  1088. this option switches assertions on and off.
  1089. If this option is on, then code is included to test these assertions
  1090. at run time. Default +.
  1091. .sp
  1092. .ti -8
  1093. c~+/-~~~\
  1094. this option, if on, allows the use of C-type string constants
  1095. surrounded by double quotes.
  1096. Moreover, a new type identifier 'string' is predefined.
  1097. Default -.
  1098. .sp
  1099. .ti -8
  1100. d~+/-~~~\
  1101. this option, if on, allows the use of variables of type 'long'.
  1102. Default -.
  1103. .sp
  1104. .ti -8
  1105. i~<num>~\
  1106. with this flag the setsize for a set of integers can be
  1107. manipulated.
  1108. The number must be the number of bits per set.
  1109. The default value is wordsize-1.
  1110. .sp
  1111. .ti -8
  1112. l~+/-~~~\
  1113. if + then code is inserted to keep track of the source line number.
  1114. When this flag is switched on and off, an incorrect line number may appear
  1115. if the error occurs in a part of the program for which this flag is off.
  1116. These same line numbers are used for the profile, flow and count options
  1117. of the EM interpreter em [5].
  1118. Default +.
  1119. .sp
  1120. .ti -8
  1121. r~+/-~~~\
  1122. if + then code is inserted to check subrange variables against
  1123. lower and upper subrange limits.
  1124. Default +.
  1125. .sp
  1126. .ti -8
  1127. s~+/-~~~\
  1128. if + then the compiler will hunt for places in the program
  1129. where non-standard features are used, and for each place found
  1130. it will generate a warning. Default -.
  1131. .sp
  1132. .ti -8
  1133. t~+/-~~~\
  1134. if + then each time a procedure is entered, the routine 'procentry' is
  1135. called, and each time a procedure exits, the procedure 'procexit' is
  1136. called. Both 'procentry' and 'procexit' have a 'string' as parameter. This
  1137. means that when a user specifies his or her own procedures, the c-option
  1138. must be used. Default procedures are present in the run time library.
  1139. Default -.
  1140. .sp
  1141. .ti -8
  1142. u~+/-~~~\
  1143. if + then the character '_' is treated like a letter,
  1144. so that it may be used in identifiers.
  1145. Procedure and function identifiers are not allowed to start with an
  1146. underscore because they may collide with library routine names.
  1147. Default -.
  1148. .in 0
  1149. .sp
  1150. Some of these flags (c, d, i, s, u, C and U) are only effective when
  1151. they appear before the 'program' symbol. The others may be switched
  1152. on and off.
  1153. .PP
  1154. A very powerful debugging tool is the knowledge that inaccessible statements
  1155. and useless tests are removed by the EM optimizer. For instance, a
  1156. statement like:
  1157. .sp
  1158. .nf
  1159. if debug then
  1160. writeln('initialization done');
  1161. .fi
  1162. .sp
  1163. is completely removed by the optimizer if debug is a constant with
  1164. value false.
  1165. The first line is removed if debug is a constant with value true.
  1166. Of course, if debug is a variable nothing can be removed.
  1167. .PP
  1168. A disadvantage of Pascal, the lack of preinitialized data, can be
  1169. diminished by making use of the possibilities of the EM optimizer.
  1170. For instance, initializing an array of reserved words is sometimes
  1171. optimized into 3 EM instructions. To maximize this effect
  1172. variables must be initialized as much as possible in order of declaration and array entries
  1173. in order of decreasing index.
  1174. .CH "References"
  1175. .in +5
  1176. .ti -5
  1177. [1]~~\
  1178. BSI standard BS 6192: 1982 (ISO 7185).
  1179. .sp
  1180. .ti -5
  1181. [2]~~\
  1182. A.S.Tanenbaum, J.W.Stevenson, Hans van Staveren, E.G.Keizer,
  1183. "Description of a machine architecture for use with block structured languages",
  1184. Informatica rapport IR-81.
  1185. .sp
  1186. .ti -5
  1187. [3]~~\
  1188. UNIX manual ack(I).
  1189. .sp
  1190. .ti -5
  1191. [4]~~\
  1192. UNIX manual ld(I).
  1193. .sp
  1194. .ti -5
  1195. [5]~~\
  1196. UNIX manual em(I).
  1197. .sp
  1198. .ti -5
  1199. [6]~~\
  1200. UNIX manual libpc(VII)
  1201. .sp
  1202. .ti -5
  1203. [7]~~\
  1204. UNIX manual pc_prlib(VII)