3.16. kink/PROGRAM

Operations on kink programs.

3.16.1. PROGRAM.compile(Program_text ...[$config = {})]

Compiles the Program_text. If the compilation succeeds, the fun continues to $on_success_handler handler with the compiled top level function. The fun takes an env as the top level env, and evaluates the program. If the compilation fails with a compile error, the fun continues to $on_error_handler handler with the message, the loc of the start of the error, and the loc of the end of the error.

$config is called with a Conf val, to configure the compilation. Conf val has the following configurer methods.

Conf.lang(Lang): configures the language tag used to create error messages. The default is 'und'.

Conf.name(Program_name): configures the name of the program. The default is '(compile)'.

Conf.on_success($on_success_handler): configures $on_success_handler. The default is CORE.id.

Conf.on_error($on_error_handler): configures $on_error_handler. The default handler raises an exception representing the compile error.


:fun <- PROGRAM.compile('10 + 20'){(:C)
  C.on_error{(:Msg :Start_loc :End_loc)
    raise('unexpected compile error: {}'.format(Msg))
stdout.print_line(fun(ENV.new))  # => 30

3.16.2. PROGRAM.compile_error_desc(Msg Start End)

Returns a typical description of a compile error.

Msg must a message str, Start must be the start loc of the compile error, and End must be the end loc of the compile error.

A typical result is: "compile error: unexpected token: [foo.kn L1 C6] 10 + -->+ 20"