home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / misc / bcpl.ark / BCPL.DOC < prev    next >
Encoding:
Text File  |  1988-11-27  |  11.1 KB  |  313 lines

  1.                CP/M 80 BCPL compiler User Documentation.
  2.                =========================================
  3.  
  4. 1.  Files.
  5. ----------
  6.  
  7. The following files are supplied.
  8.  
  9.      BCPL.COM       The compiler itself;  takes one or more BCPL 
  10.                     source  files,  and  produces  a  relocatable 
  11.                     object format file.
  12.  
  13.      LOADB.COM      Links  and relocates one or more  relocatable 
  14.                     object files,  appends runtime routines,  and 
  15.                     either  executes the  resulting  program,  or 
  16.                     saves it as a .COM file.
  17.  
  18.      PATCH.COM      Patches LOADB.COM to alter the size of the 
  19.                     global vector and stack which it provides.
  20.  
  21.      LIBRARY        Relocateable  object format  file  containing 
  22.                     the standard library.
  23.  
  24.      LIBHDR         Header  file containing declarations for  the 
  25.                     standard  library,  and  a  NEEDS  directive, 
  26.                     which   will   cause  the  standard   library 
  27.                     (LIBRARY)  to  be  automatically  loaded   by 
  28.                     LOADB.COM.
  29.      
  30.      BLIB.B         Source code for LIBRARY.
  31.  
  32.      RANDLIB        Relocateable object format file containing  a 
  33.                     library for using CPM random-access files.
  34.  
  35.      RANDHDR        Header file for RANDLIB
  36.  
  37.      RAND.B         Source code for RANDLIB
  38.  
  39.  
  40. 2.   Invoking the compiler.
  41. ---------------------------
  42.  
  43. The compiler is invoked by executing the file BCPL.COM,  the BCPL 
  44. command takes zero, one or two file names. Note that there are no
  45. compiler options.
  46.  
  47. The command
  48.  
  49. BCPL
  50.  
  51. Will  compile  a  program typed at the  keyboard,  and  save  the 
  52. resulting object in a file called BCPL.OUT on the default disk.
  53.  
  54.  
  55. BCPL <source>
  56.  
  57. Will  compile the BCPL in file <source>,  and save the result  in 
  58. BCPL.OUT, on the default disk.
  59.  
  60. BCPL <source> <destination>
  61.  
  62. Will  compile  the  BCPL  in  <source> and  save  the  result  in 
  63. <destination>.
  64.  
  65.  
  66. 3.   Invoking the loader.
  67. -------------------------
  68.  
  69. The  loader is invoked by executing the file LOADB.COM,  as  with 
  70. the compiler, zero, one, or two filenames can be given, and there 
  71. are no command line options.
  72.  
  73. The command
  74.  
  75. LOADB
  76.  
  77. Will  load the file BCPL.OUT from the default disc,  along  with 
  78. any  other  files specified by it,  append the  machine  language 
  79. support, and execute the resulting program.
  80.  
  81. LOADB <source> 
  82.  
  83. Will act as above, but the input file name is <source>
  84.  
  85. LOADB <source> <destination>
  86.  
  87. Will produce the executable image as before,  and then save it in 
  88. the file specified by <destination>. This will normally be a .COM 
  89. file.  The  resulting file is independent,  and can  be  executed 
  90. without any other BCPL system files being available.
  91.  
  92. If the filename extension is omitted from the destination, the
  93. loader will generate two files, 
  94.  
  95. <destination>.COM
  96. <destination>.SYM
  97.  
  98. the .SYM file is of the correct format to be used as a symbol file for the 
  99. Digital Research ZSID debugger.
  100.  
  101.  
  102. 4.   The compiler in detail.
  103. ----------------------------
  104.  
  105. It   is   assumed  that  this  documenation  is  being  read   in  
  106. conjunction with "BCPL - the language and its compiler" by Martin 
  107. Richards  and  Colin Whitby-Strevens (CUP  1980),  which  is  the 
  108. standard reference for the language. This document only indicates 
  109. differences  from  R&W,  and clarifies  implementation  dependent 
  110. points.
  111.  
  112. The  compiler accepts the language as described in the  reference 
  113. section  of  R&W,  with a few extensions.  The  byte  indirection 
  114. operator  (%) is implemented (Page 58).  The monadic ABS operator 
  115. is also implemented, as is the field selector extension. 
  116.  
  117. A  single  source  file may be  split  into  separately  compiled 
  118. sections by ending each section with a dot in a position where it 
  119. is  not part of an identifier.  The object code from each section 
  120. is concatenated in the output file.
  121.  
  122. A section may be named by including the directive
  123.  
  124. SECTION "<name>"
  125.  
  126. as the first statement. This has no effect except that the loader 
  127. will print the message
  128.  
  129. Loading <name>
  130.  
  131. when it starts loading that section.
  132.  
  133. The NEEDS directive is implemented,  but not as described in R&W. 
  134. A directive of the form 
  135.  
  136. NEEDS "<filename>"
  137.  
  138. may  appear  in any block-head (ie  anywhere  that  LET,  STATIC, 
  139. GLOBAL  or  MANIFEST may  appear.) Its effect is that of a  "load 
  140. time GET" ie,  at load time,  the object file given by <filename> 
  141. is  loaded,  after  the  object file  which  includes  the  NEEDS 
  142. directive.   Including  a NEEDS  directive in a  standard  header 
  143. file  will  ensure the loading of the code being declared in  the 
  144. header.  The  standard LIBHDR has a NEEDS "LIBRARY" directive  in 
  145. it.  NEEDS  can also be used to support separate compilation.  If 
  146. the modules of a system are compiled into (say)
  147.  
  148. OBJECT1
  149. OBJECT2
  150. OBJECT3
  151.  
  152. then a BCPL file consisting merely of
  153.  
  154. NEEDS "OBJECT1"
  155. NEEDS "OBJECT2"
  156. NEEDS "OBJECT3"
  157.  
  158. when compiled, will produce a "link control file" which when used 
  159. as  the  input to the loader will cause the whole  system  to  be 
  160. linked.  Note  that  the  loader will not include the  same  file 
  161. twice.  This  is important if for instance more than one  section 
  162. GETs LIBHDR, with its NEEDS "LIBRARY" directive. Only one copy of 
  163. LIBRARY is needed, and one is what you'll get.
  164.  
  165. Arithmetic:  The word size is 16 bits. TRUE is represented as -1, 
  166. and FALSE is 0. The relation operators return these values. Two's 
  167. complement  arithmetic is used,  and divsion and remainder  round 
  168. towards zero.  ie -1/2 is equal to zero, not -1. Division by zero 
  169. is trapped, and generates a fatal run-time error. Overflow is not 
  170. trapped, and simply returns the true result truncated to 16 bits.
  171.  
  172.  
  173. 5.  Library.
  174. ------------
  175.  
  176. The  standard library supplied with the compiler is in two parts, 
  177. half is implemented on assembly language,  and half in BCPL.  The 
  178. assembly  language part is automatically included  in  executable 
  179. files by the loader, along with run-time code for multiplication, 
  180. division &c.  The image of this code is stored internally by  the 
  181. loader,  it  occupies  about  2.5K.  These  routines  are  always 
  182. available to all BCPL programs,  they are accessed via the  first 
  183. thirty or so global varibales.  The second half of the library is 
  184. written  in  BCPL,  and  accessed  using  the  standard  separate 
  185. compilation  techniques in BCPL.  The object code is in the  file 
  186. LIBRARY, and the standard library header contains the directive
  187.  
  188. NEEDS "LIBRARY"
  189.  
  190. which  causes  the code to be included at load time.  Within  the 
  191. header,  LIBHDR, the declarations are split into those to do with 
  192. the  assembly  language library,  and those to do with  the  BCPL 
  193. libaray.  If  an  application does not  require  the  later,  its 
  194. declarations and the NEEDS directive can be removed. leaving only 
  195. the  declarations  required  to  access  the  assembly   language 
  196. library.
  197.  
  198. The    assembly   language   library   provides   the   following 
  199. routines/functions.
  200.  
  201. WRCH          Output a character
  202. RDCH          Input a character
  203. ENDTOINPUT    Close COS, and reopen as CIS
  204. REWIND        Set CIS file pointer to start of file
  205. BINARYINPUT   Set CIS to binary mode   
  206. BINARYOUTPUT  Set COS to binary mode
  207. SELECTINPUT   Select CIS
  208. SELECTOUTPUT  Select COS
  209. ENDREAD       Close CIS
  210. ENDWRITE      Close COS
  211. FINDINPUT     Open named file for input
  212. FINDOUTPUT    Open named file for output
  213. INPUT         Return CIS
  214. OUTPUT        Return COS
  215. LONGJUMP      Non-local GoTo
  216. LEVEL1        Provide args for LONGJUMP
  217. LEVEL2           "     "    "    "   "
  218. STACKAVAIL    Returns free stack
  219. PARSE         Parse file name into CP/M format FCB
  220. BDOS          Call the CP/M BDOS
  221. MULDIV        Evaluate X*Y/Z without overflow
  222. GETVEC        Allocate heap space
  223. FREEVEC       Free heap space
  224. MAXVEC        Return maximum size accepted by GETVEC
  225. MEMCPY        Fast memory block copy
  226. CREATECO      Create a coroutine
  227. DELEECO       Destroy a coroutine
  228. CALLCO        Call a coroutine
  229. COWAIT        Suspend a coroutine
  230. RESUMECO      Transfer control to a coroutine
  231. COLONGJUMP    Cross-coroutine version of LONGJUMP
  232. INTKEY        Return true if ctrl-C pressed
  233. REMOVEINPUT   Delete the current input file
  234. REMOVEOUTPUT  Delete the current output file
  235.  
  236. While the BCPL library provides these functions/routines.
  237.  
  238. RANDOM        Pseudo-random numbers
  239. NEWLINE       Output a newline character using WRCH
  240. NEWPAGE       Output a form-feed using WRCH
  241. WRITES        Output a string using WRCH
  242. WRITED        Output a decimal number using WRCH
  243. WRITEU        Output unsigned decimal number using WRCH
  244. WRITEN        Output a decimal number in a given field using WRCH
  245. WRITEOCT      Output an n-digit octal number using WRCH
  246. WRITEO        Output a 6-digit octal number using WRCH
  247. WRITEHEX      Output an n-digit hexadecimal number using WRCH
  248. WRITEX        Output a 4-digit hex number using WRCH
  249. WRITEF        General purpose output using WRCH
  250. READN         Read in a decimal number using RDCH
  251.  
  252. LIBHDR  also  declares  a few  MANIFEST  constants,  ENDSTREAMCH, 
  253. BYTESPERWORD,  etc.  It also declares CON,RDR,PUN,  and LST which 
  254. can  be  fed in SELECTINPUT and SELECTOUTPUT to access  the  CP/M
  255. logical devices.
  256.  
  257.  
  258. 6.  Run-time Environment.
  259. -------------------------
  260.  
  261. As supplied, the LOADB will generate binaries which allocate 2000 
  262. words  to  the run-time stack,  and have a global vector  of  200 
  263. words. These defaults can be changed with the PATCH program.
  264.  
  265. All  the  rest  of the TPA is assigned to the heap,  and  can  be 
  266. allocated  using  GETVEC.  FINDINPUT,  FINDOUTPUT,  and  CREATECO 
  267. automatically take store from the heap using GETVEC.
  268.  
  269. If a binary is invoked without any filenames, the CIS and COS are
  270. both  set to CON,  the console device.  If one extra filename  is 
  271. given,  that file is opened for input and becomes CIS at startup. 
  272. If two extra filenames are given, the first is used as above, and 
  273. the second opened for output, and assigned to COS.
  274.  
  275. So. 
  276.  
  277. MYFILE         
  278. executes MYFILE.COM, input and output to console.
  279.  
  280. MYFILE INFILE
  281. executes MYFILE.COM, taking default input from INFILE
  282.  
  283. MYFILE INFILE OUTFILE
  284. executes  MYFILE.COM,  taking  default  input  from  INFILE,  and 
  285. putting default output in OUTFILE. If OUTFILE already exists, its 
  286. contents are lost.
  287.  
  288. Note  that  a OUTFILE is automatically closed  when  the  program 
  289. exits.  This  only happens to a file opened by the system,  files 
  290. opened by FINDOUTPUT must be explicitly closed using ENDWRITE.
  291.  
  292.  
  293. 7.  The random access library.
  294. ------------------------------
  295.  
  296. There  is  a  small library  supplied,  written  in  BCPL,  which 
  297. provides CP/M random access files.  Inspection of the source will 
  298. show how to use it. Note the use of the library routine BDOS.
  299.  
  300.  
  301. 8.  Authorship.
  302. ---------------
  303. The compiler was written by Simon Kelley. It was based on the
  304. original OCODE compiler written by Martin Richards.
  305.  
  306. Simon Kelley can be contacted at:
  307. Trinity College, Cambridge, CB2 2AL, ENGLAND
  308.  
  309. or by email:
  310. srk@uk.ac.cam.cl
  311.  
  312.  
  313.