Module gmegabuf

Module gmegabuf 

Source
Expand description

gmegabuf / megabuf write rewrite for the preprocess pipeline.

evalexpr rejects assignments whose LHS is a function call, but MD2 presets commonly write gmegabuf(idx) = val and the compound forms += / -= / *= / /=. This module rewrites them to a two-argument gmegabuf_set(idx, val) call shape that the math-function registry understands.

Functions§

detect_assignment_op 🔒
Detect an assignment operator starting at byte offset pos in bytes. Returns Some((Some(op_char), after_eq)) for compound assignments (+=, -=, *=, /=), Some((None, after_eq)) for plain =, or None if no recognised assignment op (or == / other comparison) starts here.
find_assignment_value_end 🔒
Find the byte offset where an assignment’s RHS value ends. Walks forward through bytes starting at offset, tracking paren balance. Stops at the first ; or , at depth 0, an unmatched ) (the assignment lives inside an enclosing call), or end-of-buffer.
match_megabuf_name 🔒
Match gmegabuf or megabuf starting at byte offset pos. Returns the matched name slice and the byte just past it, or None if no match.
rewrite_gmegabuf_writes 🔒
Rewrite gmegabuf(<idx>) = <val> (and megabuf) into gmegabuf_set(<idx>, <val>). evalexpr’s = operator rejects a function-call LHS with a confusing “Expected String, got Float” error, which cascades across the rest of the equation. The two-arg call shape is well-formed; gmegabuf_set / megabuf_set are registered as buffer-backed functions in math_functions.rs.