yeslogic/doodle

[lang-model] `Format::AccumUntil` for fused fold-and-repeat operations

Closed this issue · 0 comments

Format::AccumUntil(
    Expr, // @ Lambda :: { ( Acc, [Elem] ) -> Bool }
    Expr, // @ Lambda :: { ( Acc, Elem ) -> Acc },
    Expr, // @ _ :: { Acc }
    ValueType, // Acc
    Box<Format>, // @ _ :: { Elem }
) // :: (Acc, [Elem])

This would solve the following (non-issue) problems:

  • For the variable-length array flags in glyf table simple descriptions, the condition to stop repeating is "sum over a given projected field of the record being repeated == final element of end_points_of_contours array". This is currently inefficient to define given our existing vocabulary, as while we have Expr::LeftFold and Format::RepeatUntilSeq, we have no way of preserving the sum over the first N elements to add the N+1 repetition to to avoid quadratic cost for a linear computation.
  • This is useful for capturing the we_have_instructions flag within the loop over composite glyph components, and could even allow us to use a single primitive for both this issue, and simple glyph termination predicates in O(N) time.