• Kipper Compiler

    The Kipper Compiler is a TypeScript-based compiler that can compile Kipper code into TypeScript and generate the required overhead for the Kipper program. (In the future, native JavaScript should be supported as well. See #32 for more information.)

    Kipper API

    Kipper provides a TypeScript API for interacting with its compiler, which can be used to configure and inspect the compilation of a program. This API is per default shipped with the @kipper/core package and the kipper-standalone.js file.

    Configuring the Kipper Compiler

    Configuring KipperCompile.compile() can be done using the CompileConfig interface, which defines all available parameters for a compilation.

    Kipper Compiler Parameters

    Parameter Type
    Description
    fileName string The name of the file. Per default anonymous-script.
    target KipperTarget The Kipper target instance, which defines the translation behaviour of the Kipper AST nodes. Per default TypeScriptTarget.
    optimisationOptions OptimisationOptions

    The options for optimising the Kipper output.

    Defaults to an object with the following values:

    • optimiseInternals: true
    • optimiseBuiltIns: false

    More info down below in Kipper Optimiser Parameters.

    extendBuiltIns Array<BuiltInFunction> Additional built-in functions that should be available in the Kipper program. This extends builtIns and is per default empty.
    builtIns
    Array<BuiltInFunction> Standard built-in functions that should be available in the Kipper program.

    If this is defined with new built-in functions that Kipper does not implement per default, the Kipper target class will have to be updated as well to implement the generation of these built-ins.

    Defaults to the function as listed in Built-in Functions.

    Kipper Optimiser Parameters

    Parameter Type Description
    optimiseInternals boolean If set to true, the internal functions (functions generated by the Kipper compiler to provide specific functionality) of the compiled code will be optimised using tree-shaking reducing the size of the output. Defaults to true.
    optimiseBuiltIns boolean If set to true, the built-in functions of the compiled code will be optimised using tree-shaking reducing the size of the output. Defaults to false.

    Example Configuration

    import { KipperCompiler } from "@kipper/core";
    import { TypeScriptTarget } from "@kipper/core/lib/targets/typescript";
    
    const compiler = new KipperCompiler();
    const result = compiler.compile(
        kipperCode, // A string or a KipperParseStream containing the source code
        {
            fileName: "myProgram.kip",
            target: new TypeScriptTarget(),
            optimisationOptions: {
                optimiseInternals: true, // Removes any unused internal function
                optimiseBuiltIns: true, // Removes any unused built-in function
            },
        },
    );
    Kipper

    Kipper CLI Parameters

    Parameters for the Kipper Compiler CLI in the console.

    Flags Description
    -b, --[no-]optimise-builtins
    If set to true, the built-in functions of the compiled code will be optimised using tree-shaking reducing the size of the output.
    -e, --encoding=encoding The encoding that should be used to read the file (ascii,utf8,utf16le). Defaults to utf8.
    -i, --[no-]optimise-internals If set to true, the internal functions of the compiled code will be optimised using tree-shaking reducing the size of the output.
    -o, --output-dir=output-dir The build directory where the compiled files should be placed. If the path does not exist, it will be created. Defaults to build.
    -s, --string-code=string-code
    The content of a Kipper file that can be passed as a replacement for the 'file' parameter.

    Example CLI Command

    kipper compile -s 'call print("Hello world!");' -e utf16le -i -b
    Bash