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.

SwitchPurpose
-6Only recognize KCML6 keywords.
-a fileGenerate prototypes. See PROTOTYPE.
-d dirDestination dir. Only used for help files.
-e fileGenerate export library. Used by kmake.
-f flagSpecify compiler flag. This may be repeated.
-i importSpecify 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 fileSpecify log file
-o libraryThis 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 filePartial build. Used by kmake.
-r fileGenerate a reference library. Used by kmake.
-sOperate silently, otherwise it will emit progress reports to standard output as it loads each component
-vList variables.
-xIgnore COM declarations.
-y fileDisplay library
-z err sevSet 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 nameValueMeaning
_KMAKE_RETURN_SUCCESS0Build succeeded without errors or warnings
_KMAKE_RETURN_WARNING1Build succeeded butb there were one or more warnings
_KMAKE_RETURN_ERROR2Build failed and no code was generated due to a fatal error
_KMAKE_RETURN_FATAL3Build 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.