home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / DOC.ZIP / README.TSM next >
Encoding:
Text File  |  1992-10-01  |  6.9 KB  |  187 lines

  1. This README file contains new information about the PROCDESC and
  2. PROCTYPE directives. Review this file for information on how to use
  3. these directives when you are writing Pascal programs.
  4.  
  5. Using procedure prototypes
  6. --------------------------
  7. For versions 3.2 and later, Turbo Assembler lets you declare procedure
  8. prototypes much like procedure prototypes in C. To do so, use the
  9. PROCDESC directive. 
  10.  
  11. The Ideal mode syntax of PROCDESC is:
  12.  
  13.      PROCDESC name [procedure_description]
  14.  
  15. Use the following syntax in MASM mode:
  16.  
  17.      name PROCDESC [procedure_description]
  18.  
  19. procedure_description is similar to the language and argument
  20. specification used in the PROC directive. Its syntax is:
  21.  
  22.      [[language_modifier] language] [distance] [argument_list]
  23.  
  24. language_modifier, language, and distance have the same syntax as in
  25. the PROC directive. argument_list has the form:
  26.  
  27.      argument [,argument] ...
  28.  
  29. An individual argument has the following syntax:
  30.  
  31.      [argname] [[count1_expression]]:complex_type [:count2_expression]
  32.  
  33. complex_type is the data type of the argument, and can be either a
  34. simple type or a pointer expression. count2_expression specifies how
  35. many items of this type the argument defines. The default value of
  36. count2_expression is 1, except for arguments of BYTE, which have a
  37. default count of 2 (since you can't PUSH a byte value onto the 80x86
  38. stack).
  39.  
  40. For the last argument, in procedure types whose calling convention
  41. allows variable-length arguments (like C), count2_expression can be ?,
  42. to indicate that the procedure caller will determine the size of the
  43. array.
  44.  
  45. Note that the name of each argument (argname) is optional, but
  46. complex_type is required for each argument because procedure types are
  47. used mainly for type checking purposes. The names of the arguments do
  48. not have to agree, but the types must.
  49.  
  50. Here's an example:
  51.  
  52.      test PROCDESC pascal near a:word,b:dword,c:word
  53.  
  54. This example defines a prototype for the procedure test as a PASCAL
  55. procedure taking three arguments (WORD, DWORD, WORD). Argument names
  56. are ignored, and you can omit them in the PROCDESC directive, as
  57. follows:
  58.  
  59.      test PROCDESC pascal near :word,:dword,:word
  60.  
  61. The procedure prototype is used to check calls to the procedure, and
  62. to check the PROC declaration against the language, number of
  63. arguments, and argument types in the prototype. For example,
  64.  
  65.      test PROC pascal near
  66.        ARG a1:word,a2:dword,a3:word       ;matches PROCDESC for test
  67.  
  68. PROCDESC also globally publishes the name of the procedure. Procedures
  69. that are not defined in a module are published as externals, while
  70. procedures that are defined are published as public. Be sure that
  71. PROCDESC precedes the PROC declaration, and any use of the procedure
  72. name. 
  73.  
  74. Procedure prototypes can also use procedure types (defined with
  75. PROCTYPE). For example,
  76.  
  77.      footype PROCTYPE pascal near :word,:dword,:word
  78.      foo PROCDESC footype
  79.  
  80.  
  81. Calling procedures that have been prototyped
  82. --------------------------------------------
  83. If you've defined the procedure prior to the call or used PROCDESC to
  84. prototype the procedure, Turbo Assembler will type check any language
  85. and arguments specified in the call and generate a warning if the
  86. language, number of parameters, or types of parameters don't match.
  87.  
  88. For example,
  89.  
  90.      test PROCDESC pascal far :word,:dword,:word
  91.      .
  92.      .
  93.      .
  94.      call test pascal ax,ds bx,cx            ;works fine
  95.      call test c, ax,dx, bx,cx               ;wrong language!
  96.      call test pascal, eax, ebx, ecx         ;wrong parameter types!
  97.      call test pascal, ax,ds bx              ;too few parameters!
  98.  
  99. Since the language of the procedure has been specified, you don't have
  100. to include it in the call. If you omit it, however, make sure to
  101. include the comma that would normally follow it:
  102.  
  103.      call test,ax,ds bx,cx                   ;works fine
  104.  
  105. You can also use procedure types (declared with PROCTYPE) to supply a
  106. distance and language, and force type-checking to occur. For example,
  107.  
  108.      footype proctype pascal near :word,:dword,:word
  109.      .
  110.      .
  111.      .
  112.      call footype ptr[bx],ax,ds bx,cs            ;no error!
  113.  
  114.  
  115. Defining a procedure type
  116. -------------------------
  117. For Turbo Assembler version 3.2 or higher, you can use a user-defined
  118. data type (called a procedure type) to describe the arguments and
  119. calling conventions of a procedure. Turbo Assembler treats procedure
  120. types like any other types; you can use it wherever types are allowed.
  121. Note that since procedure types don't allocate data, you can't create
  122. an instance of a procedure type.
  123.  
  124. Use the PROCTYPE directive to create a procedure type. Here is the
  125. Ideal mode syntax:
  126.  
  127.      PROCTYPE name [procedure_description]
  128.  
  129. The MASM mode syntax is:
  130.  
  131.      name PROCTYPE [procedure_description]
  132.  
  133. procedure_description is similar to the language and argument
  134. specification for the PROC directive. Its syntax is:
  135.  
  136.      [[language_modifier] language] [distance] [argument_list]
  137.  
  138. specify language_modifier, language, and distance exactly the same way
  139. you would for the corresponding fields in the PROC directive. 
  140.  
  141. Use the following form for argument_list:
  142.  
  143.      argument [,argument] ...
  144.  
  145. An individual argument has the following syntax:
  146.  
  147.      [argname] [[count1_expression]]:complex_type [:count2_expression]
  148.  
  149.  
  150. complex_type is the data type of the argument. It can be either a
  151. simple type or a pointer expression.
  152.  
  153. count2_expression specifies how many items of this type the argument
  154. defines. Its default value is 1, except for BYTE arguments. Those
  155. arguments have a default count of 2, since you can't PUSH a byte value
  156. onto the 80x86 stack.
  157.  
  158. In procedure types whose calling convention permits variable-length
  159. arguments (like C), count2_expression (for the last argument) can be
  160. the special keyword ?, which indicates that the procedure caller will
  161. determine the size of the array. The type UNKNOWN also indicates a
  162. variable-length parameter.
  163.  
  164. The name of each argument is optional, but complex_type is required
  165. because procedure types are used mainly  for type checking purposes.
  166. The names of the arguments don't have to agree, but the types must.
  167.  
  168. Defining procedures using procedure types
  169. -----------------------------------------
  170. You can use a procedure type (defined with PROCTYPE) as a template for
  171. the procedure declaration itself. For example,
  172.  
  173.      footype PROCTYPE pascal near :word, :dword,:word
  174.      .
  175.      .
  176.      .
  177.      foo PROC footype                    ;pascal near procedure
  178.      arg a1:word,a2:dword,a3:word        ;an error would occur if
  179.                                          ;arguments did not match
  180.                                          ;those of footype
  181.  
  182. When you declare a procedure using a named procedure description, the
  183. number and types of the arguments declared for PROC are checked
  184. against those declared by PROCTYPE. The procedure description supplies
  185. the language and distance of the procedure declaration.
  186.  
  187.