Module joiner

Module joiner 

Source
Expand description

Multi-equation join logic and top-level call interceptors.

Two concerns sit here:

  1. MilkEvaluator::eval_equation_list — paren-balance-aware join over a .milk preset’s flat equation list. Consecutive equations that aren’t paren-balanced (or end on a dangling binary operator, or look like a continuation of the previous line) get glued with ; before evaluation.
  2. MilkEvaluator::eval_processed_with_loops — top-level interceptor for loop(N, body), exec2, exec3, and while(body). evalexpr can’t express these EEL2 idioms natively (their bodies are ;-chains inside what looks like a function-call arg list), so we strip the call boundary and walk the body ourselves.

Structs§

EvaluationStats
Aggregate stats returned by MilkEvaluator::eval_equation_list.

Functions§

body_has_nested_loop 🔒
true if s contains an EEL2 control-flow builtin name (loop, while, exec2, exec3) as an identifier. Used as a cheap conservative guard before the pre-compile-the-body optimisation in the loop(N, body) interceptor: when the body has a nested loop/while/exec, replaying it as a single Node would bypass the interceptor’s recursive descent and break those semantics, so we fall back to the slow path.
contains_top_level_assignment 🔒
true if s contains a top-level single = (assignment), as opposed to == / <= / >= / != / += / -= / *= / /= / %=.
ends_with_dangling_binop 🔒
find_top_level_comma 🔒
Locate the first top-level , in bytes. Returns the byte offset or None if every comma is enclosed by parens.
find_top_level_exec_call 🔒
Find a top-level exec2(a, b) or exec3(a, b, c).
find_top_level_loop_call 🔒
Locate a top-level loop(<n_expr>, <body>) call in s. Returns (before, n_expr, body, after) slices into s, or None if no well-formed top-level loop exists.
find_top_level_named_call 🔒
Locate a top-level call name(a, b, …) and split it into (before, args, after). Returns None if no qualifying call exists at depth 0.
find_top_level_semi 🔒
Fallback splitter for loop(N; body)-shaped corpus typos.
find_top_level_while_call 🔒
Find a top-level while(body). Single-pass evaluation (see module-level docs).
next_eq_is_continuation 🔒
Return true when the next non-empty equation after idx looks like a continuation of the current buffer rather than a fresh statement, so the buffer flush should be deferred until it’s been appended.
paren_balance 🔒
Count () across s. Byte-accurate for ASCII and conservative for UTF-8 (multibyte chars never collide with the paren ASCII codepoints).
sanitize_joined_block 🔒
Collapse junk-separator pairs that the join step can produce when an equation closes a multi-line block. ;) and ;, are never valid in evalexpr’s grammar and are always artifacts of our ;-join over a previously-truncated equation that ended with ,/(.
starts_with_binop 🔒
Return true when the first non-whitespace byte of s is a binary operator with no unary form (*, /, %). Leading +/- is excluded because they’re also legitimate unary signs on a fresh statement.
starts_with_open_paren 🔒
true when s starts with (, indicating a function call whose name and arg list were split across .milk lines.
starts_with_plus_minus_orphan 🔒
Return true when the first non-whitespace byte of s is + or - AND s contains no top-level assignment = (single =, not == or a compound op). Corpus authors split a single arithmetic expression across per_pixel_N= lines whose continuation starts with +/-:
starts_with_split_assignment 🔒
true when s starts with = (single, not ==), indicating the previous equation’s tail is the LHS of an assignment split across .milk lines.