Muex.Compiler (Muex v0.6.1)

View Source

Compiles mutated ASTs and manages module hot-swapping.

Uses the language adapter for converting AST to source and compiling modules.

Summary

Functions

Compiles a mutated AST and loads it into the BEAM.

Compiles a mutated AST and writes it to a temporary file.

Generates the mutated source code string without writing to disk.

Restores the original module from its binary.

Functions

compile(mutation, original_ast, module_name, language_adapter)

@spec compile(map(), term(), atom(), module()) ::
  {:ok, {module(), binary()}} | {:error, term()}

Compiles a mutated AST and loads it into the BEAM.

Parameters

  • mutation - The mutation map containing the mutated AST
  • original_ast - The original (complete) AST with mutation applied
  • module_name - The module name to compile
  • language_adapter - The language adapter module

Returns

  • {:ok, {module, original_binary}} - Successfully compiled and loaded module with original binary
  • {:error, reason} - Compilation failed

compile_to_file(mutation, file_entry, language_adapter)

@spec compile_to_file(map(), map(), module()) :: {:ok, Path.t()} | {:error, term()}

Compiles a mutated AST and writes it to a temporary file.

This is used for port-based test execution where the mutated source needs to be on disk for a separate BEAM VM to compile.

Parameters

  • mutation - The mutation map containing the mutated AST
  • file_entry - The file entry containing the original AST and path
  • language_adapter - The language adapter module

Returns

  • {:ok, temp_file_path} - Successfully wrote mutated source to temp file
  • {:error, reason} - Failed to write mutated source

compile_to_source(mutation, file_entry, language_adapter)

@spec compile_to_source(map(), map(), module()) ::
  {:ok, String.t()} | {:error, term()}

Generates the mutated source code string without writing to disk.

This is preferred over compile_to_file/3 when the caller only needs the source string (e.g. to write into a sandbox).

Returns

  • {:ok, source_string} - The mutated source code
  • {:error, reason} - AST-to-source conversion failed

restore(module_name, original_binary)

@spec restore(atom(), binary()) :: :ok | {:error, term()}

Restores the original module from its binary.

Parameters

  • module_name - The module to restore
  • original_binary - The original module binary

Returns

  • :ok - Successfully restored
  • {:error, reason} - Restoration failed