pc_prlib.7 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. .\" $Id$
  2. .TH PC_PRLIB 7 "$Revision$"
  3. .ad
  4. .SH NAME
  5. pc_prlib \- library of Pascal runtime routines
  6. .SH SYNOPSIS
  7. .ta 11n 22n 33n 44n 55n
  8. .nf
  9. type alpha=packed array[1..8] of char;
  10. pstring= ^packed array[] of char;
  11. function _abi(i:integer):integer;
  12. function _abl(i:long):long;
  13. function _mdi(j,i:integer):integer;
  14. function _mdl(j,i:long):long;
  15. function _dvi(j,i:integer):integer;
  16. function _dvl(j,i:long):long;
  17. function _abr(r:real):real;
  18. function _sin(r:real):real;
  19. function _cos(r:real):real;
  20. function _atn(r:real):real;
  21. function _exp(r:real):real;
  22. function _log(r:real):real;
  23. function _sqt(r:real):real;
  24. function _rnd(r:real):real;
  25. type compared=-1..1;
  26. gotoinfo=record
  27. pcoffset:^procedure; { procedure id. without static link }
  28. nlocals: integer;
  29. end;
  30. type arrdescr=record
  31. lowbnd: integer;
  32. diffbnds:integer;
  33. elsize: integer;
  34. end;
  35. arr1=array[] of ?;
  36. arr2=packed array[] of ?;
  37. function _bcp(sz:integer; s2,s1:pstring):compared;
  38. function _bts(size,high,low:integer; base:^set 0..(8*size-1))
  39. :set of 0..(8*size-1);
  40. procedure _gto(lb:^integer; p:^gotoinfo);
  41. procedure _rcka(a: arrdescr; index : integer);
  42. procedure _nfa(bool:integer);
  43. procedure _new(size:integer; var p:^integer);
  44. procedure _dis(size:integer; var p:^integer);
  45. procedure _sav(var p:^integer);
  46. procedure _rst(var p:^integer);
  47. procedure _pac(var ad,zd:arrdescr; var zp:arr2; i:integer;
  48. var ap:arr1);
  49. procedure _unp(var ad,zd:arrdescr; i:integer; var ap:arr1;
  50. var zp:arr2;nosgnext:boolean);
  51. function _asz(var dp:arrdescr):integer;
  52. procedure _ass(line:integer; b:boolean);
  53. procedure procentry(name:pstring);
  54. procedure procexit(name:pstring);
  55. const lowbyte=[0..7];
  56. MAGIC =[1,3,5,7];
  57. WINDOW =[11];
  58. ELNBIT =[12];
  59. EOFBIT =[13];
  60. TXTBIT =[14];
  61. WRBIT =[15];
  62. PC_BUFLEN =1024;
  63. type file=record
  64. ptr: ^char;
  65. flags: set of [0..15];
  66. fname: pstring;
  67. ufd: 0..15;
  68. size: integer;
  69. count: 0..buflen;
  70. buflen: max(PC_BUFLEN,size) div size * size;
  71. bufadr: packed array[1..max(PC_BUFLEN,size)]
  72. of char;
  73. end;
  74. filep=^file;
  75. const NFILES=15;
  76. _extfl:^array[] of filep;
  77. procedure _ini(args:pstring; var c:integer;
  78. var p:array[] of filep; mainlb:pstring);
  79. procedure _hlt(status:0..255);
  80. procedure _opn(size:integer; f:filep);
  81. procedure _cre(size:integer; f:filep);
  82. procedure _cls(f:filep);
  83. procedure _get(f:filep);
  84. procedure _put(f:filep);
  85. function _wdw(f:filep):^char;
  86. function _efl(f:filep):boolean;
  87. function _eln(f:filep):boolean;
  88. function _rdc(f:filep):char;
  89. function _rdi(f:filep):integer;
  90. function _rdl(f:filep):long;
  91. function _rdr(f:filep):real;
  92. procedure _rln(f:filep);
  93. procedure _wrc(c:char; f:filep);
  94. procedure _wsc(w:integer; c:char; f:filep);
  95. procedure _wri(i:integer; f:filep);
  96. procedure _wsi(w:integer; i:integer; f:filep);
  97. procedure _wrl(l:long; f:filep);
  98. procedure _wsl(w:integer; l:long; f:filep);
  99. procedure _wrr(r:real; f:filep);
  100. procedure _wsr(w:integer; r:real; f:filep);
  101. procedure _wrf(ndigit:integer; w:integer; r:real; f:filep);
  102. procedure _wrs(l:integer; s:pstring; f:filep);
  103. procedure _wss(w:integer; l:integer; s:pstring; f:filep);
  104. procedure _wrb(b:boolean; f:filep);
  105. procedure _wsb(w:integer; b:boolean; f:filep);
  106. procedure _wrz(s:string; f:filep);
  107. procedure _wsz(w:integer; s:string; f:filep);
  108. procedure _wln(f:filep);
  109. procedure _pag(f:filep);
  110. .fi
  111. .SH DESCRIPTION
  112. This library is used by the Pascal to EM compiler and
  113. contains all the runtime routines for standard Pascal programs.
  114. Most routines are written in C, a few in EM assembly language.
  115. These routines can be divided into several categories.
  116. A description of each category with its routines follows.
  117. .PP
  118. Arithmetic routines:
  119. .RS
  120. .IP _abi
  121. Compute the absolute value of an integer.
  122. .PD 0
  123. .IP _abl
  124. Compute the absolute value of a long.
  125. .IP _mdi
  126. Perform the Pascal modulo operation on integers.
  127. .IP _mdl
  128. Perform the Pascal modulo operation on longs.
  129. .IP _dvi
  130. Perform the Pascal divide operation on integers.
  131. .IP _dvl
  132. Perform the Pascal divide operation on longs.
  133. .IP _abr
  134. Compute the absolute value of a real.
  135. .IP _sin
  136. Compute the sine of a real.
  137. .IP _cos
  138. Compute the cosine of a real.
  139. .IP _atn
  140. Compute the arc tangent of a real.
  141. .IP _exp
  142. Compute the e-power of a real.
  143. .IP _log
  144. Compute the natural logarithm of a real.
  145. .IP _sqt
  146. Compute the square root of a real.
  147. .IP _rnd
  148. Return a real that when truncated will
  149. result in the nearest integer (-3.5->-4).
  150. .PD
  151. .PP
  152. .RE
  153. Miscellaneous routines:
  154. .RS
  155. .IP _bcp
  156. Compare two strings. Use dictionary ordering with the ASCII
  157. character set. The EM instruction CMU can not be used, because it needs
  158. an even number of bytes.
  159. .PD 0
  160. .IP _bts
  161. Include a range of elements from low to high in a set of size bytes
  162. at address base.(size can be divided by the wordsize)
  163. .IP _gto
  164. Execute a non-local goto. Lb points to the
  165. local base of the target procedure.
  166. A lb of zero indicates a jump to the program body, the lb of the main
  167. program is found in _m_lb, which is set by _ini.
  168. The new EM stack pointer is calculated by adding the number of locals
  169. to the new local base
  170. (jumping into statements is not allowed; there are no local generators
  171. in Pascal!).
  172. .IP _rcka
  173. Check if an array reference isn't out of bounds. This is should be done by
  174. the backends, but some don't.
  175. .IP _nfa
  176. Check whether a function is assigned or not. This could have
  177. been done by the compiler, but that would make the interface between the
  178. compiler and the run-time library messier.
  179. .PD
  180. .PP
  181. .RE
  182. Heap management:
  183. .RS
  184. .PP
  185. There is one way to allocate new heap space (_new), but two different
  186. incompatible ways to deallocate it.
  187. .PP
  188. The most general one is by using dispose (_dis).
  189. A circular list of free blocks, ordered from low to high addresses, is maintained.
  190. Merging free blocks is done when a new block enters the free list.
  191. When a new block is requested (_new), the free list is searched using a
  192. first fit algorithm.
  193. Two global variables are needed:
  194. .IP _highp 10
  195. Points to the free block with the highest address.
  196. .PD 0
  197. .IP _lastp
  198. Points to the most recently entered free block or to a block
  199. in the neighborhood of the most recently allocated block.
  200. .PD
  201. The free list is empty, when one of these pointers (but then at the same
  202. time both) is zero.
  203. .PP
  204. The second way to deallocate heap space is by using
  205. mark (_sav) and release (_rst). Mark saves the current value of the
  206. heap pointer HP in the program variable passed as a parameter.
  207. By calling release with this old HP value as its argument, the old HP value
  208. is restored, effectively deallocating all blocks requested between
  209. the calls to mark and release.
  210. The heap is used as second stack in this case.
  211. .PP
  212. It will be clear that these two ways of deallocating heap space
  213. can not be used together.
  214. To be able to maintain the free list, all blocks must be a multiple
  215. of n bytes long, with a minimum of n bytes,
  216. where n is the sum of the size of a word and a pointer in the
  217. EM implementation used.
  218. .PP
  219. In summary:
  220. .IP _new
  221. Allocate heap space.
  222. .PD 0
  223. .IP _dis
  224. Deallocate heap space.
  225. .IP _sav
  226. Save the current value of HP.
  227. .IP _rst
  228. Restore an old value of HP.
  229. .PD
  230. .PP
  231. .RE
  232. Array operations:
  233. .RS
  234. .PP
  235. The only useful form of packing implemented, is packing bytes into words.
  236. All other forms of packing and unpacking result in a plain copy.
  237. .IP _pac
  238. Pack an unpacked array \fIa\fP into a packed array \fIz\fP.
  239. \fIap\fP and \fIzp\fP
  240. are pointers to \fIa\fP and \fIz\fP. \fIad\fP and \fIzd\fP
  241. are pointers to the descriptors of \fIa\fP and \fIz\fP. \fIi\fP is
  242. the index in \fIa\fP of the first element to be packed.
  243. Pack until \fIz\fP is full.
  244. .PD 0
  245. .IP _unp
  246. Unpack \fIz\fP into \fIa\fP.
  247. \fIap\fP, \fIzp\fP, \fIad\fP and \fIzd\fP are as for _pac. \fIi\fP is
  248. the index in \fIa\fP where the first element of \fIz\fP is copied into.
  249. Unpack all elements of \fIz\fP. The boolean flag \fInosgnext\fP indicates
  250. whether the values should or should not be sign-extended.
  251. .IP _asz
  252. Compute array size. Used for copying conformant arrays.
  253. .PD
  254. .PP
  255. .RE
  256. Debugging facilities:
  257. .RS
  258. The compiler allows for the verification of assertions.
  259. It generates a call to the routine _ass to check the assertion at runtime.
  260. Another feature of the compiler is that it enables the user to trace the
  261. procedure calling sequence. If the correct option is turned on, then
  262. a call to the procedure \fIprocentry\fP is generated at the start of each
  263. compiled procedure or function. Likewise, the routine \fIprocexit\fP is called
  264. just before a procedure or function exits.
  265. Default procedure \fIprocentry\fP
  266. and \fIprocexit\fP are available in this library.
  267. .IP _ass 10
  268. If \fIb\fP is zero, then change eb[0] to \fIline\fP
  269. (to give an error message with source line number) and call the error routine.
  270. .PD 0
  271. .IP procentry
  272. Print the name of the called procedure on standard output. Output must
  273. be declared in the program heading.
  274. .IP procexit
  275. Print the name of the procedure that is about to exit. Output must
  276. be declared in the program heading.
  277. .PD
  278. .PP
  279. .RE
  280. Files:
  281. .RS
  282. .PP
  283. Most of the runtime routines are needed for file handling.
  284. For each file in the Pascal program a record of type file, as described
  285. above, is allocated, static if this file is declared in the outermost block,
  286. dynamic if it is declared in inner blocks.
  287. The fields in the file record are used for:
  288. .IP bufadr 10
  289. IO is buffered except for standard input and output if
  290. terminals are involved. The size of the buffer is the maximum of PC_BUFLEN
  291. and the file element size.
  292. .PD 0
  293. .IP buflen
  294. The effective buffer length is the maximum number of file elements
  295. fitting in the buffer, multiplied by the element size.
  296. .IP size
  297. The file element size (1 or even).
  298. .IP flags
  299. Some flag bits are stored in the high byte and a magic pattern
  300. in the low byte provides detection of destroyed file
  301. information.
  302. .IP ptr
  303. Points to the file window inside the buffer.
  304. .IP count
  305. The number of bytes (the window inclusive) left in the buffer
  306. to be read or the number of free bytes (the window inclusive) for output files.
  307. .IP ufd
  308. The UNIX file descriptor for the file.
  309. .IP fname
  310. Points to the name of the file (INPUT for standard input,
  311. OUTPUT for standard output and LOCAL for local files).
  312. This field is used for generating error messages.
  313. .PD
  314. .PP
  315. The constants used by the file handling routines are:
  316. .IP WINDOW 10
  317. Bit in flags set if the window of an input file is initialized.
  318. Used to resolve the famous interactive input problem.
  319. .PD 0
  320. .IP EOFBIT
  321. Bit in flags set if end of file seen
  322. .IP ELNBIT
  323. Bit in flags set if linefeed seen
  324. .IP TXTBIT
  325. Bit in flags set for text files. Process linefeeds.
  326. .IP WRBIT
  327. Bit in flags set for output files
  328. .IP MAGIC
  329. Pattern for the low byte of flags
  330. .IP NFILES
  331. The maximum number of open files in UNIX
  332. .PD
  333. .PP
  334. .RE
  335. Prelude and postlude:
  336. .RS
  337. .PP
  338. These routines are called once for each Pascal program:
  339. .IP _ini
  340. When a file mentioned in the program heading is opened by reset or
  341. rewrite, its file pointer must be mapped onto one of the program
  342. arguments.
  343. The compiler knows how to map and therefore builds a table with
  344. a pointer to the file structure for each program argument.
  345. One of the first actions of the Pascal program is to call this procedure
  346. with this table as an argument.
  347. The global variable _extfl is used to save the address of this table.
  348. Another task of _ini is to initialize the standard input and output files.
  349. For standard output it must decide whether to buffer or not.
  350. If standard output is a terminal, then buffering is off by setting
  351. buflen to 1.
  352. Two other task of _ini are the copying of two variables from
  353. the argument list to global memory, mainlb to _m_lb and c to _extflc.
  354. The first contains the local base of the program body, the second
  355. contains the number of paremeters the program is called with.
  356. A last task of _ini is to set the global variables _pargc, _pargv and
  357. _penvp from args for possible reference later on.
  358. Args points to the argument count placed on the stack by the EM runtime system,
  359. see chapter 8 in [1].
  360. .PD 0
  361. .IP _hlt
  362. If the program is about to finish, the buffered files must be flushed.
  363. That is done by this procedure.
  364. .PD
  365. .PP
  366. .RE
  367. Opening and closing:
  368. .RS
  369. .PP
  370. Files in Pascal are opened for reading by reset and opened for writing by
  371. rewrite.
  372. Files to be rewritten may or may not exist already.
  373. Files not mentioned in the program heading are considered local files.
  374. The next steps must be done for reset and rewrite:
  375. .IP 1.
  376. If size is zero, then a text file must be opened with elements of
  377. size 1.
  378. .PD 0
  379. .IP 2.
  380. Find out if this file is mentioned in the program heading
  381. (scan table pointed to by _extfl).
  382. If not, then it is a local file and goto 7.
  383. .IP 3.
  384. If the file is standard input or output then return.
  385. .IP 4.
  386. If there are not enough arguments supplied, generate an error.
  387. .IP 5.
  388. If the file was already open, flush the buffer if necessary and close it.
  389. Note that reset may be used to force the buffer to be flushed.
  390. This is sometimes helpful against program or system crashes.
  391. .IP 6.
  392. If it is a reset, open the file, otherwise create it.
  393. In both cases goto 9.
  394. .IP 7.
  395. If the local file is to be written, then close it if it was open and
  396. create a new nameless file. First try to create it in /usr/tmp, then in /tmp
  397. and if both fail then try the current directory.
  398. See to it that the file is open for both reading and writing.
  399. .IP 8.
  400. If the local file is to be read
  401. and the file is opened already, then
  402. flush the buffer and seek to the beginning.
  403. Otherwise open a temporary file as described in 7.
  404. .IP 9.
  405. Initialize all the file record fields.
  406. .PD
  407. .PP
  408. The necessary procedures are:
  409. .IP _opn
  410. Reset a file
  411. .PD 0
  412. .IP _cre
  413. Rewrite a file
  414. .IP _cls
  415. Close a file. Closing of files is done for local files when the procedure
  416. in which they are declared exits.
  417. The compiler only closes local files if they are not part of a structured type.
  418. Files allocated in the heap are not closed when they are deallocated.
  419. There is an external routine \fIpclose\fP in libpc(7), that may be called
  420. explicitly to do the closing in these cases.
  421. Closing may be necessary to flush buffers or to keep the number of
  422. simultaneously opened files below NFILES.
  423. Files declared in the outermost block are automatically closed when the
  424. program terminates.
  425. .PD
  426. .PP
  427. .RE
  428. General file IO:
  429. .RS
  430. .PP
  431. These routines are provided for general file IO:
  432. .IP _put
  433. Append the file element in the window to the file and advance the
  434. window.
  435. .IP _get
  436. Advance the file window so that it points to the next element
  437. of the file.
  438. For text files (TXTBIT on) the ELNBIT in flags is set if the new character
  439. in the window is a line feed (ASCII 10) and the character is then changed
  440. into a space.
  441. Otherwise the ELNBIT is cleared.
  442. .IP _wdw
  443. Return the current pointer to the file window.
  444. .IP _efl
  445. Test if end of file is reached.
  446. Is always true for output files.
  447. .PD
  448. .PP
  449. .RE
  450. Textfile routines:
  451. .RS
  452. .PP
  453. The rest of the routines all handle text files.
  454. .IP _eln
  455. Return true if the next character on an input file is an end-of-line marker.
  456. An error occurs if eof(f) is true.
  457. .PD 0
  458. .IP _rdc
  459. Return the character currently in the window and advance the window.
  460. .IP _rdi
  461. Build an integer from the next couple of characters on the file,
  462. starting with the character in the window.
  463. The integer may be preceded by spaces (and line feeds), tabs and a sign.
  464. There must be at least one digit.
  465. The first non-digit signals the end of the integer.
  466. .IP _rdl
  467. Like _rdi, but for longs.
  468. .IP _rdr
  469. Like _rdi, but for reals. Syntax is as required for Pascal.
  470. .IP _rln
  471. Skips the current line and clears the WINDOW flag, so that the
  472. next routine requiring an initialized window knows that it has to
  473. fetch the next character first.
  474. .IP _wrc
  475. Write a character, not preceeded by spaces.
  476. .IP _wsc
  477. Write a character, left padded with spaces up to a field width
  478. of \fIw\fP.
  479. .IP _wri
  480. Write an integer, left padded with spaces up to a field width
  481. of 6 on 2-byte machines and a field width of 11 on 4-byte machines.
  482. .IP _wsi
  483. Write an integer, left padded with spaces up to a field width
  484. of \fIw\fP.
  485. .IP _wrl
  486. Write a long, left padded with spaces up to a field width
  487. of 11.
  488. .IP _wsl
  489. Write a long, left padded with spaces up to a field width
  490. of \fIw\fP.
  491. .IP _wrr
  492. Write a real in scientific format,
  493. left padded with spaces up to a field width of 13.
  494. .IP _wsr
  495. Write a real in scientific format,
  496. left padded with spaces up to a field width of \fIw\fP.
  497. .IP _wrf
  498. Write a real in fixed point format, with exactly \fIndigit\fP digits
  499. behind the decimal point, the last one rounded; it is left padded up to
  500. a field width of \fIw\fP.
  501. .IP _wrs
  502. Write a string of length \fIl\fP, without additional spaces.
  503. .IP _wss
  504. Write a string of length \fIl\fP, left padded up to a field
  505. width of \fIw\fP.
  506. .IP _wrb
  507. Write a boolean, represented by "true" or "false", left padded
  508. up to a field width of 5.
  509. .IP _wsb
  510. Write a boolean, represented by "true" or "false", left padded
  511. up to a field width of \fIw\fP.
  512. .IP _wrz
  513. Write a C-type string up to the zero-byte.
  514. .IP _wsz
  515. Write a C-type string, left padded up to a field width of w.
  516. .IP _wln
  517. Write a line feed (ASCII 10).
  518. .IP _pag
  519. Write a form feed (ASCII 12).
  520. .PD
  521. .PP
  522. .RE
  523. All the routines to which calls are generated by the compiler are described above.
  524. They use the following global defined routines to do some of the work:
  525. .IP _rf 10
  526. Check input files for MAGIC and WRBIT.
  527. Initialize the window if WINDOW is cleared.
  528. .PD 0
  529. .IP _wf
  530. Check output files for MAGIC and WRBIT.
  531. .IP _incpt
  532. Advance the file window and read a new buffer if necessary.
  533. .IP _outcpt
  534. Write out the current buffer if necessary and advance the window.
  535. .IP _flush
  536. Flush the buffer if it is an output file.
  537. Append an extra line marker if EOLBIT is off.
  538. .IP _wstrin
  539. All output routines make up a string in a local buffer.
  540. They call _wstrin to output this buffer and to do the left padding.
  541. .IP _skipsp
  542. Skip spaces (and line feeds) on input files.
  543. .IP _getsig
  544. Read '+' or '-' if present.
  545. .IP _fstdig
  546. See to it that the next character is a digit. Otherwise error.
  547. .IP _nxtdig
  548. Check if the next character is a digit.
  549. .IP _getint
  550. Do the work for _rdi.
  551. .IP _ecvt
  552. Convert real into string of digits for printout in scientific notation.
  553. .IP _fcvt
  554. Convert real into string of digits for fixed point printout
  555. .IP -fif
  556. Split real into integer and fraction part
  557. .IP _fef
  558. Split real into exponent and fraction part
  559. .PD
  560. .PP
  561. The following global variables are used:
  562. .IP _lastp 10
  563. For heap management (see above).
  564. .PD 0
  565. .IP _highp
  566. For heap management (see above).
  567. .IP _extfl
  568. Used to save the argument p of _ini for later reference.
  569. .IP _extflc
  570. Used to save the argument c of _ini for later reference.
  571. .IP _m_lb
  572. Used to store the local base of the main program.
  573. .IP _curfil
  574. Save the current file pointer, so that the
  575. error message can access the file name.
  576. .IP "_pargc, _pargv, _penvp"
  577. Used to access the arguments of the main program.
  578. .PD
  579. .SH FILES
  580. .IP ~em/lib/*/tail_pc 20
  581. The library used by ack[5] to link programs.
  582. .PD
  583. .SH "SEE ALSO"
  584. .IP [1]
  585. A.S. Tanenbaum, Ed Keizer, Hans van Staveren & J.W. Stevenson
  586. "Description of a machine architecture for use of
  587. block structured languages" Informatica rapport IR-81.
  588. .PD 0
  589. .IP [2]
  590. K.Jensen & N.Wirth
  591. "PASCAL, User Manual and Report" Springer-Verlag.
  592. .IP [3]
  593. Specification fo Computer programming language Pascal, BS6192: 1982
  594. (ISO 7185)
  595. .IP [4]
  596. J.W. Stevenson, H. van Eck, "Amsterdam Compiler Kit-Pascal reference manual".
  597. .br
  598. (try \fItbl ~em/doc/pcref.doc | nroff\fP).
  599. .IP [5]
  600. ack(1), em_pc(6)
  601. .PD
  602. .SH DIAGNOSTICS
  603. All errors discovered by this runtime system cause an EM TRP instruction
  604. to be executed. This TRP instruction expects the error number on top
  605. of the stack. See [1] for a more extensive treatment of the subject.
  606. .PP
  607. EM allows the user to specify a trap handling routine, called whenever
  608. an EM machine trap or a language or user defined trap occurs.
  609. One of the first actions in _ini is to specify that the routine _fatal,
  610. available in this library, will handle traps.
  611. This routine is called with an error code (0..252) as argument.
  612. The following information is printed
  613. on file descriptor 2:
  614. .IP -
  615. The name of the Pascal program
  616. .PD 0
  617. .IP -
  618. The name of the file pointed to by _curfil, if the error number
  619. is between 96 and 127 inclusive.
  620. .IP -
  621. The error message (or the error number if not found).
  622. .IP -
  623. The source line number if not equal to 0.
  624. .PD
  625. .PP
  626. The routine _fatal stops the program as soon as the message is printed.
  627. .PP
  628. The following error codes are used by the Pascal runtime system:
  629. .IP 64
  630. more args expected
  631. .PD 0
  632. .IP 65
  633. error in exp
  634. .IP 66
  635. error in ln
  636. .IP 67
  637. error in sqrt
  638. .IP 68
  639. assertion failed
  640. .IP 69
  641. array bound error in pack
  642. .IP 70
  643. array bound error in unpack
  644. .IP 71
  645. only positive j in \fIi mod j\fP
  646. .IP 72
  647. file not yet open
  648. .IP 73
  649. dispose error
  650. .IP 74
  651. function not assigned
  652. .IP 75
  653. illegal field width
  654. .sp
  655. .IP 96
  656. file xxx: not writable
  657. .IP 97
  658. file xxx: not readable
  659. .IP 98
  660. file xxx: end of file
  661. .IP 99
  662. file xxx: truncated
  663. .IP 100
  664. file xxx: reset error
  665. .IP 101
  666. file xxx: rewrite error
  667. .IP 102
  668. file xxx: close error
  669. .IP 103
  670. file xxx: read error
  671. .IP 104
  672. file xxx: write error
  673. .IP 105
  674. file xxx: digit expected
  675. .IP 106
  676. file xxx: non-ASCII char read
  677. .PD
  678. .PP
  679. .SH AUTHORS
  680. Johan Stevenson and Ard Verhoog, Vrije Universiteit.