home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / VAXTURBO.ZIP / VAXTURBO.DOC next >
Encoding:
Text File  |  1987-07-22  |  11.0 KB  |  240 lines

  1.                                Turbo Pascal
  2.                                   vs.
  3.                               VAX/VMS Pascal
  4.  
  5.                     A Comparison/Conversion Guidebook.
  6.  
  7.                                 9-May-1986
  8.                              Walter M. Lamia
  9.                          Digital Equipment Corp.
  10.  
  11.  
  12.   This  document  is  an attempt to facilitate the migration of programs
  13.   written in Turbo Pascal to VAX/VMS Pascal.  I have made  every attempt
  14.   to make it accurate, but neither I nor Digital Equipment Corp   may be
  15.   held liable for the accuracy, suitabi∞ity of use,  or  maintenance  of
  16.   this documention or its accompanying code.
  17.  
  18.   The  focus  of this document is to make Turbo Pascal features onto VAX
  19.   Pascal features, but not the  converse.    VAX  Pascal  is  a complete
  20.   implementation  of  Pascal,  and  is  a  fully  compliant VAX compiler
  21.   language, so it includes many extensions for controlling  linkages  to
  22.   other compiled modules, all VAX data types, etc.
  23.  
  24.   I  must, for the sake of brevity, assume that the reader has a working
  25.   knowledge of both Turbo Pascal and VAX Pascal, and has access to their
  26.   respective  documentation.  This document addresses the DIFFERENCES in
  27.   the two languages, not the similarities where they are equivalent.
  28.  
  29.   Finally,  keep  in  mind  that  this  document is only a guidebook for
  30.   converting and/or writing programs -- it  isn't  a  magic  recipe  for
  31.   doing  conversion  automatically,  although  some ambitious soul might
  32.   want to take a crack at  writing  a  (partial)  translator  program. I
  33.   won't.    (Hint:  if  anyone does want to try this, I suggest that you
  34.   investigate  the  VAX  Scan  language  as  a  potential   implemention
  35.   language.)  The  closer the program is written to standard Pascal, the
  36.   easier the  conversion  will  be.    Using  good  software engineering
  37.   practices of information hiding and modularity will also help greatly.
  38.   I also recommend highly the use of the VAX Language  Sensitive  Editor
  39.   for  creating and maintaining VAX Pascal programs, as it helps enforce
  40.   good coding practices.
  41.  
  42.   If  anyone  has  any suggestions or extensions to this document or its
  43.   accompanying library, please communicate with me.
  44.  
  45.           Walter M. Lamia
  46.           Digital Equipment Corp.               93 Central St.
  47.           ZKO2-3/M31                            Acton, MA  01720
  48.           110 Spit Brook Rd.
  49.           Nashua, NH  03062-2642
  50.           603-881-2121                          617-263-3214
  51.  
  52.           METOO::LAMIA
  53.           decvax!decwrl!dec-rhea!dec-metoo!lamia
  54.  
  55.   
  56.                           PROGRAM FORMAT
  57.  
  58.   TURBO                                 VAX
  59.   -----                                 ---
  60.  
  61.   PROGRAM statement ignored             PROGRAM required, and all files,
  62.                                            including INPUT and OUTPUT must be
  63.                                             declared
  64.  
  65.   Directives specified as {$d}          Attributes specified as [ATTRUBUTE]
  66.  
  67.   Comment delimiters {} and (* *) are   Comment delimiters are equivalent,
  68.    distinct, so nesting is allowed       so nesting is NOT allowed
  69.  
  70.   Hex constant format is $nn            Hex constant format is %X'nn'
  71.   ASCII value format is  #nn            ASCII value format is ''(nn)
  72.     ex: ESC = #$1B                        ex: ESC = ''(%X'1B')
  73.  
  74.   Control chars can be written ^G               N/A
  75.  
  76.   Include files with {$I filename}      Include files with %INCLUDE 'filename'
  77.  
  78.   Labels can be any alphanumeric                Same
  79.     identifier
  80.   
  81.  
  82.                        DATA TYPES AND REPRESENTATIONS
  83.  
  84.   TURBO                                 VAX
  85.   -----                                 ---
  86.  
  87.   even value = FALSE,                   Same
  88.     odd value = TRUE
  89.  
  90.   16-bit integer                        32-bit integer
  91.   48-bit real                           32-bit real
  92.                                         64-bit double (G and H)
  93.                                         128-bit quadruple
  94.  
  95.    VAX Pascal equivalents of Turbo types for when it matters how big
  96.           in bits the data items are.
  97.  
  98.   Type
  99.       integer16  = [WORD] -32768..32767;  { same size as Turbo Integer }
  100.       byte8      = [BYTE] 0..255;         { same size as Turbo Byte    }
  101.       uword      = [WORD] 0..65535;       { unsigned 16-bit word }
  102.  
  103.                             Variable strings
  104.  
  105.   St: STRING[n], n = 1 to 255           St: VARYING[n] OF CHAR, n = 1 to 65535
  106.     with length stored in St[0]           as a record structure with
  107.                                               length stored in St.LENGTH
  108.                                                and string body in St.BODY
  109.  
  110.   PACKED ignored                        PACKED works
  111.  
  112.   N/A                                   Compile-time expressions allowed
  113.                                             wherever a constant is used
  114.  
  115.   Typed constants for                   VAR initialization expression
  116.     initialized variables
  117.        CONST i : INTEGER = 3;               VAR i : INTEGER := 3;
  118.  
  119.                  { see appropriate documentation for variations }
  120.             { on the theme of Array and Record constant constructors }
  121.  
  122.  
  123.                    STATEMENTS, OPERATORS, FUNCTIONS, MISC
  124.  
  125.   Turbo                                 VAX Pascal
  126.   -----                                 ----------
  127.  
  128.   Retyping by the use of Type name      Retyping with the Typecast ::
  129.    as a function                         operator
  130.      Month(10) = Nov                        10::Month = Nov
  131.  
  132.   CASE  ...                             CASE ...
  133.     ELSE ...;                             OTHERWISE ...;
  134.     END;                                          END;
  135.  
  136.   Case labels may be lists              Case labels may be lists,
  137.     or subranges                          but not subranges (so far)
  138.  
  139.   real := Int(real | integer)           integer := INT( any ordinal )
  140.     (returns integer part of arg.)         (converts value of arg. to integer)
  141.   integer := TRUNC( real )              integer := TRUNC( real )
  142.  
  143.   arithmetic AND                        UAND function
  144.     r := p AND q;                         r := UAND( p, q );
  145.   arithmetic NOT                        UNOT function
  146.     r := NOT q;                           r := UNOT( q );
  147.   arithmetic OR                         UOR function
  148.     r := p OR q;                          r := UOR( p, q );
  149.   arithmetic XOR                        UXOR function
  150.     r := p XOR q;                         r := UXOR( p, q );
  151.   logical XOR                           XOR function
  152.     boolr := boolp XOR boolq;             boolr := XOR( boolp, boolq );
  153.   arithmetic SHL                        SHL function  {VaxTurbo library}
  154.     r := i SHL j;                         r := SHL( i, j );
  155.   arithmetic SLR                        SHR function  {VaxTurbo library}
  156.     r := i SHR j;                         r := SHR( i, j );
  157.  
  158.   Pos (pat, source)                     POS_ (pat, source) { VaxTurbo libr. }
  159.   Delete (source, pos, len)             DELETE_ (source, pos, len)  "
  160.   Random, Random(ceiling_integer)       REAL Random only            "
  161.  
  162.     Misc functions that are similar in intent, but are implemented differently
  163.  
  164.   SizeOf                                SIZE, but read documentation carefully
  165.   Addr                                  IADDRESS    "         "         "
  166.   FillChar                              Pad         "         "         "
  167.   Exit {from a procedure}               N/A {use a GOTO label}
  168.   Move                                  N/A
  169.   Halt                                  HALT (calls exit condition handler)
  170.                                             also see SYS$EXIT system service
  171.  
  172.   The  accompanying VaxTurbo library has emulations of many of the Turbo
  173.   Pascal built-in functions and procedures. Please read it as well.
  174.  
  175.   The  operating  system  access  features  of  Turbo  are obviously not
  176.   meaningful to VAX Pascal. These include: access to physical memory and
  177.   hardware ports as arrays; pointers to device drivers; operating system
  178.   Bios, Bdos, and MsDos calling procedures; Intr;  GetMem  and  FreeMem;
  179.   inline   absolute  machine  code;  IBM-PC  graphics,  windows,  sound.
  180.   Equivalent functionality can  be  had  in  VAX  Pascal  by  using  the
  181.   Run-Time Libraries and System Services.
  182.                                I/O OPERATIONS
  183.  
  184.   The  area  of  I/O  is   the   most   different   among   all   Pascal
  185.   implementations, and Turbo/VAX is no exception.
  186.  
  187.   In  general,  it  is  safe  enough  to  use Standard Pascal READLN and
  188.   WRITELN to the console and text files, which  both  versions  support.
  189.   Long  sequences of WRITE's to OUTPUT with no WRITELN's can cause quota
  190.   problems in VAX Pascal, for reasons that I won't go into now.  See the
  191.   CrtInit  procedure for a technique that helps alleviate the problem by
  192.   defining a non-standard long record length for OUTPUT.
  193.  
  194.   Both versions support FILE OF  (type)  and  READ/WRITE  on  sequential
  195.   files  in  about the same way.  However, random access is considerably
  196.   different, and VAX Pascal supports RMS ISAM files.
  197.  
  198.   The following is a table that will  help  you  to  compare  Turbo  I/O
  199.   features to VAX Pascal features. Rather than complicate this too much,
  200.   readers  are  referred  to  the  appropriate  documentation  for  more
  201.   details.
  202.  
  203.   Turbo                                         VAX Pascal
  204.   -----                                         ----------
  205.  
  206.   Assign/Reset/Rewrite/Append           OPEN/RESET/REWRITE/EXTEND
  207.  
  208.   {$I-} .. {$I+}                        ( .. ERROR:=CONTINUE) parameter on
  209.                                           I/O procedures
  210.  
  211.   IOResult variable                     STATUS(fv) function
  212.  
  213.   formatted WRITE default field size    ... = 12 for integer, real
  214.      = 1 for integer                        = 20 for double
  215.      = 18 for real                          = 40 for quadruple
  216.  
  217.   N/A                                   enumerated values in formatted WRITE
  218.  
  219.   N/A                                   GET / PUT
  220.  
  221.   MkDir                                 CREATE_DIRECTORY
  222.   Rename(fv)                            RENAME_FILE(fn1, fn2)
  223.   Erase (fv)                            DELETE_FILE(fn)
  224.   Seek                                  FIND / LOCATE
  225.   FilePos,FileSize                      N/A
  226.   KeyPressed                            ? - QIO's, maybe?
  227.   ParamCount,ParamStr                   Use LIB$GET_FOREIGN
  228.  
  229.   Block operations on Untyped files     fv: FILE OF ARRAY[1..512] OF CHAR;
  230.                                         OPEN(fv,fn,NEW,,SEQUENTIAL,FIXED);
  231.                                                    OLD
  232.                                         REWRITE / RESET
  233.                                         PUT / GET
  234.  
  235.   Execute                               Use LIB$DO_COMMAND or
  236.                                               LIB$RUN_PROGRAM or
  237.                                               LIB$SPAWN   as appropriate
  238.  
  239.   Chain overlays                        Don't bother!
  240.