Metaprogramming: Compiler Messages

This is a list of possible messages that one can obtain from the compiler. Note that this is not all the messages. The message struct contains an enum marking the kind of message it is as well as the workspace. Check the kind of message using an if statement, and then cast the message to its appropriate kind of message. More information regarding compiler messages can be found at Compiler.jai

File Message

This message triggers once for each source code file loaded during compilation.

message := compiler_wait_for_message();
if message.kind == .FILE {
  message_file := cast(*Message_File) message;
  print("Loading file '%'.\n", message_file.fully_pathed_filename);

Import Message

This message triggers for each module that is imported. If the “Basic” module is imported 9 times, you only see this message one, since the compiler only imports it once.

message := compiler_wait_for_message();
if message.kind == .IMPORT {
  message_import := cast(*Message_Import) message;
  print("Import module '%'\n", message_import.module_name);

Phase Message

This message triggers each time it advances through the various phases of compiler defined in the Compilation_Phase enum.

message := compiler_wait_for_message();
if message.kind == .PHASE {
  message_phase := cast(*Message_Phase) message;
  print("Entering phase %\n", message_phase.phase);

The phases of the compiler described in the Compilation_Phase enum are:

phase: enum u32 {
  ALL_TARGET_CODE_BUILT         :: 2;
  PRE_WRITE_EXECUTABLE          :: 3;

Typechecked Message

This message triggers any time code has passed typechecking. The code can be inspected, searched for things, modified.

message := compiler_wait_for_message();
if message.kind == .TYPECHECKED {
  message_typechecked := cast(*Message_Typechecked) message;
  print("% declarations have been typechecked\n", message_typechecked.count);
  for message_typechecked.declarations {
    print("Code declaration: %\n", it);

Error Message

This message triggers if an error occurs during compilation

message := compiler_wait_for_message();
if message.kind == .ERROR {
  // handle error

Debug Dump Message

This message triggers if a debug dump occurs

message := compiler_wait_for_message();
if message.kind == .DEBUG_DUMP {
  dump_message := cast(*Message_Debug_Dump) message;
  print("Here is the dump text: %\n", dump_message.dump_text);

Complete Message

This message triggers when compilation is finished.

message := compiler_wait_for_message();
if message.kind == .COMPLETE {
  // do something that breaks out of the compiler message loop.