The kc compiler
The kc utility is used to compile KCML programs into the KCML7 compiled form. It is the KCML7 equivalent of the kc6 utility used to build KCML libraries. The KCML6 interpreted mode allowed programs to be compiled one statement at a time with many decisions postponed to run time. While KCML7 also supports this mode of operation, a native compilation compiles while libraries and programs allowing much of the runtime checking to be done at compile time. To do this the compiler needs visibility of all the libraries that might be referenced by the target program or library so that it can check that functions exist and can check the arguments passed. Because it takes a more global approach the compiler can catch many bugs that would be hard to find in a KCML6 environment. It also allows many extensions to the language such as DEFCLASS.
The kc utility is normally executed by the KMake utility, so is not fully documented here. You are strongly recommended to use kmake rather than kc to build your libraries as it will only build the minimum necessary and will take account of cross dependencies.
Besides its primary role of compilation, the utility can also be used to generate cross referenced help files from embedded documentation in the source files and can generate a file of prototypes (see PROTOTYPE).
kc command line switches
kc [-6][-a file][-d dir] [-e file] [-f flag] [-i import] [-l file] [-o library] [-p file] [-r file] [-s] [-v] [-x] [-y file] [-z err sev] prog1 [prog2 ...]
Note that there must be at least one component source program specified. A status report is written to standard output. Any fatal errors are reported to standard error and an exit code is set.
Switches
Some of these switches are useful only to kmake.
Switch | Purpose |
---|---|
-6 | Only recognize KCML6 keywords. |
-a file | Generate prototypes. See PROTOTYPE. |
-d dir | Destination dir. Only used for help files. |
-e file | Generate export library. Used by kmake. |
-f flag | Specify compiler flag. This may be repeated. |
-i import | Specify another library that this library depends upon. The library must already exist and will be loaded before the library is resolved and saved thus allowing constants and fields to be given their correct values. This switch is optional and there can be more than one instance in which case the imported libraries will be loaded in the order specified. A list of these libraries is saved in the header of the new library. |
-l file | Specify log file |
-o library | This is an optional switch that specifies the filename of the library to be created. If missing the base name of the first source file will be used with the extension changed to .kbin. |
-p file | Partial build. Used by kmake. |
-r file | Generate a reference library. Used by kmake. |
-s | Operate silently, otherwise it will emit progress reports to standard output as it loads each component |
-v | List variables. |
-x | Ignore COM declarations. |
-y file | Display library |
-z err sev | Set error severity |
-? | Produce a usage message on standard output |
Errors
Errors have unique numbers and are classified into different degrees of severity by a prefix code. A list of the error types may be found here.
A full list of compilation errors sorted by number is to be found here.
Suppressing Errors
Errors can be suppressed in code using a special comment syntax giving the error number. The comment must be immediately prior to or on the end of the line containing the error.
// #[suppress(109)] PRINT foo PRINT foo // #[suppress(109)] // Multiple errors can be suppressed PRINT foo // #[suppress(109,627)]
Spelling
The kc compiler will check the spelling of the first string of any chevroned string and generate a NOTE for any unrecognised words. For this the Spell Checking library and dictionary need to be installed.Exit codes
When kc terminates it indicates success or failure by setting an exit code which can be tested as the return value of SHELL. There are predefined KCML constants for these:
Constant name | Value | Meaning |
---|---|---|
_KMAKE_RETURN_SUCCESS | 0 | Build succeeded without errors or warnings |
_KMAKE_RETURN_WARNING | 1 | Build succeeded butb there were one or more warnings |
_KMAKE_RETURN_ERROR | 2 | Build failed and no code was generated due to a fatal error |
_KMAKE_RETURN_FATAL | 3 | Build failed and no code was generated due to a external causes such as being unable to open a file |
More details about any error can be found from the error message written to standard error and the context can be found from the status report sent to standard output. Build errors are listed here.