MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ rewrite()

RewriteOperator::RewriteResult MayaFlux::Nodes::Network::RewriteOperator::rewrite ( uint64_t steps = 1,
std::span< const double > inputs = {} )
nodiscard

Rewrite the draft word on the producer lane, without submitting it.

Definition at line 232 of file RewriteOperator.cpp.

233{
234 if (!m_valid) {
236 }
237 if (steps > m_max_generations - m_draft->generation) {
239 }
240 if (steps == 0) {
242 }
243
244 try {
246 const std::shared_ptr<const void> held = m_hold ? m_hold() : nullptr;
247 auto current = m_draft;
248
249 for (uint64_t step = 0; step < steps; ++step) {
250 const auto& [symbols, generation] = *current;
251 std::vector<Symbol> next_symbols;
252 next_symbols.reserve(std::min(m_max_word_length, symbols.size()));
253 bool overflow {};
254
255 const EmitSymbol emit = [this, &next_symbols, &overflow](Symbol next) {
256 if (next.arity > max_symbol_parameters || next_symbols.size() >= m_max_word_length) {
257 overflow = true;
258 return false;
259 }
260 next_symbols.push_back(next);
261 return true;
262 };
263
264 for (size_t position = 0; position < symbols.size(); ++position) {
265 const auto& symbol = symbols[position];
266 const Environment environment {
267 .inputs = inputs,
268 .word = symbols,
269 .position = position,
270 .held = held.get(),
271 .held_tag = m_held_tag
272 };
273
274 if (const auto* replacement = select_replacement(symbol, environment)) {
275 replacement->successor(symbol, environment, emit);
276 } else {
277 emit(symbol);
278 }
279
280 if (overflow) {
282 "RewriteOperator generation exceeds max_word_length or symbol parameter limit");
284 }
285 }
286
287 current = std::make_shared<const Word>(Word {
288 .symbols = std::move(next_symbols),
289 .generation = generation + 1 });
290 }
291
292 m_draft = std::move(current);
294
295 } catch (const std::exception& exception) {
296
298 "RewriteOperator replacement failed: {}", exception.what());
299 } catch (...) {
300
302 "RewriteOperator replacement failed with an unknown exception");
303 }
304
306}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
void refresh_controls()
Read node sources into their controls.
std::function< bool(Symbol)> EmitSymbol
Append a symbol; false on a bound violation.
std::function< std::shared_ptr< const void >()> m_hold
const Replacement * select_replacement(const Symbol &symbol, const Environment &environment)
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager).
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
What a replacement sees: the caller's inputs, the word with the symbol's position in it,...

References GENERATION_LIMIT, INVALID_CONFIG, m_draft, m_held_tag, m_hold, m_max_generations, m_max_word_length, m_valid, max_symbol_parameters, MF_ERROR, MF_WARN, MayaFlux::Journal::NodeProcessing, MayaFlux::Journal::Nodes, MayaFlux::Nodes::Network::NetworkOperator::refresh_controls(), REPLACEMENT_FAILED, rewrite(), REWRITTEN, select_replacement(), and WORD_LIMIT.

Referenced by grow(), and rewrite().

Here is the call graph for this function:
Here is the caller graph for this function: