inflate L2 tests passing, fix TupleEnd stack history cleaning

This commit is contained in:
Breval Ferrari 2024-10-14 11:31:57 -04:00
parent 66b42e2aa0
commit c7c1fb19e2
No known key found for this signature in database
GPG key ID: 6FED68D87C479A59
2 changed files with 75 additions and 1 deletions

View file

@ -112,7 +112,10 @@ fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
}
.last_mut()
.unwrap()
.push(Atom::Tuple(popped))
.push({
stack_history.pop();
Atom::Tuple(popped)
})
} else {
result.push(Atom::Tuple(popped))
}

View file

@ -83,4 +83,75 @@ mod inflate {
])
)
}
#[test]
fn inflate_loop_l2() {
assert_eq!(
vec![Atom::Loop(
unsafe { NonZeroU8::new_unchecked(2) },
vec![Atom::Loop(
unsafe { NonZeroU8::new_unchecked(3) },
vec![Atom::Note(2), Atom::Note(3)]
)]
)],
inflate(vec![
FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(2) }),
FlatAtom::LoopStarts(unsafe { NonZeroU8::new_unchecked(3) }),
FlatAtom::Note(2),
FlatAtom::Note(3),
FlatAtom::LoopEnds,
FlatAtom::LoopEnds
])
)
}
#[test]
fn inflate_tuple_l2() {
assert_eq!(
vec![Atom::Tuple(vec![Atom::Tuple(vec![
Atom::Note(2),
Atom::Note(3)
])])],
inflate(vec![
FlatAtom::TupleStarts,
FlatAtom::TupleStarts,
FlatAtom::Note(2),
FlatAtom::Note(3),
FlatAtom::TupleEnds,
FlatAtom::TupleEnds
])
)
}
#[test]
fn inflate_slope_l2() {
let instruction = || {
let parser = fasteval::Parser::new();
let mut slab = fasteval::Slab::new();
parser
.parse(FASTEVAL_INSTRUCTION, &mut slab.ps)
.unwrap()
.from(&slab.ps)
.compile(&slab.ps, &mut slab.cs)
};
assert_eq!(
vec![Atom::Slope(
SlopeModifier::Note,
instruction(),
vec![Atom::Slope(
SlopeModifier::Note,
instruction(),
vec![Atom::Note(2), Atom::Note(3)]
)]
)],
inflate(vec![
FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()),
FlatAtom::SlopeStarts(SlopeModifier::Note, instruction()),
FlatAtom::Note(2),
FlatAtom::Note(3),
FlatAtom::SlopeEnds,
FlatAtom::SlopeEnds
])
)
}
}