From ffcc6a647cab20c15b42e53479666acb9cd9dcbc Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Sun, 23 Jun 2024 00:41:38 -0700 Subject: [PATCH] make un repeat require a count inside --- changelog.md | 2 ++ src/algorithm/invert.rs | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index 1f4df0fe..9666940f 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,8 @@ This version is not yet released. If you are reading this on the website, then t - [`join ⊂`](https://uiua.org/docs/join) will rank differences greater than 1 can now extend the smaller array - [`un °`](https://uiua.org/docs/un) [`join ⊂`](https://uiua.org/docs/join) is now easier to combine with other inverses - [`repeat ⍥`](https://uiua.org/docs/repeat) can now repeat a negative number of times, which will repeat the inverse +- [`un °`](https://uiua.org/docs/un) [`repeat ⍥`](https://uiua.org/docs/repeat) now requires the repetition count to be inside the [`un °`](https://uiua.org/docs/un) function + - This makes the inverted signature correct - [`inventory ⍚`](https://uiua.org/docs/inventory) no longer does [`each ∵`](https://uiua.org/docs/each)-like behavior - This got in the way more than it helped - Add the experimental [`triangle ◹`](https://uiua.org/docs/triangle) modifier, which calls a function on shrinking suffixes of an array's rows diff --git a/src/algorithm/invert.rs b/src/algorithm/invert.rs index 1d310269..a473e2bf 100644 --- a/src/algorithm/invert.rs +++ b/src/algorithm/invert.rs @@ -2125,22 +2125,23 @@ fn invert_repeat_pattern<'a>( input: &'a [Instr], comp: &mut Compiler, ) -> Option<(&'a [Instr], EcoVec)> { + let (input, mut instrs) = Val.invert_extract(input, comp)?; match input { [Instr::PushFunc(f), repeat @ Instr::Prim(Primitive::Repeat, span), input @ ..] => { - let instrs = f.instrs(&comp.asm).to_vec(); - let inverse = invert_instrs(&instrs, comp)?; - let inverse = make_fn(inverse, *span, comp)?; + let f_instrs = f.instrs(&comp.asm).to_vec(); + let inverse = invert_instrs(&f_instrs, comp)?; + instrs.extend(inverse); + let inverse = make_fn(instrs, *span, comp)?; Some((input, eco_vec![Instr::PushFunc(inverse), repeat.clone()])) } - [Instr::PushFunc(inv), Instr::PushFunc(f), Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, span), input @ ..] => { - Some(( - input, - eco_vec![ - Instr::PushFunc(f.clone()), - Instr::PushFunc(inv.clone()), - Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, *span), - ], - )) + [Instr::PushFunc(inv), Instr::PushFunc(f), Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, span), input @ ..] => + { + instrs.extend([ + Instr::PushFunc(f.clone()), + Instr::PushFunc(inv.clone()), + Instr::ImplPrim(ImplPrimitive::RepeatWithInverse, *span), + ]); + Some((input, instrs)) } _ => None, }