home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / pascal / !Pascal / README < prev    next >
Encoding:
Text File  |  1992-10-22  |  39.6 KB  |  1,184 lines

  1. Introduction
  2. ============
  3.  
  4. !Pascal is an ISO Level 1 Pascal compiler. It is designed to be used with
  5. the desktop development environment supplied with Desktop C. It may
  6. be used to generate RISC OS desktop applications or relocatable
  7. modules written in Pascal.
  8.  
  9. The Pascal compiler contains a number of language extensions to
  10. overcome limitations in the ISO Pascal standard and to allow RISC OS
  11. applications to be written in Pascal.
  12.  
  13. A set of header files is provided which allow Pascal programs to be
  14. linked with the RISC_OSLib library provided with Desktop C.
  15.  
  16. The Pascal run time library is provided in two variants, one for
  17. linking applications and the second for linking modules. The Pascal
  18. run time library calls the C library so programs written in Pascal
  19. must be linked with either the unshared library ANSILib or the shared
  20. library Stubs.
  21.  
  22. An example desktop program !Balls64 is included. This is a conversion
  23. of the !Balls64 program provided with Desktop C.
  24.  
  25. Installation
  26. ------------
  27.  
  28. To install !Pascal to a hard disc simply copy the !Pascal directory into the
  29. DDE directory on your hard disc.
  30.  
  31. Copy the following lines to your !Make.choices.tools file in the DDE
  32. directory.
  33.  
  34. ------------------------------------
  35. Pascal
  36. p
  37. -c -depend !Depend -throwback -IP:
  38. Pascal $(Pascalflags) -o $@ $<
  39. DDE:!Pascal.desc
  40. DDE:!Pascal.!setup
  41. ------------------------------------
  42.  
  43. Installing for command line use
  44. -------------------------------
  45.  
  46. If you wish to use the Pascal compiler from the command line
  47. copy/rename the file !Pascal.Pascal to your library directory and add the
  48. following line to your !Boot.
  49.  
  50. %Obey <DDE directory>.!Pascal.!Boot
  51.  
  52. Where <DDE directory> is substituted with the full pathname of your
  53. DDE directory. This sets up the variables P$LibRoot and P$Path which
  54. are used by the Pascal compiler to locate the pascal library and the
  55. RISC_OSLib Pascal headers.
  56.  
  57. Using the Pascal compiler from the command line is described in the
  58. section "The command line".
  59.  
  60. Using !Pascal
  61. =========
  62.  
  63. To start !Pascal double click on the !Pascal application. This will place the
  64. !Pascal icon on the icon bar.
  65.  
  66. Click Select on the !Pascal icon, this will open a setup dialog box
  67. containing a single writeable icon labelled "Source:", a number
  68. of option icons and two action icons labelled "Run" and "Cancel".
  69.  
  70. To compile a Pascal program drag the Pascal source to the Source
  71. icon and click Run. Note the Pascal source must be stored in a
  72. directory called "p", this is to allow !Make to differentiate between
  73. C and Pascal sources.
  74.  
  75. If the program compiles successfully a "Save" dialog box will be
  76. displayed containing an icon representing the compiled image. Drag
  77. this to a directory viewer and run it by double clicking on it.
  78.  
  79. If errors are encountered in the source the errors will be listed in a
  80. window. If you are using the editor !SrcEdit and the "Throwback"
  81. option is enabled the errors will also be displayed in a "Throwback"
  82. window. Double clicking on an error in the Throwback will cause
  83. !SrcEdit to open the source file containing the error at the line
  84. which generated the error, this line will be highlighted for clarity.
  85.  
  86. If you have more than one source file to compile drag all the source
  87. files to the "Source" icon and click Run. All the source files will
  88. be compiled in turn and then linked together to produce a single
  89. executable. Note: standard Pascal does not allow you to write your
  90. programs in separate source units, !Pascal allows this by means of
  91. language extensions described in the section "Language extensions".
  92.  
  93. Setup dialog box options
  94. ------------------------
  95.  
  96. Compile only:
  97.  
  98. Usually when !Pascal is used to compile a Pascal program it automatically
  99. runs the linker to bind your program with the Pascal run time library.
  100. This option can be used to prevent the link step from happening. You
  101. may want to do this if you have a number of Pascal sources which you
  102. wish to compile separately. You should place such files in a
  103. directory called "o" so that !Pascal and !Make can differentiate between
  104. pre-compiled object files and source files.
  105.  
  106. To link object files generated this way drag the object files to the
  107. Source icon and click Run. !Pascal will notice that they are pre-compiled
  108. object files (because they are stored in the "o" directory) and will
  109. just perform the necessary link step. (You can drag any mixture of
  110. source and object file in, !Pascal will perform the appropriate action
  111. on each and then link them all).
  112.  
  113. Assembler output:
  114.  
  115. Use this option if you wish to examine the assembler code generated
  116. by the compiler.
  117.  
  118. ISO:
  119.  
  120. If this option is enabled !Pascal will compile strictly according to the
  121. Pascal standard as described in BS 6192 : 1982.
  122.  
  123. Debug:
  124.  
  125. If this option is enabled !Pascal will generate an image suitable for
  126. use with the desktop debugger !DDT. The debugging facilities provided
  127. by DDT are limited in certain ways when debugging Pascal programs,
  128. these limitations and debugging in general are described in the
  129. section "Pascal and DDT".
  130.  
  131. Throwback:
  132.  
  133. If this option is enabled and the editor !SrcEdit is loaded errors
  134. in compilation are listed in a Throwback window. This window can
  135. be use to rapidly locate and correct errors in your program.
  136.  
  137. This option is enabled by default.
  138.  
  139. Uses RISC_OSLib:
  140.  
  141. This option should be selected if your pascal program makes any calls
  142. to RISC_OSLib library functions. It cause the compiler to instruct the
  143. linker to include RISC_OSLib in the list of libraries to be searched.
  144.  
  145. Run time checks:
  146.  
  147. These options enable or disable the generation of run time checking
  148. code which is inserted in the generated code. When developing
  149. a program you will probably wish to leave all these options enabled.
  150. For the final compilation, however, you may wish to disable some or
  151. all of the run time checks to reduce code size and improve
  152. performance.
  153.  
  154. Array bounds:
  155.  
  156. This option inserts code to check that array accesses do not exceed
  157. their array bounds.
  158.  
  159. Nil pointers:
  160.  
  161. This option inserts code to check that Nil pointers are not
  162. dereferenced.
  163.  
  164. Variable references:
  165.  
  166. This option inserts code to check that variables are assigned before
  167. being referenced.
  168.  
  169. Assertion statements:
  170.  
  171. One of the language extensions described in the section "Language
  172. extensions" is an "assert" statement which allows you to insert
  173. your own checks in your code. If this option is enabled the compiler
  174. will compile these assert statements. If the option is disabled such
  175. statements will not be compiled and no extra code will be generated.
  176.  
  177. Range checking:
  178.  
  179. Inserts code to check that, when a value is assigned to a variable
  180. (either directly or as the result of a procedure or function call),
  181. the value assigned is within the type range of the variable.
  182.  
  183. Setup menu options
  184. ------------------
  185.  
  186. Other less commonly used options may be accessed from the menu
  187. on the setup dialog box. These options are as follows.
  188.  
  189. Command line:
  190.  
  191. This option allows you to examine and/or change the command line
  192. generated by the !Pascal frontend which is used to run the Pascal
  193. compiler. When you change the command line and wish to execute the
  194. changed command click on the Run icon in the Command line dialog box.
  195. Once you move off the Command line dialog box onto the setup menu
  196. the changed command line will be forgotten and the original command
  197. line (as constructed by the !Pascal tool) will be reconstructed.
  198.  
  199. No warnings:
  200.  
  201. Supresses the generation of warning messages.
  202.  
  203. Module code:
  204.  
  205. This options must be enabled when compiling code to be used to
  206. generate a RISC OS relocatable module using the CMHG tool. For
  207. more information on writing relocatable modules in Pascal refer
  208. to the section "Writing relocatable modules in Pascal"
  209.  
  210. Profile:
  211.  
  212. This option enables the generation of code which is suitable for
  213. use with the ANSILib functions _mapstore and _fmapstore. This
  214. code counts the number of times each function or block of code
  215. is executed. _mapstore and _fmapstore output the profiling
  216. information to the screen or to a named file respectively. For
  217. details on how to call _mapstore or _fmapstore from Pascal refer
  218. to the section "Language extensions".
  219.  
  220. Preprocess only:
  221.  
  222. The compiler uses a pre-processor (similar to the C pre-processor)
  223. before performing the actual compilation. This option disables the
  224. compilation and just runs the pre-processor on the source file. The
  225. pre-processed output is displayed in the compilation window.
  226.  
  227. Include:
  228.  
  229. When searching for "include" files (described in the section
  230. "Language extension") the compiler usually search the path P:
  231. (ie the setting of the variable P$Path). You can use this option
  232. to change where the compiler searches for header files.
  233.  
  234. Keep comments:
  235.  
  236. Normally when pre-processing the compiler removes any comments in
  237. the source code. If this option is enabled the pre-processor will
  238. not remove comments.
  239.  
  240. Libraries:
  241.  
  242. This option specifies a list of libraries to be searched when linking.
  243. These libraries are in addition to the default Pascal run time
  244. library ("P:o.PLib"). By default this option is set to
  245. "C:o.RISC_OSLib,C:o.stubs".
  246.  
  247. Pascal programs must be linked with the C library as the Pascal run
  248. time library calls the C library. By default they are linked with
  249. the shared library Stubs. You can change this using this option to
  250. link with the unshared ANSILib instead, if, for example you wish to
  251. use the _mapstore or _fmapstore functions which are not included in
  252. shared library or if you wish to use the overlay manager in the
  253. unshared library.
  254.  
  255. Predefine:
  256.  
  257. The pre-processor allows you to define symbols which can be used to
  258. conditionally compile sections of code. The use of pre-processor
  259. symbols is described in the section "Language extensions". You may
  260. wish to use this option if, for example, you have code which displays
  261. debugging information which you would not normally wish to have
  262. compiled unless you are trying to debug the program.
  263.  
  264. Undefine:
  265.  
  266. The compiler automatically defines some pre-processor symbols on
  267. startup. These symbols are listed in the section "Language
  268. extensions". This option allows you to undefine any or all of
  269. the symbols.
  270.  
  271. Work directory:
  272.  
  273. This option allows you to change the "Work directory" used by !Pascal.
  274. The concept of a work directory is explained in the section
  275. "File naming and placing" in the Desktop C manual.
  276.  
  277. Other:
  278.  
  279. This allows you to specify other options to the underlying command
  280. line compiler. These options have not been included in the setup
  281. dialog because they are obscure and rarely used. A list of these
  282. options is given in the section "The command line".
  283.  
  284. Language extensions
  285. ===================
  286.  
  287. Identifiers
  288.  
  289. Identifiers may start with and contain underscores. There is no limit
  290. on identifier length and all characters are significant.
  291.  
  292. Files
  293.  
  294. Input and output need not appear in the program header. `File of char'
  295. and `packed file of char' are treated as equivalent to `text'. Lazy
  296. evaluation is performed on files opened for input. In the absence of
  297. explicit file bindings (see reset and rewrite in the section on
  298. library extensions) external files are bound to a filename
  299. corresponding to the file identifier in the current directory, input
  300. and output are bound to the equivalent of C stdin and stdout streams
  301. (normally the keyboard and screen). Files are buffered, on a read
  302. request from input the output buffer is flushed. 
  303.  
  304. Strings
  305.  
  306. Strings are blank padded or truncated in expressions and as value
  307. parameters to fit the required size. Strings may be of length 1. The
  308. null string '' is permitted. The packed attribute may be omitted in a
  309. string declaration.
  310.  
  311. Pascal strings are zero terminated, the compiler adds one byte to the
  312. allocation space of the string and initialises this byte to zero when
  313. the string is assigned. Thus Pascal strings may be used in calls to
  314. external functions written in C.
  315.  
  316. The predefined type string is equivalent to the C `char *' and may be
  317. used in external calls to C.  Variables of type string are compatible
  318. with Pascal strings and may be used in assignments and expressions and
  319. as value parameters. Note that no space is allocated for a variable of
  320. type string, space must be allocated either by assignment or by
  321. explicit allocation using, for example, malloc.
  322.  
  323. The predefined type alpha = packed array[1..10] of char is intended
  324. for use with the extended Pascal library, for example, date and time.
  325. See the section on library extensions.
  326.  
  327. Procedures and functions
  328.  
  329. Procedures may return values, these are declared like functions with
  330. the keyword procedure substituted for function. Value returning
  331. procedures may be called in a procedure or function context.  This is
  332. intended for use with external functions which return error codes
  333. which are not generally checked, for example, putchar.
  334.  
  335. Procedures and functions may return records, like pointers these may
  336. not be immediatly referenced but must be assigned to a variable.
  337.  
  338. Variadic functions may be declared by placing a .. as the last
  339. parameter. Variadic arguments may be accessed using the address and
  340. size functions (see the section on library extensions) however the
  341. intended purpose is for declaring external variadic functions, for
  342. example, printf.
  343.  
  344. Procedure and functions pointers may be declared, these are declared
  345. by placing a `^' before a procedure or function declaration in a type
  346. declaration, note that the procedure or function must be given a name
  347. and all parameters must be named. Only top level and external
  348. procedures or functions may be be assigned to a procedure or function
  349. pointer. Procedure and function pointers are intended for use with
  350. external procedures or functions which take or return procedure or
  351. function pointers, for example, signal.
  352.  
  353. External objects
  354.  
  355. Procedures, functions and variables may be declared external or global
  356. by placing extern; or external; after the declaration (like forward is
  357. used for declaring forward referenced procedures or functions).  Such
  358. objects are taken to be external if there is no definition of the
  359. object in the same module and global if there is a definition. Objects
  360. declared external use the case of the external declaration identifier.
  361. External declarations are case sensitive between modules and case
  362. insensitive within a single module. The program heading may be omitted
  363. to create a module containing only procedure and functions and/or
  364. variables. No mainline may be given if the program heading is omitted.
  365.  
  366. The recommended way to use external declarations is to create a header
  367. file (ending with `.h') containing the external declarations and use
  368. the #include mechanism provided by the C preprocessor to include this
  369. header in both the module defining the object and the module
  370. referencing the object. This insures type correctness between modules.
  371. Note that the filename after the #include must be enclosed in double
  372. quotes not single quotes.
  373.  
  374. Type casts
  375.  
  376. For each pointer, ordinal or file type declared a cast function of the
  377. same name is automatically declared which casts a pointer, ordinal or
  378. file variable to the declared type.
  379.  
  380. Constants
  381.  
  382. Constant expressions may be used in const declarations. The following
  383. functions may be used in constant expressions if they have constant
  384. arguments: shl, shr, uand, uor, uxor, unot, trunc, ord, chr, succ,
  385. pred, odd, and undefined.
  386.  
  387. Declarations
  388.  
  389. Multiple Label, Const, Type and Variable declarations sections may be
  390. given within a single block. Label, Const, Type, Variable, Procedure
  391. and Function declarations may occur in any order.
  392.  
  393. Predefined types
  394.  
  395. string = ^char - This type is compatible with Pascal strings and is
  396. intended for use with with external library functions which require a
  397. C style string.
  398.  
  399. alpha = packed array[1..10] of char - This type is used with the
  400. extended library functions time and date.
  401.  
  402. pointer - This is a generic pointer type compatible with all other
  403. pointer types. It is equivalent to the C void * type.
  404.  
  405. byte - This is a one byte long signed integer type.
  406.  
  407. short - This is a half word long signed integer type.
  408.  
  409. word - This is a word long unsigned integer type.
  410.  
  411. os_error - Variables of this type may be used to hold pointers to RISC OS
  412. errors. These variables are compatible with the with the Pascal type
  413. boolean yielding True if the variable points to RISC OS error block.
  414.  
  415. Operators
  416.  
  417. The additional operators `&' and `|' are provided. These are
  418. functionally identical to and and or.
  419.  
  420. Preprocessor
  421. ------------
  422.  
  423. The Pascal compiler invokes the C preprocessor on the Pascal source
  424. before compiling it. A complete description of the C preprocessor
  425. is not given here.
  426.  
  427. #include "<header>.h"
  428.  
  429. This reads a header file "h.<header>" into your Pascal source. Header
  430. files are used to contain inter module definitions when writing
  431. multiple module Pascal programs. A standard set of headers is provided
  432. for use with modules in the library RISC_OSLib. See the example
  433. program !Balls64 for examples of how to use RISC_OSLib.
  434.  
  435. Header files are searched for first in the current directory, then in
  436. the directory <P$LibRoot>. By default <P$LibRoot> is set to P:. This
  437. causes the compiler to search the directory specified by the comma
  438. separated list of directories in P$Path. This is set up by the !Pascal
  439. application to point to the directory containing the RISC_OSLib
  440. headers.
  441.  
  442. #define <symbol> [<expansion>]
  443.  
  444. This defines a simple symbol expansion. The <symbol> is replaced with
  445. its expansion when it occurs in your source. If <expansion> is omitted
  446. the following default is used.
  447.  
  448. #define <symbol> 1
  449.  
  450. #define <macro>(<arg1>, <arg2>, ...) <macro expansion>
  451.  
  452. This defines a macro expansion. When a function or procedure call is
  453. made which corresponds to the macro definition the macro is expanded.
  454. Arguments <arg1>, <arg2>, ... are replaced where they occur in the
  455. macro expansion.
  456.  
  457. #undef <symbol>|<macro>
  458.  
  459. Removes a symbol or macro definition.
  460.  
  461. #ifdef <symbol>
  462. #else
  463. #endif
  464.  
  465. This construct may be used to conditionally compile section of code.
  466. If the preprocessor symbol <symbol> is defined the code between
  467. the #ifdef <symbol> and the #else is compiled, otherwise the code
  468. between the #else and the #endif is compiled. The #else clause may
  469. be omitted.
  470.  
  471. The use of the C preprocess #if is not supported.
  472.  
  473. #error <text of error>
  474.  
  475. Causes compilation to stop printing <text of error>. This may be
  476. used when conditionally compiling code for different architectures or
  477. operating systems, for example,
  478.  
  479. #ifdef BIG_ENDIAN
  480. #error This code must be modified to run on a big endian machine
  481. #endif
  482.  
  483. #pragma -<letter>[<digit>]
  484. #pragma [no_]<pragma>
  485.  
  486. Pragmas may be specified in two forms, a long form and a short form.
  487. The following pragmas are recognised.
  488.  
  489. long form                       short form      negative short form
  490. ---------                       ----------      -------------------
  491. check_memory_accesses              -c1                  -c0
  492. continue_after_hash_error          -e1                  -e0
  493. profile                            -p1                  -p0
  494. check_stack                        -s0                  -s1
  495.  
  496. check_memory_accesses           (default = off)
  497.  
  498. This tells the compiler to insert code to check that memory accesses
  499. (via pointers or arrays) are within the application space allocated
  500. to the application.
  501.  
  502. continue_after_hash_error       (default = off)
  503.  
  504. This tells the compiler to continue compilation after it encounters
  505. a #error statement.
  506.  
  507. profile                         (default = off)
  508.  
  509. This pragma tells the compiler to insert code to count the number of
  510. times each procedure or function is called. To display the count
  511. insert a call to _mapstore or _fmapstore at the end of your program.
  512.  
  513. check_stack                     (default = on)
  514.  
  515. This pragma tells the compiler to insert code to check that the stack
  516. limit has not been exceeded in each procedure / function entry. The
  517. code checks that the procedure / function has enough stack to execute
  518. to completion and will try to extend the stack if this is not the
  519. case.
  520.  
  521. check_stack must be disabled around signal handlers which deal with
  522. stack overflow.
  523.  
  524. Library extensions
  525. ------------------
  526.  
  527. address(x) : pointer
  528.  
  529. Returns the address of variable access x.
  530.  
  531. argc : integer
  532.  
  533. Returns the number of command line arguments to the program including
  534. the program name (ie argc is always at least 1).
  535.  
  536. argv(i, a)
  537.  
  538. where i is an integer expression in range 0 to argc and a is a string
  539. variable. If a is of type string then the C expression argv[i] is
  540. assigned directly to a (ie a will point directly into the argv array
  541. and should not therefore be modified otherwise the contents of argv[i]
  542. are copied (possibly blank padded or truncated) to a.
  543.  
  544. assert(x[, a])
  545.  
  546. where x is a boolean expressions and a is an optional string
  547. expression (typically explaining why the assertion might have failed).
  548. The assert call checks the value of x and if it is false generates a
  549. run time error giving the file and line number where the assertion
  550. failed. The reason string a is also printed if given in the assert
  551. call. Calls to the assert function must be enabled with the -rp option
  552. on the command line.
  553.  
  554. byte_offset(t, f) : integer
  555.  
  556. t is the name of a record type, f is the name of a field within that
  557. record. Returns the offset (in bytes) of field f within a variable of
  558. record type t.
  559.  
  560. card(s) : integer
  561.  
  562. where s is a set expression returns the number of elements in s.
  563.  
  564. close(f)
  565.  
  566. where f is a file variable close the file bound to f, deallocates all
  567. buffers associated with f and frees f for reallocation.
  568.  
  569. clock : integer
  570.  
  571. returns the number of milliseconds elapsed since this program started.
  572.  
  573. date(a)
  574.  
  575. where a is a variable of type alpha assigns the current date to a in
  576. the form `dd mmm yy'.
  577.  
  578. flush(f)
  579.  
  580. flushes any output buffered for file f into its associated file
  581. binding.
  582.  
  583. halt
  584.  
  585. stops execution and returns control to the parent process with a
  586. return code of 0.
  587.  
  588. iaddress(x) : integer
  589.  
  590. Returns the address of variable access x as an integer. This is
  591. equivalent to integer(address(x)).
  592.  
  593. ignore(x)
  594.  
  595. where x is an expression of any type. Does nothing.
  596.  
  597. linelimit(f, x)
  598.  
  599. where f is a variable of type text and x is and integer expression.
  600. Limits the number of lines of output to file f to x. If x is less than
  601. 0 no limit is imposed. By default no limit is imposed. These limits
  602. are ignored by the current release.
  603.  
  604. message(...)
  605.  
  606. This is equivalent to writeln(...) except it writes to the unbuffered
  607. error stream stderr.
  608.  
  609. null
  610.  
  611. Does nothing.
  612.  
  613. random(x) : real
  614.  
  615. where x is a real expression which is evaluated but otherwise ignored
  616. returns a random number between 0.0 and 1.0 inclusive.  random uses a
  617. linear congruential random number generator. Successive seeds are
  618. generated as (seed * 62605 + 113218009) mod 536870912. The initial
  619. seed is 7774755. The `random' numbers generated by this method are not
  620. very random, the preferred method is to use the external function
  621. rand.
  622.  
  623. read(..., a, ...)
  624.  
  625. readln(..., a, ...)
  626.  
  627. where a is a string variable reads the remainder of the text line into
  628. a. The text line is blank padded or truncated to fit the string. If
  629. the variable is of type string it is assumed that it is pointing to an
  630. allocated area large enough to hold the current line.
  631.  
  632. remove(a)
  633.  
  634. where a is a string expression removes the file whose name is a
  635. (with trailing blanks removed).
  636.  
  637. reset(f, a)
  638.  
  639. where f is a file variable and a is a string expression associates the
  640. filename f with the file variable and opens that file for reading.
  641. Note that there is no way of detecting an error opening a file (eg.
  642. file not found). To do this use the external function fopen.
  643.  
  644. rewrite(f, a)
  645.  
  646. Similarly to reset, the two argument form of rewrite allows a filename
  647. to be bound to a file variable except the file is opened for writing
  648. instead of reading.
  649.  
  650. seed(x) : integer
  651.  
  652. where x is an integer expression sets the current random number
  653. generator seed to x and returns the value of the previous seed.
  654.  
  655. shl(x1, x2) : integer
  656.  
  657. where x1 and x2 are integers returns x1 shifted left x2 times. This is
  658. equivalent to x1 << x2 in C.
  659.  
  660. shr(x1, x2) : integer
  661.  
  662. where x1 and x2 are integers returns x1 shifted right x2 times. This
  663. is equivalent to x1 >> x2 in C.
  664.  
  665. size(x) : integer
  666.  
  667. where x is a variable access returns the size of variable access x in
  668. bytes.
  669.  
  670. stlimit(x)
  671.  
  672. where x is an integer expression limits the number of statements that
  673. may be executed by the current program. By default no limit is
  674. imposed. This limit is ignored by the current release.
  675.  
  676. swi(<swi-no> [ , <inregset> { , <inarg> } ]
  677.      [ ; <outregset> { , <outarg> } ] [ ; <returnreg> ]) : integer
  678. swix(<swi-no> [ , <inregset> { , <inarg> } ]
  679.      [ ; <outregset> { , <outarg> } ]) : error
  680.  
  681. calls a RISC OS SWI. swix calls the X form of the SWI, swi calls the
  682. non X form.
  683.  
  684. <swi-no> is an integer expression specifying the SWI no.,
  685. alternatively <swi-no> may be a constant string literal specifying the
  686. name of the SWI to be called, this name is looked up by the compiler
  687. at compile time and converted into the SWI no.
  688.  
  689. <inregset> is a constant register set specifying the input registers
  690. for the SWI.
  691.  
  692. Each <inarg> argument corresponds to one set element in the <inregset>
  693. from low numbered registers to high numbered registers. Each argument
  694. must be less than or equal to a machine word in size. If an array,
  695. record or string is specified as an input register the address is
  696. taken and passed to the SWI.
  697.  
  698. <outregset> is a constant register set specifying the output registers
  699. for the SWI.
  700.  
  701. Each <outarg> argument corresponds to one set element in the
  702. <outregset> from low numbered registers to high numbered registers.
  703. Each argument must be equal to a machine word in size (the compiler
  704. will pad some arguments less than a word in size to a word size).
  705.  
  706. <returnreg> specifies a register to be returned from the swi function
  707. call. If this is not specified R0 is returned by default.
  708.  
  709. swix returns type error. This is a pointer to a system error, this is
  710. set to the Nil pointer if there was no error. The type error may be
  711. used in boolean expressions yielding True if it points to an error
  712. block.
  713.  
  714. Eg:
  715.   e = swix('Wimp_Initialise', [0,1,2], 200, $4b534154, 'Test';
  716.                               [1], task_handle);
  717.  
  718. sysclock : integer
  719.  
  720. returns the number of milliseconds elapsed since this program started.
  721.  
  722. time(a)
  723.  
  724. where a is a variable of type alpha assigns the current local time to
  725. a in the form `hh:mm:ss'.
  726.  
  727. uand(x1, x2) : integer
  728.  
  729. where x1 and x2 are integer returns the bitwise and of x1 and x2. This
  730. is equivalent to x1 & x2
  731.  
  732. uor(x1, x2) : integer
  733.  
  734. where x1 and x2 are integer returns the bitwise or of x1 and x2. This
  735. is equivalent to x1 | x2 in C.
  736.  
  737. undefined(x) : boolean
  738.  
  739. where x is a real expression returns false.
  740.  
  741. unot(x) : integer
  742.  
  743. where x is integer returns the bitwise negation of x. This is
  744. equivalent to ~x in C.
  745.  
  746. uxor(x1, x2) : integer
  747.  
  748. where x1 and x2 are integer returns the bitwise exclusive or of x1 and
  749. x2. This is equivalent to x1 ^ x2 in C.
  750.  
  751. write(..., x [: n] <mode>, ...)
  752.  
  753. writeln(..., x [: n] <mode>, ...)
  754.  
  755. where x is a boolean, character or integer expression, n is an
  756. optional field width and <mode> is one of hex or oct writes the
  757. expression x in hexadecimal or octal notation respectively.
  758.  
  759. wallclock : integer
  760.  
  761. returns the time in seconds since 00:00:00 GMT, January 1, 1970.
  762.  
  763. The command line
  764. ================
  765.  
  766. The syntax of the Pascal command line is:
  767.  
  768. *Pascal [options] filenames
  769.  
  770. The following options are available
  771.  
  772. -iso
  773.  
  774. Compile strictly according to the ISO Pascal standard (equivalent to
  775. BS 6192 : 1982).
  776.  
  777. -c
  778.  
  779. Do not perform the Link step. This merely compiles the source
  780. program(s), leaving the object file(s) in the o directory.
  781.  
  782. -E
  783.  
  784. If this flag is specified, only the preprocessor phase of the compiler
  785. is executed. The output from this phase is sent to the standard output
  786. stream. This may be redirected to a file by using the command line
  787. output redirection. For example:
  788.  
  789. Pascal -E myprog > ppoutput
  790.  
  791. -C
  792.  
  793. When used in conjunction with the -E option this option specifies
  794. that comments should be included in the pre-processor output.
  795.  
  796. -D<symbol>
  797.  
  798. This option may be used to define a preprocessor symbol. These symbols
  799. may be used to conditionally compile sections of code using the #ifdef
  800. or #ifndef preprocessor constructs. The pre-processor is described in
  801. the section "Language extensions".
  802.  
  803. -U
  804.  
  805. This option may be used to undefine certain symbols which are defined
  806. automatically by the compiler, for example the symbol "__arm".
  807.  
  808. -w
  809.  
  810. Supresses the generation of warning messages
  811.  
  812. -s
  813.  
  814. If this flag is specified, no object code is generated. Instead an
  815. assembly listing of the code produced is written to s.<file>.
  816.  
  817. -g
  818.  
  819. Generate debugging tables suitable for use with the desktop debugger
  820. DDT. Object files with debugging tables must be linked with the -debug
  821. option to be usable with the debugger.
  822.  
  823. -r<mod>
  824.  
  825. Enables a selction of run time checks. Enabling these checks may add
  826. considerably to the size and speed of execution of the generated code
  827. so they should be left disabled for production software. Multiple
  828. modifiers may be specified after the -r, for example, -rarnp will
  829. enable all run time checking.
  830.  
  831. -ra
  832.  
  833. This options turns on array bound checking, if an array bound is
  834. exceeded during execution the error "Array index out of bounds" will
  835. be generated. Use the debugger to determine the location of the error.
  836.  
  837. -rn
  838.  
  839. Turns on Nil pointer checking. If a Nil pointer is referenced during
  840. execution the error "Uninitialised variable or Nil pointer referenced"
  841. will be generated. Use the debugger to determine the location of the
  842. error.
  843.  
  844. -rr
  845.  
  846. Turns on uninitialised variable checking. If an uninitialised variable
  847. reference is detected during execution the error "Uninitialised
  848. variable or Nil pointer referenced" will be generated. Use the
  849. debugger to determine the location of the error.
  850.  
  851. -rp
  852.  
  853. Enables the generation of code for assertion statements embedded in
  854. the code. If an assertion statement fails the message "*** assertion
  855. failed: <diagnostic string>, file <file>, line <line>" will be written
  856. to the standard error stream followed by a postmortem backtrace. If
  857. you are running the program from within the desktop you will need to
  858. redirect the standard error stream to a file to prevent the output
  859. being written to the graphics screen. To do this use the command line
  860. redirection facility, for example, "Run <Prog$Dir>.!Runimage
  861. 2><Prog$Dir>.ErrOutput".
  862.  
  863. -rv
  864.  
  865. Enables range checking on assignment of variables, either by direct
  866. assignment or as the result of a procedure / function call.
  867.  
  868. -ff
  869.  
  870. Do not embed function names in the code area. The compiler does this
  871. to make the output produced by the stack backtrace function and
  872. _mapstore() more readable. Removing the names makes the code slightly
  873. smaller (typically 5%) at the expense of less meangingful backtraces
  874. and _mapstore() outputs.
  875.  
  876. -fw
  877.  
  878. Allow string literals to be writeable, as expected by some older UNIX
  879. code, by allocating them in the program's data area rather than the
  880. notionally read-only area.
  881.  
  882. You will need to use this option if you are generating code for use
  883. with the overlay manager.
  884.  
  885. -p
  886.  
  887. Generate code suitable for use with the _mapstore() and _fmapstore
  888. profiling functions in ANSILib
  889.  
  890. -zp<mod>
  891.  
  892. This option can be used to select one of the #pragma directives over
  893. a complete source module. These are described in the section on the
  894. preprocessor.
  895.  
  896. For example the option -zps1 would disable stack checking in all the
  897. functions in the source module being compiled.
  898.  
  899. Other options
  900. -------------
  901.  
  902. Other unrecognised options will be passed through to the linker. For
  903. example the -o <filename> which is used to specify the name of the
  904. image to be generated and the -l <libraries> which may be used to
  905. specify a comma separated list of libraries to be included in the link
  906. step.
  907.  
  908. Pascal and DDT
  909. ==============
  910.  
  911. To prepare a program for use with DDT specify the "Debug" option in
  912. the compiler and linker setup dialog boxes or the -g and -debug
  913. options on the compiler and linkers command line respectively.
  914.  
  915. If you are using the compiler to perform the link step you do not need
  916. to specify the debug option to the linker. The compiler will specify
  917. this when it invokes the linker.
  918.  
  919. The Pascal compiler creates a pseudo procedure 'main' which
  920. corresponds to the start of the Pascal program. DDT automatically sets
  921. a breakpoint on 'main' when it starts so just selecting continue in
  922. DDT will continue execution (through the library initialisation) until
  923. it reaches the start of your source code and then stop and display
  924. your source code.
  925.  
  926. You can display Pascal variables but there are some limitations.
  927. Global Pascal variables are not available to the debugger, local
  928. variables and procedure/function arguments are. If this causes
  929. problems you can wrap your entire program up in a single procedure and
  930. have a simple mainline which just calls this procedure. This has the
  931. effect of making all global variable local to the procedure and hence
  932. accessible by the debugger.
  933.  
  934. When entering expressions in the debugger they must be entered using C
  935. syntax as this is the only syntax the debugger understands. When the
  936. debugger displays expressions it will display them in C style syntax.
  937.  
  938. Procedures are named as <proc>.<subproc>.<subsubproc>... Procedure
  939. procb in the following would be referred to as proca.procb.
  940.  
  941. Procedure proca;
  942.  
  943. Procedure procb;
  944.  
  945. ...
  946.  
  947. Data representation
  948. ===================
  949.  
  950. This section describes how pascal objects (records, arrays etc) are
  951. represented at the machine level. This information is required if you
  952. are writing code which calls or is called by code written in other
  953. languages (for example, C or assembler).
  954.  
  955. The Pascal compiler uses the APCS-R variant of the ARM Procedure Call
  956. Standard. This has the following register bindings. The ARM Procedure
  957. Call Standard is not described here. It is described in the C Release
  958. 3 and Desktop Development Environment manuals.
  959.  
  960. sl      RN      10
  961. fp      RN      11
  962. ip      RN      12
  963. sp      RN      13
  964.  
  965. These are the same bindings as those used by C Release 3 and C Release
  966. 4. C Release 2 and ForTran 77 use different register bindings so code
  967. compiled using these compilers cannot easily be interworked with
  968. Pascal.
  969.  
  970. The following describes the machine representation for each pascal
  971. type.
  972.  
  973. Simple types:
  974. -------------
  975.  
  976. Integer
  977. -------
  978.  
  979. Integers and subranges of integers are stored as words (32 bits).
  980. These are always word aligned. The compiler will insert padding in
  981. records to ensure this. On function entry integer arguments may be
  982. stored in registers 0 to 3.
  983.  
  984. This is compatible with the C type 'int'.
  985.  
  986. Real
  987. ----
  988.  
  989. Reals are stored as two words, word aligned. On function entry a real
  990. may occupy 2 of the registers 0 to 3.
  991.  
  992. This is compatible with the C type 'double'.
  993.  
  994. Char
  995. ----
  996.  
  997. Chars and subranges of chars are stored as single bytes. On function
  998. entry these may be stored (0 extended) in registers 0 to 3. Chars
  999. which are not part of an array or record are stored in words (the
  1000. unused bytes in the word are 0 padded).
  1001.  
  1002. Care must be taken when passing a char which is an element of an array
  1003. or record by address or by reference to an external function written
  1004. in another language. You must ensure that the external function does
  1005. not write back a full word. If this is the case it may overwrite other
  1006. elements of the array or record. In this case use a Char which is not
  1007. an element of an array or record and assign it into the array or
  1008. record when the procedure / function returns.
  1009.  
  1010. Boolean
  1011. -------
  1012.  
  1013. Booleans and subranges of booleans are stored as single bytes. False
  1014. has the ordinal value 0, True has the ordinal value 1. On function
  1015. entry these may be stored (0 extended) in registers 0 to 3. Booleans
  1016. which are not part of an array or record are stored in words (the
  1017. unused bytes in the word are 0 padded).
  1018.  
  1019. Similar care must be taken when passing Booleans which are elements of
  1020. arrays or records to functions by address or reference.
  1021.  
  1022. Text
  1023. ----
  1024.  
  1025. This uses the same representation as the compound type File of Char.
  1026.  
  1027. Compound types:
  1028. ---------------
  1029.  
  1030. Compound types are stored at word aligned addresses, no distinction is
  1031. made between packed and unpacked types.
  1032.  
  1033. The storage of conformant array formal parameters and procedure or
  1034. function formal parameters is not described here.
  1035.  
  1036. Records
  1037. -------
  1038.  
  1039. Element of records are stored at monotonically increasing addresses
  1040. within the record. These addresses are padded as necessary to fit the
  1041. alignment constraints of the record elements.
  1042.  
  1043. For variant records the maximum space is allocated to allow storage of
  1044. any variant in the variant part. If a variant descriminator is present
  1045. this is stored after all other elements of the record and before the
  1046. variant part.
  1047.  
  1048. Arrays
  1049. ------
  1050.  
  1051. Elements of arrays are stored at monotonically increasing addresses
  1052. within the array. For arrays of char an extra byte is allocated to the
  1053. storage size of the array, this byte is initialised to 0. This allows
  1054. Pascal arrays of char to be used in system and C library calls which
  1055. require 0 terminated strings.
  1056.  
  1057. Sets
  1058. ----
  1059.  
  1060. Sets are stored as bit images, each bit corresponding to one element
  1061. of the set (1 => element is present). Bits are allocated starting at
  1062. the lowest word in the set then in the lowest bit within that word.
  1063.  
  1064. Files
  1065. -----
  1066.  
  1067. Files are stored as single words containing a pointer to a
  1068. data structure within the library. This structure is compatible with
  1069. the C structure FILE. This allows Pascal file variables to be used in
  1070. calls to C file handling functions.
  1071.  
  1072. Pointers
  1073. --------
  1074.  
  1075. Pointers are stored in single words which address the object pointed
  1076. to. The value 0 is used to denote the Nil pointer.
  1077.  
  1078. Writing relocatable modules in Pascal
  1079. =====================================
  1080.  
  1081. To write a module using Pascal you will need to use the CMHG tool
  1082. provided with ANSI C Release 4. This tool construct module entry
  1083. veneers for C or Pascal code (or any APCS-R conformant code). The
  1084. CMHG tool is documented in the chapter "How to write relocatable
  1085. modules in C" in the ANSI C manual.
  1086.  
  1087. Pascal code to be included in a module must be compiled with the
  1088. Module option enabled (-zm from the command line).
  1089.  
  1090. Procedures or function which are referenced by the CMHG veneers must
  1091. be declared extern.
  1092.  
  1093. Pascal code to be included in a module must be linked with the library
  1094. 'pmodlib' instead of the library 'plib'. This library may be found in
  1095. <!Pascal>.o. The code must also be linked with the shared C library stubs
  1096. rather than the unshared ANSILib.
  1097.  
  1098. The CMHG entry veneers and Pascal declarations are given below. Note
  1099. that each Pascal procedure function requires a declaration and a
  1100. definition, just like a forward declaration in standard Pascal but
  1101. with the keyword 'extern' substituted for 'forward'.
  1102.  
  1103. type _kernel_swi_regs = array[0..9] of integer;
  1104.  
  1105. Run entry
  1106. ---------
  1107.  
  1108. module-is-runnable:
  1109.  
  1110. No pascal declaration. The run entry of the module will call the
  1111. mainline of you Pascal program. The arguments 'argc' and 'argv' may be
  1112. accessed through the library functions 'argc' and 'argv'.
  1113.  
  1114. Initialisation entry
  1115. --------------------
  1116.  
  1117. initialisation-code: user_init
  1118.  
  1119. function user_init(cmd_tail : string;
  1120.                    podule_base : integer;
  1121.                    pw : pointer) : error; extern;
  1122.  
  1123. Finalisation entry
  1124. ------------------
  1125.  
  1126. Finalisation entries are handled by registering a function with the C
  1127. library function 'atexit'. The registed function is called when the
  1128. module dies. The declarations for 'atexit' and the exit handler are as
  1129. follows:
  1130.  
  1131. Type atexit_handler = ^procedure exit_handler;
  1132.  
  1133. function atexit(exit_handler : atexit_handler) : integer; extern;
  1134.  
  1135. procedure exit_handler;
  1136.  
  1137. ...
  1138.  
  1139. Service calls
  1140. -------------
  1141.  
  1142. service-call-handler: sc_handler <number> <number> ...
  1143.  
  1144. procedure sc_handler(service_number : integer;
  1145.                      var r : _kernel_swi_regs;
  1146.                      pw : pointer); extern;
  1147.  
  1148. Help and command entries
  1149. ------------------------
  1150.  
  1151. command-keyword-table: cmd_handler <command-description>
  1152.  
  1153. function cmd_handler(arg_string : string;
  1154.                      argc : integer;
  1155.                      cmd_no : integer;
  1156.                      pw : pointer) : error; extern;
  1157.  
  1158. SWI handler
  1159. -----------
  1160.  
  1161. swi-handler-code: swi_handler
  1162.  
  1163. function swi_handler(swi_no : integer;
  1164.                      var r : _kernel_swi_regs;
  1165.                      pw : pointer) : error; extern;
  1166.  
  1167. SWI decoding code
  1168. -----------------
  1169.  
  1170. swi-decoding-code: swi_decoder
  1171.  
  1172. procedure swi_decode(var r : _kernel_swi_regs;
  1173.                      pw : pointer); extern;
  1174.  
  1175. IRQ handlers
  1176. ------------
  1177.  
  1178. irq-handlers: entry_name/handler_name
  1179.  
  1180. procedure entry_name; extern;
  1181.  
  1182. function handler_name(var r : _kernel_swi_regs;
  1183.                       pw : p[ointer); extern;
  1184.