pcref.doc 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. .\" $Header$
  2. .ds OF \\fBtest~off:~\\fR
  3. .ds ON \\fBtest~on:~~\\fR
  4. .ds AL \\fBtest~all:~\\fR
  5. .ll 72n
  6. .wh 0 hd
  7. .wh 60 fo
  8. .de hd
  9. 'sp 5
  10. ..
  11. .de fo
  12. 'bp
  13. ..
  14. .tr ~
  15. . TITLE
  16. .de TL
  17. .sp 15
  18. .ce
  19. \\fB\\$1\\fR
  20. ..
  21. . AUTHOR
  22. .de AU
  23. .sp 15
  24. .ce
  25. by
  26. .sp 2
  27. .ce
  28. \\$1
  29. ..
  30. . DATE
  31. .de DA
  32. .sp 3
  33. .ce
  34. ( Dated \\$1 )
  35. ..
  36. . INSTITUTE
  37. .de VU
  38. .sp 3
  39. .ce 4
  40. Vakgroep Informatica
  41. Vrije Universiteit
  42. De Boelelaan 1081
  43. Amsterdam
  44. ..
  45. . PARAGRAPH
  46. .de PP
  47. .sp
  48. .ti +5
  49. ..
  50. .nr CH 0 1
  51. . CHAPTER
  52. .de CH
  53. .nr SH 0 1
  54. .bp
  55. .in 0
  56. \\fB\\n+(CH.~\\$1\\fR
  57. .PP
  58. ..
  59. . SUBCHAPTER
  60. .de SH
  61. .sp 3
  62. .in 0
  63. \\fB\\n(CH.\\n+(SH.~\\$1\\fR
  64. .PP
  65. ..
  66. . INDENT START
  67. .de IS
  68. .sp
  69. .in +5
  70. ..
  71. . INDENT END
  72. .de IE
  73. .in -5
  74. .sp
  75. ..
  76. . DOUBLE INDENT START
  77. .de DS
  78. .sp
  79. .in +5
  80. .ll -5
  81. ..
  82. . DOUBLE INDENT END
  83. .de DE
  84. .ll +5
  85. .in -5
  86. .sp
  87. ..
  88. . EQUATION START
  89. .de EQ
  90. .sp
  91. .nf
  92. ..
  93. . EQUATION END
  94. .de EN
  95. .fi
  96. .sp
  97. ..
  98. . ITEM
  99. .de IT
  100. .sp
  101. .in 0
  102. \\fBISO~\\$1:\\fR~\\
  103. ..
  104. . IMPLEMENTATION 1
  105. .de I1
  106. .IS
  107. .ti -3
  108. 1.~\\
  109. ..
  110. . IMPLEMENTATION 2
  111. .de I2
  112. .sp
  113. .ti -3
  114. 2.~\\
  115. ..
  116. .de CS
  117. .br
  118. ~-~\\
  119. ..
  120. .br
  121. .fi
  122. .TL "Amsterdam Compiler Kit-Pascal reference manual"
  123. .AU "Johan W. Stevenson"
  124. .DA "January 4, 1983"
  125. .VU
  126. .CH "Introduction"
  127. This document refers to the (March 1980) ISO standard proposal for Pascal [1].
  128. Ack-Pascal complies with the requirements of this proposal almost completely.
  129. The standard requires an accompanying document describing the
  130. implementation-defined and implementation-dependent features,
  131. the reaction on errors and the extensions to standard Pascal.
  132. These four items will be treated in the rest of this document,
  133. each in a separate chapter.
  134. The other chapters describe the deviations from the standard and
  135. the list of options recognized by the compiler.
  136. .PP
  137. The Ack-Pascal compiler produces code for an EM machine as defined in [2].
  138. It is up to the implementor of the EM machine to decide whether errors like
  139. integer overflow, undefined operand and range bound error are recognized or not.
  140. For these errors the reaction of some known implementations is given.
  141. .PP
  142. There does not (yet) exist a hardware EM machine.
  143. Therefore, EM programs must be interpreted, or translated into
  144. instructions for a target machine.
  145. For the following implementations the behavior is documented:
  146. .I1
  147. an interpreter running on a PDP-11.
  148. Normally the interpreter performs some tests to detect undefined
  149. integers, integer overflow, range errors, etc.
  150. However, an option of the interpreter is to skip these tests.
  151. Another option is to perform some extra tests
  152. to check for instance the number of actual parameter
  153. words against the number expected by
  154. the called procedure.
  155. We will refer to these modes of operation as 'test all', 'test on' and 'test off'.
  156. .I2
  157. a translator into PDP-11 instructions.
  158. .IE
  159. .CH "Implementation-defined features"
  160. For each implementation-defined feature mentioned in the ISO standard
  161. we give the section number, the quotation from that section and the definition.
  162. First we quote the definition of implementation-defined:
  163. .DS
  164. Those parts of the language which may differ between processors, but which
  165. will be defined for any particular processor.
  166. .DE
  167. .IT 6.1.7
  168. Each string-character shall denote an implementation-defined value of char-type.
  169. .IS
  170. All 7-bits ASCII characters except linefeed LF (10) are allowed.
  171. Note that an apostrophe ' must be doubled within a string.
  172. .IE
  173. .IT 6.4.2.2
  174. The values of type real shall be an implementation-defined subset
  175. of the real numbers denoted as specified by 6.1.5.
  176. .IS
  177. The format of reals is not defined in EM.
  178. Even the size of reals depends on the implementation.
  179. The compiler can be instructed, by the f-option, to use a different
  180. size for real values.
  181. The size of reals is preset by the calling program \fIack\fP
  182. [4] to
  183. the proper size.
  184. For each implementation of EM the following constants must be defined:
  185. epbase: the base for the exponent part
  186. epprec: the precision of the fraction
  187. epemin: the minimum exponent
  188. epemax: the maximum exponent
  189. .br
  190. These constants must be chosen so that zero and all numbers with
  191. exponent e in the range
  192. .EQ
  193. epemin <= e <= epemax
  194. .EN
  195. and fraction-parts of the form
  196. .EQ
  197. f = +_ f\d1\u.b\u-1\d + ... + f\depprec\u.b\u-epprec\d
  198. .EN
  199. where
  200. .EQ
  201. f\di\u = 0,...,epbase-1 and f\d1\u <> 0
  202. .EN
  203. are possible values for reals.
  204. All other values of type real are considered illegal.
  205. (See [3] for more information about these constants).
  206. .br
  207. For the known EM implementations these constants are:
  208. .I1
  209. epbase = 2
  210. .br
  211. epprec = 24
  212. .br
  213. epemin = -127
  214. .br
  215. epemax = +127
  216. .I2
  217. ditto
  218. .IE
  219. .IT 6.4.2.2
  220. The type char shall be the enumeration of a set of implementation-defined
  221. characters, some possibly without graphic representations.
  222. .IS
  223. The 7-bits ASCII character set is used, where LF (10) denotes the
  224. end-of-line marker on text-files.
  225. .IT 6.4.2.2
  226. The ordinal numbers of the character values shall be values of integer-type,
  227. that are implementation-defined, and that are determined by mapping
  228. the character values on to consecutive non-negative integer values
  229. starting at zero.
  230. .IS
  231. The normal ASCII ordering is used: ord('0')=48, ord('A')=65, ord('a')=97, etc.
  232. .IE
  233. .IT 6.4.3.4
  234. The largest and smallest values of integer-type
  235. permitted as numbers of a value
  236. of a set-type shall be implementation-defined.
  237. .IS
  238. The smallest value is 0. The largest value is default 15, but can be
  239. changed by using the i-option of the compiler up to a maximum
  240. of 32767.
  241. The compiler allocates as many bits for set-type variables as are necessary
  242. to store all possible values of the host-type of the base-type of the set,
  243. rounded up to the nearest multiple of 16.
  244. If 8 bits are sufficient then only
  245. 8 bits are used if part of a packed structure.
  246. Thus, the variable s, declared by
  247. .EQ
  248. var s: set of '0'..'9';
  249. .EN
  250. will contain 128 bits, not 10 or 16.
  251. These 128 bits are stored in 16 bytes, both for packed and unpacked sets.
  252. If the host-type of the base-type is integer, then the
  253. number of bits depends on the i-option.
  254. The programmer may specify how many bits to allocate for these sets.
  255. The default is 16, the maximum is 32767.
  256. The effective number of bits is rounded up to the next multiple of 16, or up
  257. to 8 if the number of bits is less than or equal to 8.
  258. Note that the use of set-constructors for sets with more than 256 elements
  259. is far less efficient than for smaller sets.
  260. .IT 6.7.2.2
  261. The predefined constant maxint shall be of integer-type and shall denote
  262. an implementation-defined value, that satisfies the following conditions:
  263. .sp 1
  264. .in +5
  265. .ti -4
  266. (a)~All integral values in the closed interval from -maxint to +maxint
  267. shall be values in the integer-type.
  268. .ti -4
  269. (b)~Any monadic operation performed on an integer value in this interval
  270. shall be correctly performed according to the mathematical rules for
  271. integer arithmetic.
  272. .ti -4
  273. (c)~Any dyadic integer operation on two integer values in this same interval
  274. shall be correctly performed according to the mathematical rules for
  275. integer arithmetic, provided that the result is also in this interval.
  276. .ti -4
  277. (d)~Any relational operation on two integer values in this same interval
  278. shall be correctly performed according to the mathematical rules for
  279. integer arithmetic.
  280. .in -5
  281. .IS
  282. The representation of integers in EM is a \fIn\fP*8-bit word using
  283. two's complement arithmetic.
  284. Where \fIn\fP is called wordsize.
  285. The compiler can only generate code for EM with wordsize 2.
  286. Thus always:
  287. .EQ
  288. maxint = 32767
  289. .EN
  290. Because the number -32768 may be used to indicate 'undefined', the
  291. range of available integers depends on the EM implementation:
  292. .I1
  293. \*(ON-32767..+32767.
  294. .br
  295. \*(OF-32768..+32767.
  296. .I2
  297. -32768..+32767.
  298. .IE
  299. .IT 6.9.4.2
  300. The default TotalWidth values for integer, Boolean and real types
  301. shall be implementation-defined.
  302. .IS
  303. The defaults are:
  304. integer 6
  305. Boolean 5
  306. real 13
  307. .IT 6.9.4.5.1
  308. ExpDigits, the number of digits written in an exponent part of a real,
  309. shall be implementation-defined.
  310. .IS
  311. ExpDigits is defined as
  312. .EQ
  313. ceil(log10(log10(2 ** epemax)))
  314. .EN
  315. For the current implementations this evaluates to 2.
  316. .IT 6.9.4.5.1
  317. The character written as part of the representation of
  318. a real to indicate the beginning of the exponent part shall be
  319. implementation-defined, either 'E' or 'e'.
  320. .IS
  321. The exponent part starts with 'e'.
  322. .IT 6.9.4.6
  323. The case of the characters written as representation of the
  324. Boolean values shall be implementation-defined.
  325. .IS
  326. The representations of true and false are 'true' and 'false'.
  327. .IT 6.9.6
  328. The effect caused by the standard procedure page
  329. on a text file shall be implementation-defined.
  330. .IS
  331. The ASCII character form feed FF (12) is written.
  332. .IT 6.10
  333. The binding of the variables denoted by the program-parameters
  334. to entities external to the program shall be implementation-defined if
  335. the variable is of a file-type.
  336. .IS
  337. The program parameters must be files and all, except input and output,
  338. must be declared as such in the program block.
  339. .PP
  340. The program parameters input and output, if specified, will correspond
  341. with the UNIX streams 'standard input' and 'standard output'.
  342. .PP
  343. The other program parameters will be mapped to the argument strings
  344. provided by the caller of this program.
  345. The argument strings are supposed to be path names of the files to be
  346. opened or created.
  347. The order of the program parameters determines the mapping:
  348. the first parameter is mapped onto the first argument string etc.
  349. Note that input and output are ignored in this mapping.
  350. .PP
  351. The mapping is recalculated each time a program parameter
  352. is opened for reading or writing by a call to the standard procedures
  353. reset or rewrite.
  354. This gives the programmer the opportunity to manipulate the list
  355. of string arguments using the external procedures argc, argv and argshift
  356. available in libpc [7].
  357. .IT 6.10
  358. The effect of an explicit use of reset or rewrite
  359. on the standard textfiles input or output shall be implementation-defined.
  360. .IS
  361. The procedures reset and rewrite are no-ops
  362. if applied to input or output.
  363. .CH "Implementation-dependent features"
  364. For each implementation-dependent feature mentioned in the ISO standard draft,
  365. we give the section number, the quotation from that section and the way
  366. this feature is treated by the Ack-Pascal system.
  367. First we quote the definition of 'implementation-dependent':
  368. .DS
  369. Those parts of the language which may differ between processors,
  370. and for which there need not be a definition for a particular processor.
  371. .DE
  372. .IT 5.1.1
  373. The method for reporting errors or warnings shall be implementation-dependent.
  374. .IS
  375. The error handling is treated in a following chapter.
  376. .IE
  377. .IT 6.1.4
  378. Other implementation-dependent directives may be defined.
  379. .IS
  380. Except for the required directive 'forward' the Ack-Pascal compiler recognizes
  381. only one directive: 'extern'.
  382. This directive tells the compiler that the procedure block of this
  383. procedure will not be present in the current program.
  384. The code for the body of this procedure must be included at a later
  385. stage of the compilation process.
  386. .PP
  387. This feature allows one to build libraries containing often used routines.
  388. These routines do not have to be included in all the programs using them.
  389. Maintenance is much simpler if there is only one library module to be
  390. changed instead of many Pascal programs.
  391. .PP
  392. Another advantage is that these library modules may be written in a different
  393. language, for instance C or the EM assembly language.
  394. This is useful if you want to use some specific EM instructions not generated
  395. by the Pascal compiler. Examples are the system call routines and some
  396. floating point conversion routines.
  397. Another motive could be the optimization of some time-critical program parts.
  398. .PP
  399. The use of external routines, however, is dangerous.
  400. The compiler normally checks for the correct number and type of parameters
  401. when a procedure is called and for the result type of functions.
  402. If an external routine is called these checks are not sufficient,
  403. because the compiler can not check whether the procedure heading of the
  404. external routine as given in the Pascal program matches the actual routine
  405. implementation.
  406. It should be the loader's task to check this.
  407. However, the current loaders are not that smart.
  408. Another solution is to check at run time, at least the number of words
  409. for parameters. Some EM implementations check this:
  410. .I1
  411. \*(ALthe number of words passed as parameters is checked, but this will not catch all faulty cases.
  412. .br
  413. \*(ONnot checked.
  414. .I2
  415. not checked.
  416. .IE
  417. .PP
  418. For those who wish the use the interface between C and Pascal we
  419. give an incomplete list of corresponding formal parameters in C and Pascal.
  420. .sp 1
  421. .ta 8 37
  422. .nf
  423. Pascal C
  424. a:integer int a
  425. a:char int a
  426. a:boolean int a
  427. a:real double a
  428. a:^type type *a
  429. var a:type type *a
  430. procedure a(pars) struct {
  431. void (*a)() ;
  432. char *static_link ;
  433. }
  434. function a(pars):type struct {
  435. type (*a)() ;
  436. char *static_link ;
  437. }
  438. .fi
  439. The Pascal runtime system uses the following algorithm when calling
  440. function/procedures passed as parameters.
  441. .nf
  442. .ta 8 16
  443. if ( static_link ) (*a)(static_link,pars) ;
  444. else (*a)(pars) ;
  445. .fi
  446. .IT 6.7.2.1
  447. The order of evaluation of the operands of a dyadic operator
  448. shall be implementation-dependent.
  449. .IS
  450. Operands are always evaluated, so the program part
  451. .EQ
  452. if (p<>nil) and (p^.value<>0) then
  453. .EN
  454. is probably incorrect.
  455. .PP
  456. The left-hand operand of a dyadic operator is almost always evaluated
  457. before the right-hand side.
  458. Some peculiar evaluations exist for the following cases:
  459. .IS
  460. .ti -3
  461. 1.~\
  462. the modulo operation is performed by a library routine to
  463. check for negative values of the right operand.
  464. .IE
  465. .sp
  466. .ti -3
  467. 2.~\
  468. the expression
  469. .EQ
  470. set1 <= set2
  471. .EN
  472. where set1 and set2 are compatible set types is evaluated in the
  473. following steps:
  474. .IS
  475. .CS
  476. evaluate set2
  477. .CS
  478. evaluate set1
  479. .CS
  480. compute set2+set1
  481. .CS
  482. test set2 and set2+set1 for equality
  483. .IE
  484. This is the only case where the right-hand side is computed first.
  485. .sp
  486. .ti -3
  487. 3.~\
  488. the expression
  489. .EQ
  490. set1 >= set2
  491. .EN
  492. where set1 and set2 are compatible set types is evaluated in the following steps:
  493. .IS
  494. .CS
  495. evaluate set1
  496. .CS
  497. evaluate set2
  498. .CS
  499. compute set1+set2
  500. .CS
  501. test set1 and set1+set2 for equality
  502. .IE
  503. .IT 6.7.3
  504. The order of evaluation, accessing and binding
  505. of the actual-parameters for functions
  506. shall be implementation-dependent.
  507. .IS
  508. The order of evaluation is from right to left.
  509. .IT 6.8.2.2
  510. If access to the variable in an assignment-statement involves the indexing of an array
  511. and/or a reference to a field within a variant of a record
  512. and/or the de-referencing of a pointer-variable
  513. and/or a reference to a buffer-variable,
  514. the decision whether these actions precede or follow the evaluation
  515. of the expression shall be implementation-dependent.
  516. .IS
  517. The expression is evaluated first.
  518. .IT 6.8.2.3
  519. The order of evaluation and binding of the actual-parameters for procedures
  520. shall be implementation-dependent.
  521. .IS
  522. The same as for functions.
  523. .IT 6.9.6
  524. The effect of inspecting a text file to which the page
  525. procedure was applied during generation is
  526. implementation-dependent.
  527. .IS
  528. The formfeed character written by page is
  529. treated like a normal character, with ordinal value 12.
  530. .IT 6.10
  531. The binding of the variables denoted by the program-parameters
  532. to entities external to the program shall be implementation-dependent unless
  533. the variable is of a file-type.
  534. .IS
  535. Only variables of a file-type are allowed as program parameters.
  536. .IE
  537. .CH "Error handling"
  538. There are three classes of errors to be distinguished.
  539. In the first class are the error messages generated by the compiler.
  540. The second class consists of the occasional errors generated by the other
  541. programs involved in the compilation process.
  542. Errors of the third class are the errors as defined in the standard by:
  543. .DS
  544. An error is a violation by a program of the requirements of this standard
  545. such that detection normally requires execution of the program.
  546. .DE
  547. .SH "Compiler errors"
  548. The error messages (and the listing) are not generated by the compiler itself.
  549. The compiler only detects errors and writes the errors in condensed form on
  550. an intermediate file.
  551. Each error in condensed form contains:
  552. .IS
  553. .CS
  554. an optional error message parameter (identifier or number).
  555. .CS
  556. an error number
  557. .CS
  558. a line number
  559. .CS
  560. a column number.
  561. .IE
  562. Every time the compiler detects an error that does not have influence
  563. on the code produced by the compiler or on the syntax decisions, a warning
  564. messages is given.
  565. If only warnings are generated, compilation proceeds and probably results
  566. in a correctly compiled program.
  567. .PP
  568. The intermediate error file is read by the interface program
  569. \fIack\fP [4],
  570. that produces the error messages.
  571. It uses an other file, the error message file,
  572. to find an error script line.
  573. Whenever this error script line contains the character '%', the error messages
  574. parameter is substituted.
  575. For negative error numbers the message constructed is prepended with 'Warning: '.
  576. .PP
  577. Sometimes the compiler produces several errors for the same file position
  578. (line number, column number).
  579. Only the first of these messages is given, because the others are probably
  580. directly caused by the first one.
  581. If the first one is a warning while one of its successors for that position
  582. is a fatal message, then the warning is promoted to a fatal one.
  583. However, parameterized messages are always given.
  584. .PP
  585. The error messages and listing come in three flavors, selected by flags
  586. given to \fIack\fP [4]:
  587. .in +10
  588. .sp
  589. .ti -8
  590. default:no listing, one line per error giving the file name
  591. of the Pascal source file, the line number and the error messages.
  592. .sp
  593. .ti -8
  594. -e:~~~~~for each erroneous line a listing of the line and its predecessor.
  595. The next line contains one or more characters '^' pointing to the
  596. places where an error is detected.
  597. For each error on that line a message follows.
  598. .sp
  599. .ti -8
  600. -E:~~~~~same as for '-e', except that all source lines are listed,
  601. even if the program is perfect.
  602. .IE
  603. .IE
  604. .SH "Other errors detected at compilation time"
  605. Two main categories: file system problems and table overflow.
  606. Problems with the file system may be caused by protection (you may not read
  607. or create files) or by space problems (no space left on device; out of inodes;
  608. too many processes).
  609. Table overflow problems are often caused by peculiar source programs:
  610. very long procedures or functions, a lot of strings.
  611. Table overflow problems can sometimes be cured
  612. by giving a flag (-sl when producing e.out files) to \fIack\fP [4].
  613. .PP
  614. Extensive treatment of these errors is outside the scope of this manual.
  615. .SH "Runtime errors"
  616. Errors detected at run time cause an error message to be generated on the
  617. diagnostic output stream (UNIX file descriptor 2).
  618. The message consists of the name of the program followed by a message
  619. describing the error, possibly followed by the source line number.
  620. Unless the l-option is turned off, the compiler generates code to keep track
  621. of which source line causes which EM instructions to be generated.
  622. It depends on the EM implementation whether these LIN instructions
  623. are skipped or executed:
  624. .I1
  625. LIN instructions are always executed. The old line number is saved and
  626. restored whenever a procedure or function is called.
  627. All error messages contain this line number, except when the l-option
  628. was turned off.
  629. .I2
  630. same as above, but line numbers are not saved when procedures and functions
  631. are called.
  632. .IE
  633. For each error mentioned in the standard we give the section number,
  634. the quotation from that section and the way it is processed by the
  635. Pascal-compiler or runtime system.
  636. .PP
  637. For detected errors the corresponding message
  638. and trap number are given.
  639. Trap numbers are useful for exception-handling routines.
  640. Normally, each error causes the program to terminate.
  641. By using exception-handling routines one can
  642. ignore errors or perform alternate actions.
  643. Only some of the errors can be ignored
  644. by restarting the failing instruction.
  645. These errors are marked as non-fatal,
  646. all others as fatal.
  647. A list of errors with trap number between 0 and 63
  648. (EM errors) can be found in [2].
  649. Errors with trap number between 64 and 127 (Pascal errors) are listed in [8].
  650. .IT 6.4.3.3
  651. It shall be an error if any field-identifier defined within a variant
  652. is used in a field-designator unless the value of the tag-field
  653. is associated with that variant.
  654. .IS
  655. This error is not detected.
  656. Sometimes this feature is used to achieve easy type conversion.
  657. However, using record variants this way is dangerous, error prone and not portable.
  658. .IT 6.4.6
  659. It shall be an error if a value of type T2 must be
  660. assignment-compatible with type T1, while
  661. T1 and T2 are compatible ordinal-types and the value of
  662. type T2 is not in the closed interval specified by T1.
  663. .IS
  664. The compiler distinguishes between array-index expressions and the other
  665. places where assignment-compatibility is required.
  666. .PP
  667. Array subscripting is done using the EM array instructions.
  668. These instructions have three arguments: the array base address,
  669. the index and the address of the array descriptor.
  670. An array descriptor describes one dimension by three values:
  671. the element size, the lower bound on the index and the number of elements
  672. minus one.
  673. It depends on the EM implementation whether these bounds are checked:
  674. .I1
  675. \*(ONchecked (array bound error, trap 0, non-fatal).
  676. .br
  677. \*(OFnot checked
  678. .I2
  679. not checked.
  680. .IE
  681. The other places where assignment-compatibility is required are:
  682. .IS
  683. .CS
  684. assignment
  685. .CS
  686. value parameters
  687. .CS
  688. procedures read and readln
  689. .CS
  690. the final value of the for-statement
  691. .IE
  692. For these places the compiler generates an EM range check instruction, except
  693. when the r-option is turned off, or when the range of values of T2
  694. is enclosed in the range of T1.
  695. If the expression consists of a single variable and if that variable
  696. is of a subrange type,
  697. then the subrange type itself is taken as T2, not its host-type.
  698. Therefore, a range instruction is only generated if T1 is a subrange type
  699. and if the expression is a constant, an expression with two or more
  700. operands, or a single variable with a type not enclosed in T1.
  701. If a constant is assigned, then the EM optimizer removes the range check
  702. instruction, except when the value is out of bounds.
  703. .PP
  704. It depends on the EM implementation whether the range check instruction
  705. is executed or skipped:
  706. .I1
  707. \*(ONchecked (range bound error, trap 1, non-fatal).
  708. .br
  709. \*(OFskipped
  710. .I2
  711. skipped
  712. .IE
  713. .IT 6.4.6
  714. It shall be an error if a value of type T2 must be
  715. assignment-compatible with type T1, while T1 and T2 are compatible
  716. set-types and any member of the value of type T2
  717. is not in the closed interval specified by the base-type
  718. of the type T1.
  719. .IS
  720. This error is not detected.
  721. .IT 6.5.4
  722. It shall be an error if
  723. the pointer-variable has a nil-value or is undefined at the time
  724. it is de-referenced.
  725. .IS
  726. The EM definition does not specify the binary representation of pointer
  727. values, so that it is not possible to choose an otherwise illegal
  728. binary representation for the pointer value NIL.
  729. Rather arbitrary the compiler uses the integer value zero to represent NIL.
  730. For all current implementations this does not cause problems.
  731. .PP
  732. The size of pointers depends on the implementation and is
  733. preset in the compiler by \fIack\fP [4].
  734. The compiler can be instructed, by the p-option, to use
  735. any size for pointer objects.
  736. NIL is represented here by the appropriate number of zero words.
  737. .PP
  738. It depends on the EM implementation whether de-referencing of a pointer
  739. with value NIL causes an error:
  740. .I1
  741. \*(ONfor every de-reference the pointer value is checked to be legal.
  742. The value NIL is always illegal.
  743. Objects addressed by a NIL pointer always cause an error, except
  744. when they are part of some extraordinary sized structure
  745. (bad pointer, trap 22, fatal).
  746. .br
  747. \*(OFde-referencing for fetching will not cause
  748. an error to occur.
  749. However, if the pointer value is used for a store operation,
  750. a segmentation violation probably results (memory fault, trap 21, fatal).
  751. (Note: this is only true if the interpreter is executed with coinciding
  752. address spaces and protected text part. The interpreter must therefore
  753. be loaded with the '-n' option of the UNIX loader [5]).
  754. .I2
  755. de-referencing for a fetch operation will not cause an error.
  756. A store operation probably causes an error if the '-n' flag is
  757. specified to \fIack\fP [4] or ld [5] while loading your program.
  758. .IE
  759. Some implementations of EM initialize all memory cells for newly
  760. created variables with a constant that probably causes an error if that variable
  761. is not initialized with a value of its own type before use.
  762. For each implementation we give whether memory cells are initialized,
  763. with what value, and whether this value causes an error if de-referenced.
  764. .I1
  765. each memory word is initialized with the bit representation 1000000000000000,
  766. representing -32768 in 2's complement notation.
  767. For most small and medium sized programs this value will cause a segmentation
  768. violation (memory fault, trap 21, fatal).
  769. .I2
  770. no initialization.
  771. Whenever a pointer is de-referenced, without being properly initialized,
  772. a segmentation violation (memory fault, trap 21, fatal)
  773. or 'bus error' are possible.
  774. .IE
  775. .IT 6.5.5
  776. It shall be an error if the value of a file-variable f is altered
  777. while the buffer-variable is an actual variable parameter, or
  778. an element of the record-variable-list of a with-statement, or both.
  779. .IS
  780. This error is not detected
  781. .IT 6.5.5
  782. It shall be an error if the value of a file-variable f is altered
  783. by an assignment-statement which contains the buffer-variable f^ in
  784. its left-hand side.
  785. .IS
  786. This error is not detected.
  787. .IT 6.6.5.2
  788. It shall be an error if
  789. the stated pre-assertion does not hold immediately
  790. prior to any use of the file handling procedures
  791. rewrite, put, reset and get.
  792. .IS
  793. For each of these four operations the pre-assertions
  794. can be reformulated as:
  795. .sp
  796. rewrite(f):~no pre-assertion.
  797. .br
  798. put(f):~~~~~f is opened for writing and f^ is not undefined.
  799. .br
  800. reset(f):~~~f exists.
  801. .br
  802. get(f):~~~~~f is opened for reading and eof(f) is false.
  803. .sp
  804. The following errors are detected for these operations:
  805. .sp
  806. rewrite(f):
  807. .in +10
  808. .ti -5
  809. more args expected, trap 64, fatal:
  810. .br
  811. f is a program-parameter and the corresponding
  812. file name is not supplied by the caller of the program.
  813. .ti -5
  814. rewrite error, trap 101, fatal:
  815. .br
  816. the caller of the program lacks the necessary
  817. access rights to create the file in the file system
  818. or operating system problems like table overflow
  819. prevent creation of the file.
  820. .in -10
  821. .sp
  822. put(f):
  823. .in +10
  824. .ti -5
  825. file not yet open, trap 72, fatal:
  826. .br
  827. reset or rewrite are never applied to the file.
  828. The checks performed by the run time system are not foolproof.
  829. .ti -5
  830. not writable, trap 96, fatal:
  831. .br
  832. f is opened for reading.
  833. .ti -5
  834. write error, trap 104, fatal:
  835. .br
  836. probably caused by file system problems.
  837. For instance, the file storage is exhausted.
  838. Because IO is buffered to improve performance,
  839. it might happen that this error occurs if the
  840. file is closed.
  841. Files are closed whenever they are rewritten or reset, or on
  842. program termination.
  843. .in -10
  844. .sp
  845. reset(f):
  846. .in +10
  847. .ti -5
  848. more args expected, trap 64, fatal:
  849. .br
  850. same as for rewrite(f).
  851. .ti -5
  852. reset error, trap 100, fatal:
  853. .br
  854. f does not exist, or the caller has insufficient access rights, or
  855. operating system tables are exhausted.
  856. .in -10
  857. .sp
  858. get(f):
  859. .in +10
  860. .ti -5
  861. file not yet open, trap 72, fatal:
  862. .br
  863. as for put(f).
  864. .ti -5
  865. not readable, trap 97, fatal:
  866. .br
  867. f is opened for writing.
  868. .ti -5
  869. end of file, trap 98, fatal:
  870. .br
  871. eof(f) is true just before the call to get(f).
  872. .ti -5
  873. read error, trap 103, fatal:
  874. .br
  875. unlikely to happen. Probably caused by hardware problems
  876. or by errors elsewhere in your program that destroyed
  877. the file information maintained by the run time system.
  878. .ti -5
  879. truncated, trap 99, fatal:
  880. .br
  881. the file is not properly formed by an integer
  882. number of file elements.
  883. For instance, the size of a file of integer is odd.
  884. .ti -5
  885. non-ASCII char read, trap 106, non-fatal:
  886. .br
  887. the character value of the next character-type
  888. file element is out of range (0..127).
  889. Only for text files.
  890. .in -10
  891. .IT 6.6.5.3
  892. It shall be an error to change any variant-part of a variable
  893. allocated by the form new(p,c1,...,cn) from the variant specified.
  894. .IS
  895. This error is not detected.
  896. .IT 6.6.5.3
  897. It shall be an error if a variable to be disposed had been allocated
  898. using the form new(p,c1,...,cn) with more variants specified than
  899. specified to dispose.
  900. .IS
  901. This error can cause more memory to be freed then was allocated.
  902. Dispose causes a fatal trap 73 when memory already on the free
  903. list is freed again.
  904. .IT 6.6.5.3
  905. It shall be an error if the variants of a variable to be disposed
  906. are different from those specified by the case-constants to dispose.
  907. .IS
  908. This error is not detected.
  909. .IT 6.6.5.3
  910. It shall be an error if the value of the pointer parameter of dispose has
  911. nil-value or is undefined.
  912. .IS
  913. The same comments apply as for de-referencing NIL or undefined pointers.
  914. .IT 6.6.5.3
  915. It shall be an error if a variable that is identified by the pointer parameter
  916. of dispose (or a component thereof) is currently either an actual
  917. variable parameter, or an element of the record-variable-list of a
  918. with-statement, or both.
  919. .IS
  920. This error is not detected.
  921. .IT 6.6.5.3
  922. It shall be an error if a referenced-variable created using the second form
  923. of new is used in its entirety
  924. as an operand in an expression, or as the variable in an assignment-statement
  925. or as an actual-parameter.
  926. .IS
  927. This error is not detected.
  928. .IT 6.6.6.2
  929. It shall be an error if the mathematical defined result of an
  930. arithmetic function would fall outside the set of values
  931. of the indicated result.
  932. .IS
  933. Except for the errors for undefined arguments,
  934. the following errors may occur for the arithmetic functions:
  935. .in +16
  936. .ti -11
  937. abs(x):~~~~none.
  938. .ti -11
  939. sqr(x):~~~~real underflow, trap 5, non-fatal;
  940. .br
  941. real overflow, trap 4, non-fatal
  942. .ti -11
  943. sin(x):~~~~real underflow, trap 5, non-fatal
  944. .ti -11
  945. cos(x):~~~~real underflow, trap 5, non-fatal
  946. .ti -11
  947. exp(x):~~~~error in exp, trap 65, non-fatal (if x>10000);
  948. .br
  949. real underflow, trap 5, non-fatal;
  950. .br
  951. real overflow, trap 4, non-fatal
  952. .ti -11
  953. ln(x):~~~~~error in ln, trap 66, non-fatal ( if x<=0)
  954. .ti -11
  955. sqrt(x):~~~error in sqrt, trap 67, non-fatal (if x<0)
  956. .ti -11
  957. arctan(x):~real underflow, trap 5, non-fatal;
  958. .br
  959. real overflow, trap 4, non-fatal
  960. .in -16
  961. .IE
  962. .IT 6.6.6.2
  963. It shall be an error if x in ln(x) is not greater than zero.
  964. .IS
  965. See above.
  966. .IT 6.6.6.2
  967. It shall be an error if x in sqrt(x) is negative.
  968. .IS
  969. See above.
  970. .IT 6.6.6.2
  971. It shall be an error if
  972. the integer value of trunc(x) does not exist.
  973. .IS
  974. This error is detected (conversion error, trap 10, non-fatal).
  975. .IT 6.6.6.2
  976. It shall be an error if
  977. the integer value of round(x) does not exist.
  978. .IS
  979. This error is detected (conversion error, trap 10, non-fatal).
  980. .IT 6.6.6.2
  981. It shall be an error if
  982. the integer value of ord(x) does not exist.
  983. .IS
  984. This error can not occur, because the compiler will not allow
  985. such ordinal types.
  986. .IT 6.6.6.2
  987. It shall be an error if
  988. the character value of chr(x) does not exist.
  989. .IS
  990. Except when the r-option is turned off, the compiler generates an EM
  991. range check instruction. The effect of this instruction depends on the
  992. EM implementation as described before.
  993. .IT 6.6.6.2
  994. It shall be an error if the value of succ(x) does not exist.
  995. .IS
  996. Same comments as for chr(x).
  997. .IT 6.6.6.2
  998. It shall be an error if the value of pred(x) does not exist.
  999. .IS
  1000. Same comments as for chr(x).
  1001. .IT 6.6.6.5
  1002. It shall be an error if
  1003. f in eof(f) is undefined.
  1004. .IS
  1005. This error is detected (file not yet open, trap 72, fatal).
  1006. .IT 6.6.6.5
  1007. It shall be an error if
  1008. f in eoln(f) is undefined, or if eof(f) is true at that time.
  1009. .IS
  1010. The following errors may occur:
  1011. .IS
  1012. file not yet open, trap 72, fatal;
  1013. .br
  1014. not readable, trap 97, fatal;
  1015. .br
  1016. end of file, trap 98, fatal.
  1017. .IE
  1018. .IT 6.7.1
  1019. It shall be an error if any variable or function used as an operand in an expression is
  1020. undefined at the time of its use.
  1021. .IS
  1022. Detection of undefined operands is only possible if there is at least one bit
  1023. representation that is not allowed as legal value.
  1024. The set of legal values depends on the type of the operand.
  1025. To detect undefined operands, all newly created variables must be assigned
  1026. a value illegal for the type of the created variable.
  1027. The compiler itself does not generate code to initialize newly created variables.
  1028. Instead, the compiler generates code to allocate some new memory cells.
  1029. It is up to the EM implementation to initialize these memory cells.
  1030. However, the EM machine does not know the types of the variables for which
  1031. memory cells are allocated.
  1032. Therefore, the best an EM implementation can do is to initialize with a value
  1033. that is illegal for the most common types of operands.
  1034. .PP
  1035. For all current EM implementations we will describe whether memory cells
  1036. are initialized, which value is used to initialize, for each operand type
  1037. whether that value is illegal, and for all operations on all operand
  1038. types whether that value is detected as undefined.
  1039. .I1
  1040. \*(ONnew memory words are initialized with -32768.
  1041. Assignment of this value is always allowed. Errors may occur
  1042. whenever undefined operands are used in operations.
  1043. .br
  1044. .ul
  1045. integer:
  1046. -32768 is illegal. All arithmetic operations (except unary +) cause
  1047. an error (undefined integer, trap 8, non-fatal).
  1048. Relational operations do not, except for IN when the left operand is undefined.
  1049. Printing of -32768 using write is allowed.
  1050. .br
  1051. .ul
  1052. real:
  1053. the bit representation of a real, caused by initializing the constituent
  1054. memory words with -32768, is illegal.
  1055. All arithmetic and relational operations (except unary +) cause an error
  1056. (real undefined, trap 9, non-fatal).
  1057. Printing causes the same error.
  1058. .br
  1059. .ul
  1060. char:
  1061. the value -32768 is illegal. For objects of type 'packed array[] of char'
  1062. half the characters will have the value chr(0), which is legal, and the
  1063. others will have the value chr(128), outside the valid ASCII range.
  1064. The relational operators, however, do not cause an error.
  1065. .br
  1066. .ul
  1067. Boolean:
  1068. the value -32768 is illegal. For objects of type 'packed array[] of boolean'
  1069. half the booleans will have the value false, while the others have the value v,
  1070. where ord(v) = 128, naturally illegal.
  1071. However, the Boolean and relational operations do not cause an error.
  1072. .br
  1073. .ul
  1074. set:
  1075. undefined operands of type set can not be distinguished from
  1076. properly initialized ones.
  1077. The set and relational operations, therefore, can never cause an error.
  1078. However, if one forgets to initialize a set of character, then spurious
  1079. characters like '/', '?', 'O', '_' and 'o' appear.
  1080. .sp
  1081. \*(OFnew memory cells are initialized with -32768.
  1082. The only cases where this value causes an error are when
  1083. an undefined operand of type real is used in an arithmetic or relational
  1084. operation (except unary +) or when an undefined real is used as an
  1085. argument to a standard function.
  1086. .I2
  1087. Newly created memory cells are not initialized and therefore
  1088. they have a random value.
  1089. .IT 6.7.1
  1090. It shall be an error if
  1091. the value of any member denoted by any member-designator of the
  1092. set-constructor is outside the implementation-defined limits.
  1093. .IS
  1094. This error is detected (set bound error, trap 2, non-fatal).
  1095. .IT 6.7.1
  1096. It shall be an error if
  1097. the possible types of an set-constructor do not permit it
  1098. to assume a suitable type.
  1099. .IS
  1100. The compiler allocates as many bits as are necessary to store all
  1101. elements of the host-type of the base-type of the set, not the
  1102. base-type itself.
  1103. Therefore, all possible errors can be detected at compile time.
  1104. .IT 6.7.2.2
  1105. It shall be an error if j is zero in 'i div j'.
  1106. .IS
  1107. It depends on the EM implementation whether this error is detected:
  1108. .I1
  1109. \*(ONdetected (divide by 0, trap 6, non-fatal).
  1110. .br
  1111. \*(OFnot detected.
  1112. .I2
  1113. not detected.
  1114. .IE
  1115. .IT 6.7.2.2
  1116. It shall be an error if
  1117. j is zero or negative in i MOD j.
  1118. .IS
  1119. This error is detected (only positive j in 'i mod j', trap 71, non-fatal).
  1120. .IT 6.7.2.2
  1121. It shall be an error if the result of any operation on integer
  1122. operands is not performed according to the mathematical
  1123. rules for integer arithmetic.
  1124. .IS
  1125. The reaction depends on the EM implementation:
  1126. .I1
  1127. \*(ONerror detected if
  1128. .EQ
  1129. (result >= 32768) or (result < -32768).
  1130. .EN
  1131. (integer overflow, trap 3, non-fatal).
  1132. Note that if the result is -32768 the use of this value in further operations
  1133. may cause an error.
  1134. .br
  1135. \*(OFnot detected.
  1136. .I2
  1137. not detected.
  1138. .IT 6.8.3.5
  1139. It shall be an error if none of the case-constants is equal to the value of the
  1140. case-index upon entry to the case-statement.
  1141. .IS
  1142. This error is detected (case error, trap 20, fatal).
  1143. .IT 6.8.3.9
  1144. It shall be an error if the final-value of a for-statement is not
  1145. assignment-compatible with the control-variable when the
  1146. initial-value is assigned to the control-variable.
  1147. .IS
  1148. It is detected if the control variable leaves
  1149. its allowed range of values while stepping
  1150. from initial to final value.
  1151. This is equivalent with the requirements if the
  1152. for-statement is not terminated before
  1153. the final value is reached.
  1154. .IT 6.9.2
  1155. It shall be an error if the sequence of characters read looking for an integer does not
  1156. form a signed-integer as specified in 6.1.5.
  1157. .IS
  1158. This error is detected (digit expected, trap 105, non-fatal).
  1159. .IT 6.9.2
  1160. It shall be an error if the sequence of characters read looking for a real does not
  1161. form a signed-number as specified in 6.1.5.
  1162. .IS
  1163. This error is detected (digit expected, trap 105, non-fatal).
  1164. .IT 6.9.2
  1165. It shall be an error if read is applied to f while f is undefined or
  1166. not opened for reading.
  1167. .IS
  1168. This error is detected (see get(f)).
  1169. .IT 6.9.4
  1170. It shall be an error if write is applied to f while f is undefined or
  1171. not opened for writing.
  1172. .IS
  1173. This error is detected (see put(f)).
  1174. .IT 6.9.4
  1175. It shall be an error if TotalWidth or FracDigits as specified in
  1176. write or writeln procedure calls are less than one.
  1177. .IS
  1178. This error is not detected. Moreover, it is considered an extension to
  1179. allow zero or negative values.
  1180. .IT 6.9.6
  1181. It shall be an error if page is applied to f while f is undefined or
  1182. not opened for writing.
  1183. .IS
  1184. This error is detected (see put(f)).
  1185. .CH "Extensions to the standard"
  1186. .IS
  1187. .ti -3
  1188. 1.~\
  1189. Separate compilation.
  1190. .sp
  1191. The compiler is able to (separately) compile a collection of declarations,
  1192. procedures and functions to form a library.
  1193. The library may be linked with the main program, compiled later.
  1194. The syntax of these modules is
  1195. .EQ
  1196. module = [constant-definition-part]
  1197. [type-definition-part]
  1198. [var-declaration-part]
  1199. [procedure-and-function-declaration-part]
  1200. .EN
  1201. The compiler accepts a program or a module:
  1202. .EQ
  1203. unit = program | module
  1204. .EN
  1205. All variables declared outside a module must be imported
  1206. by parameters, even the files input and output.
  1207. Access to a variable declared in a module is only possible
  1208. using the procedures and functions declared in that same module.
  1209. By giving the correct procedure/function heading followed by the
  1210. directive 'extern' you may use procedures and functions declared in
  1211. other units.
  1212. .sp
  1213. .ti -3
  1214. 2.~\
  1215. Assertions.
  1216. .sp
  1217. The Ack-Pascal compiler recognizes an additional statement, the assertion.
  1218. Assertions can be used as an aid in debugging and documentation.
  1219. The syntax is:
  1220. .EQ
  1221. assertion = 'assert' Boolean-expression
  1222. .EN
  1223. An assertion is a simple-statement, so
  1224. .EQ
  1225. simple-statement = [assignment-statement |
  1226. procedure-statement |
  1227. goto-statement |
  1228. assertion
  1229. ]
  1230. .EN
  1231. An assertion causes an error if the Boolean-expression is false.
  1232. That is its only purpose.
  1233. It does not change any of the variables, at least it should not.
  1234. Therefore, do not use functions with side-effects in the Boolean-expression.
  1235. If the a-option is turned off, then assertions are skipped by the
  1236. compiler. 'assert' is not a word-symbol (keyword) and may be used as identifier.
  1237. However, assignment to a variable and calling of a procedure with that name will be impossible.
  1238. .sp
  1239. .ti -3
  1240. 3.~\
  1241. Additional procedures.
  1242. .sp
  1243. Three additional standard procedures are available:
  1244. .IS
  1245. .IS
  1246. .ti -8
  1247. halt:~~~a call of this procedure is equivalent to jumping to the
  1248. end of your program. It is always the last statement executed.
  1249. The exit status of the program may be supplied
  1250. as optional argument.
  1251. .ti -8
  1252. release:
  1253. .ti -8
  1254. mark:~~~for most applications it is sufficient to use the heap as second stack.
  1255. Mark and release are suited for this type of use, more suited than dispose.
  1256. mark(p), with p of type pointer, stores the current value of the
  1257. heap pointer in p. release(p), with p initialized by a call
  1258. of mark(p), restores the heap pointer to its old value.
  1259. All the heap objects, created by calls of new between the call of
  1260. mark and the call of release, are removed and the space they used
  1261. can be reallocated.
  1262. Never use mark and release together with dispose!
  1263. .sp
  1264. .in -10
  1265. .ti -3
  1266. 4.~\
  1267. UNIX interfacing.
  1268. .sp
  1269. If the c-option is turned on, then some special features are available
  1270. to simplify an interface with the UNIX environment.
  1271. First of all, the compiler allows you to use a different type
  1272. of string constants.
  1273. These string constants are delimited by double quotes ('"').
  1274. To put a double quote into these strings, you must repeat the double quote,
  1275. like the single quote in normal string constants.
  1276. These special string constants are terminated by a zero byte (chr(0)).
  1277. The type of these constants is a pointer to a packed array of characters,
  1278. with lower bound 1 and unknown upper bound.
  1279. .br
  1280. Secondly, the compiler predefines a new type identifier 'string' denoting
  1281. this just described string type.
  1282. .PP
  1283. The only thing you can do with these features is declaration of
  1284. constants and variables of type 'string'.
  1285. String objects may not be allocated on the heap and string pointers
  1286. may not be de-referenced.
  1287. Still these strings are very useful in combination with external routines.
  1288. The procedure write is extended to print these zero-terminated strings correctly.
  1289. .sp
  1290. .ti -3
  1291. 5.~\
  1292. Double length (32 bit) integers.
  1293. .sp
  1294. If the d-option is turned on, then the additional type 'long' is known to the compiler.
  1295. Long variables have integer values in the range -2147483647..+2147483647.
  1296. Long constants may be declared.
  1297. It is not allowed to form subranges of type long.
  1298. All operations allowed on integers are also
  1299. allowed on longs and are indicated by the same
  1300. operators: '+', '-', '*', '/', 'div', 'mod'.
  1301. The procedures read and write have been extended to handle long arguments correctly.
  1302. The default width for longs is 11.
  1303. The standard procedures 'abs' and 'sqr' have been extended to work on long arguments.
  1304. Conversion from integer to long, long to real,
  1305. real to long and long to integer are automatic, like the conversion from integer to real.
  1306. These conversions may cause a
  1307. .IS
  1308. conversion error, trap 10, non-fatal
  1309. .IE
  1310. This last error is only detected in implementation 1, with 'test on'.
  1311. Note that all current implementations use target
  1312. machine floating point instructions
  1313. to perform some of the long operations.
  1314. .sp
  1315. .ti -3
  1316. 6.~\
  1317. Underscore as letter.
  1318. .sp
  1319. The character '_' may be used in forming identifiers, if the u-option is turned on.
  1320. .sp
  1321. .ti -3
  1322. 7.~\
  1323. Zero field width in write.
  1324. .sp
  1325. Zero or negative TotalWidth arguments to write
  1326. are allowed.
  1327. No characters are written for character, string or Boolean type arguments then.
  1328. A zero or negative FracDigits argument for fixed-point representation of reals causes the
  1329. fraction and the character '.' to be suppressed.
  1330. .sp
  1331. .ti -3
  1332. 8.~\
  1333. Alternate symbol representation.
  1334. .sp
  1335. The comment delimiters '(*' and '*)' are recognized and treated like '{' and '}'.
  1336. The other alternate representations of symbols are not recognized.
  1337. .sp
  1338. .ti -3
  1339. 9.~\
  1340. Pre-processing.
  1341. .sp
  1342. If the very first character of a file containing a Pascal
  1343. program is the sharp ('#', ASCII 23(hex)) the file is preprocessed
  1344. in the same way as C programs.
  1345. Lines beginning with a '#' are taken as preprocessor command lines
  1346. and not fed to the Pascal compiler proper.
  1347. C style comments, /*......*/, are removed by the C preprocessor,
  1348. thus C comments inside Pascal programs are also removed when they
  1349. are fed through the preprocessor.
  1350. .CH "Deviations from the standard"
  1351. Ack-Pascal deviates from the (March 1980) standard proposal in the following ways:
  1352. .IS
  1353. .ti -3
  1354. 1.~\
  1355. Only the first 8 characters of identifiers are significant,
  1356. as requested by all standard proposals prior to March 1980.
  1357. In that proposal, however, the sentence
  1358. .DS
  1359. "A conforming program should not have its meaning altered
  1360. by the truncation of its identifiers to eight characters
  1361. or the truncation of its labels to four digits."
  1362. .DE
  1363. is missing.
  1364. .sp
  1365. .ti -3
  1366. 2.~\
  1367. The character sequences 'procedur', 'procedur8', 'functionXyZ' etc. are
  1368. all erroneously classified as the word-symbols 'procedure' and 'function'.
  1369. .sp
  1370. .ti -3
  1371. 3.~\
  1372. Standard procedures and functions are not allowed as parameters in Ack-Pascal,
  1373. conforming to all previous standard proposals.
  1374. You can obtain the same result with negligible loss of performance
  1375. by declaring some user routines like:
  1376. .EQ
  1377. function sine(x:real):real;
  1378. begin
  1379. sine:=sin(x)
  1380. end;
  1381. .EN
  1382. .sp
  1383. .ti -3
  1384. 4.~\
  1385. The scope of identifiers and labels should start at the beginning of the block
  1386. in which these identifiers or labels are declared.
  1387. The Ack-Pascal compiler, as most other one pass compilers, deviates in this respect,
  1388. because the scope of variables and labels start
  1389. at their defining-point.
  1390. .CH "Compiler options"
  1391. Some options of the compiler may be controlled by using "{$....}".
  1392. Each option consists of a lower case letter followed by +, - or an unsigned
  1393. number.
  1394. Options are separated by commas.
  1395. The following options exist:
  1396. .in 8
  1397. .sp
  1398. .ti -8
  1399. a~+/-~~~\
  1400. this option switches assertions on and off.
  1401. If this option is on, then code is included to test these assertions
  1402. at run time. Default +.
  1403. .sp
  1404. .ti -8
  1405. c~+/-~~~\
  1406. this option, if on, allows you to use C-type string constants
  1407. surrounded by double quotes.
  1408. Moreover, a new type identifier 'string' is predefined.
  1409. Default -.
  1410. .sp
  1411. .ti -8
  1412. d~+/-~~~\
  1413. this option, if on, allows you to use variables of type 'long'.
  1414. Default -.
  1415. .sp
  1416. .ti -8
  1417. f~<num>~\
  1418. the size of reals can be changed by this option. <num> should be specified in 8-bit bytes.
  1419. The default in most implementations is 8, but other values can
  1420. occur.
  1421. .sp
  1422. .ti -8
  1423. i~<num>~\
  1424. with this flag the setsize for a set of integers can be
  1425. manipulated.
  1426. The number must be the number of bits per set.
  1427. The default value is 16, just fitting in one word on the PDP and many other minis.
  1428. .sp
  1429. .ti -8
  1430. l~+/-~~~\
  1431. if + then code is inserted to keep track of the source line number.
  1432. When this flag is switched on and off, an incorrect line number may appear
  1433. if the error occurs in a part of your program for which this flag is off.
  1434. These same line numbers are used for the profile, flow and count options
  1435. of the EM interpreter em [6].
  1436. Default +.
  1437. .sp
  1438. .ti -8
  1439. p~<num>~the size of pointers can be changed by this option. <num> should be specified in bytes.
  1440. Default 2 in most implementations.
  1441. .sp
  1442. .ti -8
  1443. r~+/-~~~\
  1444. if + then code is inserted to check subrange variables against
  1445. lower and upper subrange limits.
  1446. Default +.
  1447. .sp
  1448. .ti -8
  1449. s~+/-~~~\
  1450. if + then the compiler will hunt for places in your program
  1451. where non-standard features are used, and for each place found
  1452. it will generate a warning. Default -.
  1453. .sp
  1454. .ti -8
  1455. t~+/-~~~\
  1456. if + then each time a procedure is entered, the routine 'procentry'
  1457. is called.
  1458. The compiler checks this flag just before the first symbol that follows the
  1459. first 'begin' of the body of the procedure.
  1460. Also, when the procedure exits, then the procedure 'procexit' is called
  1461. if the t flag is on just before the last 'end' of the procedure body.
  1462. Both 'procentry' and 'procexit' have a packed array of 8 characters as a parameter.
  1463. Default procedures are present in the run time library.
  1464. Default -.
  1465. .sp
  1466. .ti -8
  1467. u~+/-~~~\
  1468. if + then the character '_' is treated like a lower case letter,
  1469. so that it may be used in identifiers.
  1470. Procedure and function identifiers starting with an underscore may cause problems,
  1471. because they may collide with library routine names.
  1472. Default -.
  1473. .in 0
  1474. .sp
  1475. Seven of these flags (c, d, f, i, p, s and u) are only effective when they appear
  1476. before the 'program' symbol. The others may be switched on and off.
  1477. .PP
  1478. A second method of passing options to the compiler ia available.
  1479. This method uses the file on which the compact EM code will be written.
  1480. The compiler starts reading from this file scanning for options
  1481. in the same format as used normally, except for the comment delimiters and
  1482. the dollar sign.
  1483. All options found on the file override the options set in your program.
  1484. Note that the compact code file must always exist before the compiler is called.
  1485. .PP
  1486. The user interface program \fIack\fP[4]
  1487. takes care of creating this file normally
  1488. and also writes one of its options onto this file.
  1489. The user can specify, for instance, without changing any character in its
  1490. Pascal program, that the compiler must include code for
  1491. procedure/function tracing.
  1492. .PP
  1493. Another very powerful debugging tool is the knowledge that inaccessible
  1494. statements and useless tests are removed by the EM optimizer.
  1495. For instance, a statement like:
  1496. .sp
  1497. .nf
  1498. if debug then
  1499. writeln('initialization done');
  1500. .fi
  1501. .sp
  1502. is completely removed by the optimizer if debug is a constant with
  1503. value false.
  1504. The first line is removed if debug is a constant with value true.
  1505. Of course, if debug is a variable nothing can be removed.
  1506. .PP
  1507. A disadvantage of Pascal, the lack of preinitialized data, can be
  1508. diminished by making use of the possibilities of the EM optimizer.
  1509. For instance, initializing an array of reserved words is sometimes
  1510. optimized into 3 EM instructions. To maximize this effect you must initialize
  1511. variables as much as possible in order of declaration and array entries
  1512. in order of decreasing index.
  1513. .CH "References"
  1514. .in +5
  1515. .ti -5
  1516. [1]~~\
  1517. ISO standard proposal ISO/TC97/SC5-N462, dated February 1979.
  1518. The same proposal, in slightly modified form, can be found in:
  1519. A.M.Addyman e.a., "A draft description of Pascal",
  1520. Software, practice and experience, May 1979.
  1521. An improved version, received March 1980,
  1522. is followed as much as possible for the
  1523. current Ack-Pascal.
  1524. .sp
  1525. .ti -5
  1526. [2]~~\
  1527. A.S.Tanenbaum, J.W.Stevenson, Hans van Staveren, E.G.Keizer,
  1528. "Description of a machine architecture for use with block structured languages",
  1529. Informatica rapport IR-81.
  1530. .sp
  1531. .ti -5
  1532. [3]~~\
  1533. W.S.Brown, S.I.Feldman, "Environment parameters and basic functions
  1534. for floating-point computation",
  1535. Bell Laboratories CSTR #72.
  1536. .sp
  1537. .ti -5
  1538. [4]~~\
  1539. UNIX manual ack(I).
  1540. .sp
  1541. .ti -5
  1542. [5]~~\
  1543. UNIX manual ld(I).
  1544. .sp
  1545. .ti -5
  1546. [6]~~\
  1547. UNIX manual em(I).
  1548. .sp
  1549. .ti -5
  1550. [7]~~\
  1551. UNIX manual libpc(VII)
  1552. .sp
  1553. .ti -5
  1554. [8]~~\
  1555. UNIX manual pc_prlib(VII)