home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 116.lha / Web / web.doc < prev    next >
Encoding:
Text File  |  1986-11-20  |  17.9 KB  |  450 lines

  1.  
  2.                Web
  3.  
  4.                              Greg Lee
  5.                              July 8, 1986
  6.  
  7. General Description.
  8.  
  9.    Web is a preprocessor for assembly language programs.  It converts
  10. assembly language programs which make use of certain structuring
  11. conventions into files which are acceptable to a 68000 assembler, in
  12. particular, the Metacomco assembler for the Amiga.  Although inspired
  13. by Donald Knuth's system of the same name (see "Literate Programming"
  14. in The Computer Journal, v.27, no.2, 1984, pp.97-111), it is very much
  15. more primitive than Knuth's system, and the syntax of the language
  16. it interprets is different from that of the real WEB.
  17.  
  18. Structuring.
  19.  
  20.    The structuring conventions made available by the use of web fall
  21. into the following categories:
  22.  
  23.       comments         (numbered comment sections, etc.)
  24.       procedures       (can be given more readable names)
  25.       named code sections  (code defined apart from where it is used)
  26.       defined symbols      (for which text strings will be substituted)
  27.       line separator       (';' separates multiple statements on a line)
  28.       statement grouping   (using '{...}', '«...»', and '[...]')
  29.       branch mnemonics     (using '=' for 'bne', etc.)
  30.       breaks           (an easy way to branch to the end of a section)
  31.       infix statements     (express move/add/sub/lea/cmp with '='/'?' infix)
  32.       length typing    (associate byte/word/long with variables)
  33.       data declarations    (declare simple unitialized data variables)
  34.  
  35. Some details about these can be found below.  The source for web makes use
  36. of these conventions, and this is the principle documentation for the
  37. use of web, both by way of example and providing details of the
  38. implementation.  The source is not put forward as an ideal model of
  39. style (you can do better).
  40.  
  41.  
  42. Usage.
  43.  
  44.    The source code that web is to process is assumed to be in
  45. a file whose name ends in '.w', as for example in 'web.w'.  When you
  46. invoke web, give the name of the file on the command line, either with
  47. or without the '.w' suffix, as you choose.  The output file which is
  48. to be assembled will have the same name, except ending in '.a' instead
  49. of '.w'.  It will be created in the same directory as that of the '.w'
  50. file, and any pre-existing file of that name will be deleted.
  51.  
  52.    For example, the command for web to process itself is either 'web web'
  53. or 'web web.w', and the assembly file created is 'web.a'.
  54.  
  55.    The largest file that web can process is fixed by the size of
  56. an internal buffer which is now set at 80,000 bytes.  The source file
  57. can typically be twice this size, since comments and multiple spaces
  58. are removed before the text is placed in the buffer.  The total number
  59. of procedures, named code sections, and definitions must not exceed
  60. the size of an internal table, which can now hold a maximum of 400
  61. entries.  Having the source code, of course you can easily change
  62. these limits.
  63.  
  64.  
  65. Optionality.
  66.  
  67.    The use of every part of web's extended syntax is optional.  A program
  68. which could have been assembled directly can be sent through a web
  69. proprocessing stage without occasioning any changes in the resulting object
  70. code. So, if there are some aspects of the syntax you don't like, you don't
  71. need to use the related conventions.  However, there are some
  72. incompatibilities between the languages that the assembler and web accept.
  73. So not just any correct assembly language program can be processed by web
  74. without problems.  Here is a list of the potential difficulties:
  75.  
  76.       capital letters -- the first non-blank character of a line must
  77.      not be a capital, unless the intention is to name a procedure;
  78.      also, the sequences '.B','.W','.L' are elided
  79.       semi-colon -- this must not be used for comments, since web
  80.      understands it as a line separator
  81.       colon -- after a label terminated with a colon, web starts a new
  82.      line, so one can't use a colon with a label before the assembler
  83.      directives macro, reg, set, equ, equr, section, rorg
  84.       data sections -- web just does not understand data sections, so
  85.      they must be treated as procedures (never called, of course);
  86.      at the end of a data section, one must give a 'section ...,code'
  87.      directive, so the assembler will accept the 'rts' instruction
  88.      that web will add at the end of the section
  89.       angle brackets -- assembler macros that take string arguments may
  90.      have these arguments enclosed in angle brackets; web does not
  91.      know that such angles should protect the enclosed characters
  92.      from being changed
  93.       double quotes -- web understands that single quotes protect characters,
  94.      but it does not understand double quotes; use single quotes
  95.      around file names after the 'include' directive
  96.       keywords -- when the words 'define', 'byte', 'word', 'long' occur
  97.      first on a line, possibly preceded by spaces, they are interpreted
  98.      in a special way (detailed below)
  99.  
  100.  
  101. Comments.
  102.  
  103.    A paragraph of commentary can be introduced by a number followed by a
  104. period, or the Amiga topaz section character '§' (Alt single quote), or the
  105. paragraph character '¶' (Alt '6').  The paragraph introducer is the first
  106. nonblank thing on the line. Such a paragraph is terminated with an empty
  107. line.
  108.  
  109.    A second way of giving comments is to place them in parentheses.  The
  110. initial left parenthesis must be the the very first thing on the line, but
  111. the closing right parenthesis can come anywhere following, except within
  112. another comment or enclosed in single quotes.  Pairs of parenthses may
  113. occur within a parenthetical comment (so one can comment out portions of
  114. code that contain parenthetical comments).
  115.  
  116.    Thirdly, the bullet character '·' and everything on the remainder of
  117. its line is treated as a comment.  This is a replacement for the assembler
  118. use of ';', which is no longer available with web.
  119.  
  120.    Lastly, '*' at the beginning of a line makes that line a comment.  This
  121. is also an assembler convention.
  122.  
  123.    The assembler convention of placing comments after complete code
  124. instructions will also often work, but is not recommended, since it
  125. sometimes will interfere with web's syntactic analysis.  It definitely
  126. will interfere after an infix statement (see below).
  127.  
  128.  
  129. Procedures.
  130.  
  131.    Subroutines can be given long names which may contain spaces.  A line
  132. beginning with a capital letter is treated as such a name, and the lines
  133. following, up to the next procedure name or named code section or end
  134. of file, are part of the procedure.  To call the procedure, just give its
  135. name preceded on a line by one or more blanks (possibly preceded by a
  136. left statement grouper or a colon-terminated label).
  137.  
  138.    Web generates an 'rts' instruction at the end of a procedure definition.
  139. At the end of the output file, it also generates an 'end' directive.
  140. Material at the beginning of the input file before any procedure name or
  141. named code section is treated as the body of an unnamed procedure,
  142. except that no 'rts' is added at the end.
  143.  
  144.    Procedures can be defined with parameters and with a list of registers
  145. to save.  The list of parameters is given in parentheses following the
  146. name of the procedure, and the registers to save after that.  The
  147. register list is in the form used by the 'movem' instruction.  When
  148. the procedure is called with a parenthesized list of arguments, a
  149. series of 'move.l' instructions is generated for each of the names
  150. in the argument list with corresponding names in the parameter list
  151. as destinations.  If one of the corresponding names should be missing,
  152. no move instruction is generated.  Redundant moves, and moves to a
  153. destination which is the same as a subsequent source are not checked
  154. for.
  155.  
  156.  
  157. Named Code Sections.
  158.  
  159.    Named code sections are in-line procedures.  A line beginning with
  160. two hyphens is treated as the name of a code section, and the section
  161. is defined as all following lines up to the next procedure name or named
  162. code section or end of file.  To invoke the code, just give its name
  163. (including the hyphens) on a line preceded by one or more blanks
  164. (which may be preceded by a left brace or a colon-terminated label).
  165. Then the definition will be substituted for the name.
  166.  
  167.    Such code sections need not be defined before they are invoked, and
  168. the definitions may contain invocations of other named code sections,
  169. with no restriction on the level of nesting allowed.  However, if there is
  170. recursion, the output file will exceed the capacity of most disk drives,
  171. since it will be infinitely long.
  172.  
  173.    Parameters and a register save list work just as they do for procedures.
  174.  
  175.    Due to a mistake in the implementation, if a given code section is
  176. to be invoked more than once, it must not contain '{...}', '«...»', '[...]'
  177. (see below), since then the generated labels will not be unique.
  178.  
  179.  
  180. Defines.
  181.  
  182.    Symbols can be defined as standing for a string of text.  For instance,
  183. if the input file has the line:  define new_line  #10
  184. then  for all occurrences of 'new_line', in the output file the text
  185. '#10' would be substituted.
  186.  
  187.    A symbol is a span of lower case letters or '_' or the grave accent.
  188. In the definition, the substitution text starts with the first non-blank
  189. character after the defined symbol and continues to the end of the line.
  190. Symbols cannot be redefined, and the substitution text cannot contain
  191. material which web is responsible for processing, except that it can
  192. contain other defined symbols.  As in the case of named code sections,
  193. there is no protection provided against recursive definitions.
  194.  
  195.    No symbol substitutions are made within labels which are followed by
  196. a colon or which stand alone on a line.
  197.  
  198.  
  199. Line Separater.
  200.  
  201.    One can put multiple code instructions on one line by separating
  202. them with ';'s.  However, the titles of procedures or named code
  203. sections, 'define's, and data declarations cannot come after ';'.
  204.  
  205.  
  206. Statement Grouping.
  207.  
  208.    As an alternative to making up your own labels for program branches,
  209. you can have web do this for you.  A unique label is substituted for
  210. each of every pair of matching left and right braces.  For example,
  211.  
  212.       instead of     bne  lab23     you can write     bne { move D0,D3
  213.              move D0,D3               }
  214.           lab23:
  215.  
  216. After the label for a left brace, a new line is begun in the output,
  217. and left indentation is removed before the labels substituted for either
  218. brace.  In addition, '«' (Alt shift '+') is provided as a synonym for '{',
  219. and '»' (Alt ';') is a synonym for ';}', so instead of the above,
  220. you can also put:
  221.              bne «  move D0,D3  »
  222. A right brace could not be used in this last example, because the
  223. label substituted would be put on the same line as the move instruction.
  224.  
  225. Yet another alternative for statement grouping is to use '[...]'.  These
  226. work like braces, and can be used for notational variety.  However, they
  227. generate a different set of labels, and they need not be properly nested
  228. with respect to braces.  For example, one can make unstructured loops
  229. like this:
  230.         { add.w  d0,d1
  231.           [ subq.l  #1,d3
  232.         bpl }
  233.         moveq  #30,d3
  234.         subq.l #1,d4
  235.         bpl  ]
  236.  
  237. Branch Mnemonics.
  238.  
  239.    Used with braces, the ordinary branch mnemonics are unintuitive.
  240. Consequently, the following alternative symbols are provided:
  241.  
  242.       use  <=±  for  bgt
  243.       use  <=   for  bhi
  244.       use  >=±  for  blt
  245.       use  >=   for  bcs
  246.       use  ~=   for  beq
  247.       use  !=   for  beq
  248.       use  ->   for  bra
  249.       use  <±   for  bge
  250.       use  <    for  bcc
  251.       use  >±   for  ble
  252.       use  >    for  bls
  253.       use  =    for  bne
  254.       use  -    for  bpl ('-' must be followed by a blank)
  255.       use  +    for  bmi
  256.  
  257. Thus the above example could also have been written:
  258.  
  259.              =  «  move D0,D3  »
  260.  
  261.  
  262. Breaks.
  263.  
  264.    As a further means to avoid writing labels, the symbols '¶' (Alt '6')
  265. and '§' (Alt single-quote) can be used as targets of branch instructions.
  266. '¶' refers to the position of the next following unmatched right brace,
  267. and '§' refers to the end of the current procedure or named code section.
  268. The "end" is just before the 'movem.l (sp)+,...' to restore registers
  269. if a register save list was given, and for a procedure, before the
  270. the 'rts' instruction generated by web.
  271.  
  272. Note that '¶' does not refer to ']', only '}'.  Thus one can break out of
  273. deeply nested inner loops for which brackets were used to the end of
  274. an outer loop enclosed by braces.  
  275.  
  276. Infix Statements.
  277.  
  278.    Web allows a few C-style infix statements.  However in most cases
  279. the intended length for the generated assembler mnemonic must be
  280. explicitly given as a suffix on the first operand.  Here are examples
  281. for some byte-length operations:
  282.  
  283.    use   d0.b  = d2      for   move.b  d2,d0
  284.    use   d0.b += d2      for   add.b   d2,d0
  285.    use   d0.b -= d2      for   sub.b   d2,d0
  286.    use   d0.b  ? d2      for   cmp.b   d2,d0
  287.  
  288. Similarly, word and long word operations can be expressed using '.w'
  289. and '.l' suffixes. '*=', '/=', '&=', '|=', '<<=', '>>=' generate respectively
  290. instructions mulu, divu, and, or, lsl, lsr.  An lea instruction is generated
  291. when the second operand begins with '&' or '^':
  292.  
  293.    use   a0 = &buffer   for   lea   buffer,a0
  294.    use   a0 = ^buffer   for   lea   buffer,a0
  295.  
  296.    If the second operand begins with single-quote, '@', '%', or digits
  297. optionally preceded by '-' but not followed by '(', then '#' is
  298. appended.  For instance:
  299.  
  300.    use   d0.b  = 'z'     for   move.b  #'z',d0
  301.    use   (a0)+.w ? 312   for   cmp.w   #312,(a0)+
  302.    use   -(a0).l = -11   for   move.l  #-11,-(a0)
  303.    use   verf.b -= 1(a0) for   sub.b   1(a0),verf
  304.    use   verf.b -= %10(a0) for  sub.b   #%10(a0),verf (sic!!)
  305.  
  306.    For add's and sub's, if the second operand begins with a single digit from
  307. 1 to 8 (not followed by '('), addq and subq are used:
  308.  
  309.    use  memvar.w += 7   for   addq.w   #7,memvar
  310.    use  memvar.w += 7+2 for   addq.w   #7+2,memvar   (sic!!)
  311.    use  memver.w += 9   for   add.w    #9,memvar
  312.  
  313. Substitution for defined symbols is done before the conversion of
  314. infix statements, so in the above cases the operands could be in
  315. symbolic form without preventing web from finding the appropriate
  316. assembler instruction.  But web does not analyze assembler 'equ'
  317. directives, so equ'd symbols should not be used for operands of
  318. infix statements.
  319.  
  320.    When the first operand of an infix statement is not given a
  321. length suffix, then provided certain conditions are satisfied, web
  322. will use a moveq instruction for an '=' statement and an addq.l
  323. or subq.l for '+=' or '-=' statements.  Otherwise, the instruction
  324. mnemonic is just passed on to the assembler without a length suffix.
  325. For moveq, 'd' & a digit must precede the '=' sign (signifying one hopes that
  326. a data register is referred to) and digit or '-' digit must follow (unless
  327. followed by '(').  For addq.l and subq.l, the second operand
  328. must be a digit from 1 to 8.
  329.  
  330.    use   d0 = 0       for  moveq  #0,d0
  331.    use   had0 = 0     for  moveq  #0,had0  (sic!!)
  332.    use   d0 = 128     for  moveq  #128,d0  (sic!!)
  333.    use   a0 += 4      for  addq.l #4,a0
  334.  
  335.    If the second operand is an expression intended for the assembler
  336. to evaluate, spacing may be used freely, since the spaces will be
  337. removed by web.
  338.  
  339.    use   d0 = 1 + 28 for   moveq #1+28,d0
  340.  
  341.  
  342. Length Typing.
  343.  
  344.    The treatment of length suffixes in infix statements as discussed
  345. above has this drawback:  length is made to appear to be a property
  346. of a variable (which is often reasonable), yet only when the variable
  347. appears at the left of an infix operator.  As a partial corrective,
  348. there is an added facility for expressing variable references in a
  349. uniform way.  If the length suffixes are given with capital letters,
  350. the information they convey will be made use of in translating infix
  351. statements, but deleted everywhere else.  One might have a sequence
  352. such as:              for:
  353.      d2.B  =  memvar.B        move.b  memvar,d2
  354.      d1.B  =  d2.B        move.b  d2,d1
  355.      d1.B  ?  verf.B          cmp.b   verf,d1
  356.      != « memvar.B += d1.B »      beq     somelabel
  357.        ...            add.b   d1,memvar
  358.                    somelabel:
  359.                        ...
  360.  
  361. In this example, no use will be made of the '.B's on the right hand
  362. sides;  they are for appearance only.  Now in conjunction with
  363. the define feature, length information can be made implicit, if one
  364. wishes.  Accompanied by:
  365.  
  366.      define  snail  D1.B
  367.      define  clips  D2.B
  368.  
  369. the above could be written:
  370.  
  371.      clips  =  memvar.B
  372.      snail  =  clips
  373.      snail  ?  verf.B
  374.      != « memvar.B += snail »
  375.        ...
  376.  
  377. One does not lose any flexibility in following such a policy of variable
  378. usage, since implicit lengths can always be explicitly overridden.
  379. While the above 'snail  =  clips' translates to 'move.b D2,D1', if
  380. for some reason a long operation was wanted, e.g., one could write
  381. 'snail.l  =  clips', which would translate to 'move.l D2,D1'.
  382.  
  383.  
  384. Data Declarations.
  385.  
  386.    Built on top of the preceding method of hiding variable lengths
  387. is a primitive provision for declaring memory variables.  The keywords
  388. 'long', 'word', and 'byte' define the following symbol as having the
  389. named length, and a bss section is appended to the output file requesting
  390. the allocation of memory to hold the data.  For the above example, one
  391. could add the declarations:
  392.  
  393.      byte    memvar
  394.      byte    verf
  395.  
  396. and revise the code to read:
  397.  
  398.      clips  =  memvar
  399.      snail  =  clips
  400.      snail  ?  verf
  401.      != « memvar += snail »
  402.        ...
  403.  
  404. In the output file, this would produce:
  405.  
  406.  move.b .0001Q,D2
  407.  move.b D2,D1
  408.  cmp.b .0002Q,D1
  409.  beq .0001
  410.  add.b D1,.0001Q
  411. .0001
  412. .8001
  413.    ...
  414.  section webroom,bss
  415.    ...
  416. .0001Q DS.B 1
  417. .0002Q DS.B 1
  418.    ...
  419.  end
  420.  
  421. (The actual labels generated would depend on what code had preceded.  The
  422. label '.8001' is there as the target of a potential branch to ¶ instruction,
  423. though none occurs in this instance.)
  424.  
  425.    Long words declared in this way will be aligned on long word
  426. boundaries, and words aligned on word boundaries.
  427.  
  428.  
  429. Converting old assembly files.
  430.  
  431.    A separate utility 'atow' will convert move, add, and sub instructions
  432. to web's '=' format.
  433.  
  434.  
  435. Bugs.
  436.  
  437.    There is practically no error checking, aside from checking for
  438. balanced braces in each section.
  439.  
  440.    See the above lines with '(sic!!)' at the end.
  441.  
  442.    The language interpreted by web does not have a regular syntax.  The
  443. only criterion for correctness is whether the code will be translated
  444. into proper and appropriate assembly language by the simple text
  445. transformations discussed above.  Consequently, in writing code for
  446. web one must often do the prospective translation mentally in order to
  447. decide what form statements should take.
  448.  
  449.  
  450.