Compilation options

Various named option control how Kawa compiles certain forms.

--module-static

If no module-static is specified, generate a static module (as if (module-static #t) were specified). See Modules and how they are compiled to classes.

--warn-invoke-unknown-method

Emit a warning if the invoke function calls a named method for which there is no matching method in the compile-time type of the receiver. This (currently) defaults to on; to turn it off use the --no-warn-invoke-unknown-method flag.

--warn-undefined-variable

Emit a warning if the code references a variable which is neither in lexical scope nor in the compile-time dynamic (global) environment. This is useful for catching typos. (A define-variable form can be used to silence warnings. It declares to the compiler that a variable is to be resolved dynamically.)

--warn-as-error

Treat a compilation warning as if it were an error and halt compilation.

An option can be followed by a value, as in --warn-invoke-unknown-method=no. For boolean options, the values yes, true, on, or 1 enable the option, while no, false, off, or 0 disable it. You can also negate an option by prefixing it with no-: The option --no-warn-invoke-unknown-method is the same as --warn-invoke-unknown-method=no.

You can set the same options (except, for now, module-static) within your Scheme source file. (In that case they override the options on the command line.)

Syntax: module-compile-options [key: value] ...

This sets the value of the key option to value for the current module (source file). It takes effect as soon it is seen during the first macro-expansion pass, and is active thereafter (unless overridden by with-compile-options).

The key is one of the above option names. (The following colon make it a Kawa keyword.) The value must be a literal value: either a boolean (#t or #f), a number, or a string, depending on the key. (All the options so far are boolean options.)

(module-compile-options warn-undefined-variable: #t)
;; This causes a warning message that y is unknown.
(define (func x) (list x y))

Syntax: with-compile-options [key: value] ... body

Similar to module-compile-options, but the option is only active within body.

(define (func x)
  (with-compile-options warn-invoke-unknown-method: #f
    (invoke x 'size)))