From f532e397cdeff6a0dc6534e1ac788eac30286252 Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Thu, 20 Jun 2024 16:44:35 -0700 Subject: [PATCH] add some but/with tests and fix with --- src/compile/modifier.rs | 31 +++++++++++++++---------------- tests/units.ua | 7 +++++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/compile/modifier.rs b/src/compile/modifier.rs index fb3ae34f..a4e6437a 100644 --- a/src/compile/modifier.rs +++ b/src/compile/modifier.rs @@ -592,24 +592,23 @@ impl Compiler { Signature::new(sig.args.max(1), sig.outputs + 1) } With => { - instrs.insert(0, Instr::copy_inline(span)); - if sig.outputs < 2 { - instrs.push(Instr::TouchStack { count: 2, span }); - sig.outputs = 2; + let mut prefix = EcoVec::new(); + if sig.args < 2 { + prefix.push(Instr::TouchStack { count: 2, span }); + sig.args = 2; } - instrs.push(Instr::pop_inline(span)); - instrs.push(Instr::Prim(Flip, span)); - if sig.outputs >= 2 { - for _ in 0..sig.outputs - 1 { - instrs.push(Instr::push_inline(span)); - instrs.push(Instr::Prim(Flip, span)); - } - instrs.push(Instr::PopTemp { - stack: TempStack::Inline, - count: sig.outputs - 1, - span, - }); + prefix.push(Instr::Prim(Dup, span)); + for _ in 0..sig.args - 1 { + prefix.push(Instr::push_inline(span)); + prefix.push(Instr::Prim(Flip, span)); } + prefix.push(Instr::PopTemp { + stack: TempStack::Inline, + count: sig.args - 1, + span, + }); + prefix.extend(instrs); + instrs = prefix; Signature::new(sig.args.max(1), sig.outputs + 1) } _ => unreachable!(), diff --git a/tests/units.ua b/tests/units.ua index 2e208acc..c208c9b4 100644 --- a/tests/units.ua +++ b/tests/units.ua @@ -620,12 +620,15 @@ repr[{[[1 2][2 3]][3 4]}{[[1 2][2 3]]□{[[1 2][2 3]]□□[3 4]}}] ⍤⟜≍: [1 3 2] °(°[⊙⊙∘]⊏0_2_1) 1 2 3 # But -⍤⟜≍: [3 ¯3] [⤙¯ 3] +⍤⟜≍: [5 ¯3 5] [⤙¯ 3 5] +⍤⟜≍: [3 5 ¯3 5] [⟜⤙¯ 3 5] ⍤⟜≍: [5 8] [⤙+ 3 5] ⍤⟜≍: [4 1 2 3 4] [⤙⊙⊙⊙∘ 1 2 3 4] ⍤⟜≍: [4 1 2 3] [⤙⊙⊙⊙◌ 1 2 3 4] -⍤⟜≍: [¯3 3] [⤚¯ 3] +# With +⍤⟜≍: [¯3 5 3] [⤚¯ 3 5] +⍤⟜≍: [¯3 5 3 5] [⊸⤚¯ 3 5] ⍤⟜≍: [8 3] [⤚+ 3 5] ⍤⟜≍: [1 2 3 4 1] [⤚⊙⊙⊙∘ 1 2 3 4] ⍤⟜≍: [2 3 4 1] [⤚⋅⊙⊙∘ 1 2 3 4]