Zig Compiler Notes


Tags: None
State: None

Tokenizer

Token = (tag, pos)

  • State machine
  • Token-by-token, not stored in memory

Parser

AST Node = (tag, main_token, data)

tag = type of node main_token = index in token data = (lhs, rhs)

Example:

func decl, has:

  • func name
  • param list
  • return type
  • body, etc.

lhs == function prototype node rhs == function body

lhs, rhs points to either nodes or extradata in the parser

extradata == array of Index how many fields = defined by tag

for prototype it's 6 fields, defined as a struct: (start/end of params, alignexpr, addrspaceexpr, sectionexpr, callconvexpr)

Backend

  1. main.zig
    1. buildOutputType
    2. Compilation object created
  2. ZIR is first generated

Compiler.zig

binfile: link.File

--watch command

Sources:

  1. Entry
  2. Update
    1. comp.makeBinFileWritable
    2. updateModule
      1. comp.update