home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / bcpl / BCPL / alib / doc < prev    next >
Encoding:
Text File  |  1988-02-22  |  9.6 KB  |  357 lines

  1. BCPL document of 25 Oct 85 17:38:21
  2.  
  3. Compiler options
  4.  
  5. Default values are given in square brackets.
  6.  
  7.  Front end:
  8.  
  9.    B     [off]      stack grows from high to low addresses -
  10.           point VECs at the end, not beginning
  11.    C     [on]      equate cases
  12.    L     [on]      enable special LISP operators
  13.    R     [off]      'restricted' language
  14.    Sn     [4]      set savespace size
  15.    T     [off]      print parse tree
  16.    Xn     [large]  set extension level to n
  17.    $tag       set tag to TRUE
  18.    $tag'      set tag to FALSE
  19.    Dn     - ignored -
  20.  
  21.  Code generator options:
  22.  
  23.    A     [off]      generate AOF
  24.    B     [on]      ensure RB contains address of destination procedure on call
  25.    C     [off]      stack checking
  26.    P     [off]      profile and call counting
  27.    K     [off]      call counting
  28.    N     [off]      generate variable names in code
  29.    S     [on]      produce compacter code at the expense of speed by compiling
  30.           various sequences out of line
  31.    Wn     - ignored -
  32.    Dn     [0]      set CG debug mode to n.
  33.           I assure you, you don't want to use this
  34.    On     [1]      set CG optimise mode to n
  35.  
  36.  Switch options must be preceded by + or -.  Options may be separated by
  37.  commas and spaces.  Front end options are seperated from code generator
  38.  ones by /.
  39.  
  40.  If the B front-end option is used, the code generated requires the support
  41.  of a different (currently non-existent) mclib.
  42.  The P code generator option currently generates only entry counts.
  43.  The N code generator option is only partially implemented at present.
  44.  
  45.  
  46. The library
  47.  
  48. 14    PutByte(vec, offset, value)
  49. 15    result := GetByte(vec, offset)
  50.  
  51. 37    result := GBytes(hardware-address,  size)
  52. 38    PBytes(hardware-address,  size,  data)
  53.  
  54. 16    result := MulDiv(a, b, c)
  55.        result  = a*b/c
  56.        result2 = a*b REM c
  57.  
  58. 20    ch := CapitalCh(ch)
  59.  
  60. 21    comparison := CompCh(ch1, ch2)
  61.        result has the sign of ch1-ch2 (case folded)
  62.  
  63. 22    comparison := CompString(s1, s2)
  64.  
  65. 35    Stop
  66.  
  67. 41    frameptr := Level()
  68.  
  69. 42    LongJump(frameptr, lab)
  70.        The frame value must be one that is reachable by chaining back
  71.        from the current frame
  72.  
  73. 43    Aptovec(proc, vec ub)
  74.        Note that Aptovec uses a stack frame itself
  75.  
  76. 48    CreateCo(function, stacksize)
  77.  
  78. 49    successcode := DeleteCo(cptr)
  79.  
  80. 50    CallCo(cptr, arg)
  81.  
  82. 51    ResumeCo(cptr, arg)
  83.  
  84. 52    CoWait(cptr)
  85.  
  86. 54    vec := GetVec(upperbound)
  87.  
  88. 55    FreeVec(vec)
  89.  
  90. 56    size := MaxVec()
  91.  
  92. 94    error status := SWI(number, args, results)
  93.       args           is a 10 word BCPL vector containing the values for
  94.                R0 to R9 inclusive
  95.       results      is a 10 word BCPL vector to receive the values of
  96.                R0 to R9 inclusive after the SWI
  97.       error status is non-zero if the SWI gave rise to an error
  98.  
  99. 96    Avalue := OSArgs(op, handle, data)
  100.       result is negative if an error occurred.
  101.       (otherwise, only significant when op=handle=0)
  102.       result2 receives the returned data value.
  103.  
  104. 97    byte := OSBGet(channel)
  105.        (#x1fe returned at end of file)
  106.        result is negative on an error.
  107.  
  108. 98    error := OSBPut(byte, channel)
  109.        result is 0 if OK, negative if an error occurred.
  110.  
  111. 99    result := OSFind(op, arg)
  112.        op=0, (close) arg is file handle
  113.        op ~=0 (open) arg is file name (BCPL string), returns handle
  114.  
  115. 100    result := OSFile(op, filename, args)
  116.       filename is a BCPL string
  117.       args       is a BCPL vector containing the values wanted by Brazil
  118.            OSFile in R2 to R5.    Where these are addresses, they are
  119.            hardware adresses (ie BCPL pointers shifted up two places).
  120.       result is guaranteed valid only if op is 5
  121.     If an error occurs, Result2 is returned non-zero
  122.  
  123. 101    result := OSCLI(command)
  124.       command is a BCPL string
  125.       result  is False if the command fails, True otherwise
  126.     If the base of this program is not #x8000, then it tries to run the
  127.     command as a sub-program.
  128.  
  129. 102    error := OSWrCh(ch)
  130.        result is negative if an error occurred
  131.  
  132. 103    ch := OSRdCh()
  133.        Result2 is the value of the carry flag result (cf OSWord 0)
  134.  
  135. 104    result := OSByte(a, x, y).
  136.        Result is return X value; Result2 is set to return Y value
  137.  
  138. 93    result := OSByte2(a, x, y)
  139.        Result is negative if an error;
  140.        otherwise bottom byte = return x
  141.              byte 1 = return y
  142.              byte 2 is non-zero if return carry flag set
  143.        (This is how OSByte should have been: I may later remove it in
  144.         favour of this).
  145.  
  146. 105    OSWord(number, buffer)
  147.        If number=0 this does a Brazil ReadLine, and returns the length read
  148.                as result and the value of the carry flag in Result2
  149.                (TRUE if set, FALSE otherwise)
  150.        If number~=0 does a Brazil OSWord; no result returned
  151.  
  152. 106    buffer := TKRErr(buffer, maxlength)
  153.        Moves the most recent error string into the given buffer.
  154.        returns the (bcpl address of the) beffer, just as passed
  155.  
  156. 140    MoveWords(direction, length, from, to)
  157.        from and to are BCPL addresses
  158.  
  159. 141    FillWords(base, length, value)
  160.        Initialise !base to base!(length-1) to value.
  161.        base is a BCPL address.
  162.  
  163. 112    SetEventHandler(event number, data, treatment)
  164.  
  165.   Treatment may have one of the values:
  166.       ev_ignore (0)
  167.       ev_set_flag (1)
  168.      data  is the (BCPL) address of a word which onoccurrence of the
  169.            event will be set to a non-zero value
  170.       ev_call_proc (2)
  171.      data  is the hardware address of a piece of code tobe called when
  172.            the event occurs.  Call conditions are as for the Brazil
  173.            event handler.  No BCPL environment is set up for the call.
  174.  
  175.       ev_buffer (3)
  176.      data  is the address of a buffer to be used for the event values.
  177.            The values written are
  178.           (event number<<16) + (X value<<8) + Y value.
  179.            The buffer is a structure of the form
  180.           insertion_pointer = 0*4
  181.           extraction_pointer = 1*4
  182.           buffer_size = 2*4
  183.           buffer = 3*4 // to (buffer_size+2)*4
  184.           Values are inserted into the buffer using the algorithm
  185.           buffer!insertion_pointer := value;
  186.           $( LET new_i_p = insertion_pointer+1;
  187.              IF new_i_p=buffer_size THEN new_i_p := 0;
  188.              IF new_i_p~=extraction_pointer
  189.             THEN insertion_pointer := new_i_p
  190.           $)
  191.   Escape flag update is treated as event number -1: acknowledgement is
  192.   done automatically.
  193.  
  194.  
  195. 46    stream := FindInput(name)
  196. 47    stream := FindOutput(name)
  197.    Special cases are
  198.     VDU:
  199.     RS423:
  200.     RS232:
  201.     PRINTER:
  202.     NULL:
  203.  
  204. 29    SelectInput(stream)
  205. 30    SelectOutput(stream)
  206.  
  207. 27    stream := Input()
  208. 28    stream := Output()
  209.  
  210. 24    ch := RdCh()
  211. 26    WrCh(ch)
  212.  
  213. 44    ch := RdBin()
  214. 45    WrBin(byte)
  215.  
  216. 76    EndRead()
  217. 77    EndWrite()
  218.  
  219. 25    UnRdch()
  220.  
  221. 66    count := ReadBytes(vector, offset, count)
  222. 67    WriteBytes(vector, offset, count)
  223.  
  224. 59    Read.Offset(stream, vector)
  225.       vector!0 is set to the sequential pointer for the file open on stream
  226.  
  227. 60    Set.Offset(stream, vector)
  228.       Sets the sequential pointer for the file open on  stream  to vector!0
  229.  
  230. 61    filelength := Extent(stream)
  231.  
  232. 78    n := ReadN()
  233.  
  234. 23    NewLine()
  235. 36    NewPage()
  236.  
  237. 19    WriteF(format, a, b, c, d, e, f, g, h, i, j, k)
  238.  
  239. 18    WriteS(string)
  240.  
  241. 79    WriteD(n, digits)
  242.  
  243. 80    WriteN(n)
  244.  
  245. 81    WriteHex(n, digits)
  246.  
  247. 82    WriteOct(n, digits)
  248.  
  249. 83    RdArgs(keys, argv, size)
  250. 85    FindArg(keys, w)
  251.  
  252. 108    centisecondtime := Time()
  253. 109    timeofdaystring := TimeOfDay()
  254. 110    datestring := Date()
  255.  
  256. 90    n := Random(n)
  257.  
  258. 69    PackString(vector, string)
  259. 70    UnpackString(string, vector)
  260.  
  261. 63    Abort(n)
  262.       Called on hardware abort, or library-detected fatal fault.  The call
  263.       is as from the place of the fault; n = 0 for a software-detected
  264.       fault or the Arthur error code for a hardware trap
  265.       Note that global n is initialised to #xAE950000+4*n.    If used as an
  266.       address, this will give an address exception, and if branched to
  267.       will give a prefetch abort.
  268.  
  269. 64    BackTrace()
  270.  
  271. 65    MapStore()
  272.  
  273. Variables
  274. 89    random.state
  275. 40    stackbase
  276. 57    blocklist
  277. 144    vdustream
  278. 145    errorstream
  279.  
  280.  
  281.  
  282. Section format
  283.  
  284. SectionStart
  285.     =    "BCPL"
  286.     &    globinits-SectionStart
  287.     =    8 bytes of section name (8 data bytes, not a string)
  288.     =    20 bytes date and time compiled, also not a string.
  289.         The BCPL system uses the format, eg
  290.         "07 Oct 85 15:54:35",0,0.
  291.         Anything different will give odd output from MapStore.
  292.     =    0
  293.  
  294. globinits
  295.     &    offset of global in section,  global number
  296.        ...
  297.     &    highest global number used, 0
  298.  
  299. [ This bit will not be present when using a BCPL system which requires
  300.   linking rather than joining
  301.  
  302.        &       &12345678
  303.  
  304.     &    offset of word in section requiring relocation
  305.       ....
  306.  
  307.     &    &87654321
  308. (note that global initialisations need to be relocated.
  309. There's laziness for you).
  310. ]
  311.  
  312. Each procedure is preceded by a 12-byte header
  313.     &    -1
  314.     =    7, first 7 characters of procedure name (filled with space)
  315. Compiled BCPL may preceed that with a word giving the address of static data
  316. for the section.
  317.  
  318.  
  319.  
  320. Compiled code conventions
  321.  
  322. Registers:
  323.  
  324. RB       8
  325. RL       12
  326. RTS       11
  327. RP       10
  328. RG       9
  329. RGB       7
  330.  
  331. There is an upwards-growing stack, addressed by two registers.    RFP is the
  332. frame pointer, RTS the top of stack pointer (actually, it points to the first
  333. unused word above the stack).  RTS is not always correct within procedures, but
  334. it always is on procedure call and must be on return.
  335.  
  336. RG points at the base of the global vector; RGB addresses a set of subroutines
  337. within the library.
  338.  
  339. On procedure entry, RB holds the address of the called procedure.  It need not
  340. be preserved.  RL holds the address of the caller's static data, and must be
  341. preserved.  R14 holds the link: this must be written to both PC and PSR on
  342. return.  R1 to R4 hold the first four arguments, with others on the stack
  343. above RTS in the usual way. Thus, a general procedure would look like:
  344.     STMEA    rts!, {rb, rp, rl, r14} ; save linkage
  345.     SUB    rp, rts, #16        ; new frame pointer
  346.     STMEA    rts!, {a1, ...}     ; arguments
  347.        ...
  348.     MOV    rts, rp         ; unwind our frame
  349.     LDMIB    rp, {rp, rl, pc}^    ; no need to restore RB
  350.  
  351. Functions return their result in R1.
  352.  
  353. R0 to R6 and RB may be used without saving their values; so may R13 and
  354. moreover it is accessible from BCPL through the name NIL (assignment to NIL
  355. from BCPL has the side-effect of updating R6).    R6 and R13 are guaranteed
  356. untouched by the library, and by BCPL code which does not update NIL.
  357.