MAINSAIL Compiler User's Guide, Chapter 9

previous   next   top   contents   index   framed top   this page unframed


9. Invoking the Compiler from a Program

To invoke the compiler from a program, allocate a new data section for the MODULE COMPIL (of interface CLASS $compil, with $programInterface set) and call the PROCEDURE $compile in the allocated data section (see Figure 9–1); e.g.:

POINTER($compilp;
...
p := new("COMPIL",$programInterface);
...
IF p.$compile(...) THEN ...

The data section may be disposed when all compilations have been completed:

dispose(p);

Figure 9–1. $compile
BOOLEAN
PROCEDURE   $compile    (OPTIONAL STRING cmds;
                         
OPTIONAL POINTER(textFilef);

cmds is a STRING that contains exactly what would be typed to the compiler had it been invoked by the user from the terminal (cmds may contain embedded eols). If cmds is the empty STRING, or when cmds is exhausted, subsequent lines of input are read from f if f is not NULLPOINTER. If cmds is empty and f is NULLPOINTER the compiler enters into its user dialogue (on cmdFile and logFile) as usual. The result is TRUE if no errors were detected (in the last compilation), else FALSE. The compiler prompts are suppressed when the compiler is invoked from $compile. However, logging information (as shown by the LOG subcommand) and error messages are still written to logFile unless redirected or suppressed by the appropriate compiler subcommands in cmds. Interactive define responses are read from cmdFile, not from cmds or f (except when the subcommand CMDLINE is in effect).

When cmds and f are exhausted, $compile acts as if it had read an eol from the input. If the commands in cmds and f terminate the compilation session before cmds and f are exhausted, the unprocessed input is ignored.

Subcommands within cmds should be spelled in full for compatibility with future releases of MAINSAIL (to avoid ambiguities with newly introduced subcommands in future releases; no guarantee is made, however, that individual subcommands will be supported from release to release).

For example, to compile the files foo.msl and baz.msl NOCHECK and add them to the library s.lib:

p.$compile(
    "
foo.msl," & eol &   # "," means enter subcommand mode
        "
library s.lib" & eol &
        "
nocheck" & eol &
        
eol &            # exit subcommand mode
    "
baz.msl" & eol);

previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Compiler User's Guide, Chapter 9