Central Docs
Catálogo Inicio

External MIR

External MIR is a line-oriented program whose first token selects a RIF Rule. For example, if the target defines mov:

mov rax, 1
add rbx, 2

The remaining tokens on each line are consumed by the selected Rule. A line that leaves unconsumed tokens is rejected.

Command Line

The command-line entrypoint is rif.py:

rif main.rif program.asm
rif main.pack program.asm
rif main.rif program.asm -o build/program.bin

The MIR extension must match .ext in the target's linker block. When -o is omitted, the output path is the MIR path with a .bin suffix.

Direct Python API

Use the direct source API when RIF should tokenize a string:

from MIR import compile_mir_source

result = compile_mir_source("main.rif", "mov rax\n")
binary = result.binary

Prepare a target once when compiling multiple inputs:

from MIR import compile_mir_source, prepare_target

target = prepare_target("main.pack")
first = compile_mir_source(target, "mov rax\n")
second = compile_mir_source(target, "add rbx\n")

Use compile_mir_file for a file and compile_mir_tokens when another compiler already has a token stream:

from MIR import compile_mir_file, compile_mir_tokens, tokenize_mir

result = compile_mir_file("main.rif", "program.asm")
tokens = tokenize_mir("mov rax\n", "generated.asm")
result = compile_mir_tokens("main.pack", tokens)

compile_mir_tokens avoids lexing and parsing the MIR a second time. It is the preferred entry when a host compiler already owns tokenization.

Sections

The default output section is .entrysection from @config. A direct caller can select another configured section:

result = compile_mir_source(target, source, section="text")

The returned MIRCompilation exposes binary, image, executions, program, context, section_binary, and the selected section name.

The lower-level pipeline is also public:

from MIR import compile_definition, compile_project, execute_rule

program = compile_definition("main.rif")
project = compile_project("main.rif")
execution = execute_rule(project, "mov", tokens)

parse_source exposes the Gram parse phase, while compile_source returns a resolved target definition without creating an output image. These helpers are useful when a host compiler needs to inspect or execute individual Rules.