Skip to content

Commit

Permalink
add some but/with tests and fix with
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 20, 2024
1 parent fbcbee3 commit f532e39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
31 changes: 15 additions & 16 deletions src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand Down
7 changes: 5 additions & 2 deletions tests/units.ua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f532e39

Please sign in to comment.