mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-14 13:35:00 +01:00
fix set_n pass
This commit is contained in:
parent
7973d9f77b
commit
d9f163ef3a
4 changed files with 11 additions and 11 deletions
|
|
@ -1,4 +0,0 @@
|
|||
>+++++[-]++++++++++[[-->+++++++++>+++++++++>+++++++++<<<<->]]>.>.>.
|
||||
<[-]<[-]<[-]
|
||||
>>>>+ >>>>> ++++++++++ <<<< <<<<<
|
||||
+[[>>>>]]+[[++--[+++>>]]>.][-]
|
||||
|
|
@ -32,14 +32,12 @@ fn run_bf(bf: &str) {
|
|||
fn optimized(c: &mut Criterion) {
|
||||
let fizzbuzz = include_str!("fizzbuzz.bf");
|
||||
let bench = include_str!("bench.bf");
|
||||
let loopremove = include_str!("loopremove.bf");
|
||||
let twinkle = include_str!("twinkle.bf");
|
||||
let bottles = include_str!("bottles.bf");
|
||||
let hanoi = include_str!("hanoi.bf");
|
||||
|
||||
c.bench_function("fizzbuzz", |b| b.iter(|| run_bf(black_box(fizzbuzz))));
|
||||
c.bench_function("bench", |b| b.iter(|| run_bf(black_box(bench))));
|
||||
c.bench_function("loopremove", |b| b.iter(|| run_bf(black_box(loopremove))));
|
||||
c.bench_function("twinkle", |b| b.iter(|| run_bf(black_box(twinkle))));
|
||||
c.bench_function("bottles", |b| b.iter(|| run_bf(black_box(bottles))));
|
||||
c.bench_function("hanoi", |b| b.iter(|| run_bf(black_box(hanoi))));
|
||||
|
|
|
|||
|
|
@ -154,8 +154,16 @@ fn pass_find_set_null(ir: &mut Ir<'_>) {
|
|||
/// pass that replaces `SetNull Add(5)` with `SetN(5)`
|
||||
fn pass_set_n(ir: &mut Ir<'_>) {
|
||||
let stmts = &mut ir.stmts;
|
||||
let mut i = 0;
|
||||
while i < stmts.len() - 1 {
|
||||
for i in 0..stmts.len() {
|
||||
let a = &mut stmts[i];
|
||||
if let StmtKind::Loop(body) = &mut a.kind {
|
||||
pass_set_n(body);
|
||||
}
|
||||
|
||||
if i >= stmts.len() - 1 {
|
||||
break; // we are the last element
|
||||
}
|
||||
|
||||
let a = &stmts[i];
|
||||
if let StmtKind::SetNull = a.kind() {
|
||||
let b = &stmts[i + 1];
|
||||
|
|
@ -163,7 +171,6 @@ fn pass_set_n(ir: &mut Ir<'_>) {
|
|||
StmtKind::Add(n) => StmtKind::SetN(*n),
|
||||
StmtKind::Sub(n) => StmtKind::SetN(0u8.wrapping_sub(*n)),
|
||||
_ => {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
@ -171,6 +178,5 @@ fn pass_set_n(ir: &mut Ir<'_>) {
|
|||
stmts.remove(i + 1);
|
||||
stmts[i] = Stmt::new(new, span);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
|
||||
[>[-]+++++++++++++++++++++++++[>[-]++++++[-]<-]<-]
|
||||
Loading…
Add table
Add a link
Reference in a new issue