mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-14 13:35:00 +01:00
rename lir lifetimes
This commit is contained in:
parent
5fc5c49dff
commit
d0718adf7f
4 changed files with 13 additions and 17 deletions
|
|
@ -31,7 +31,7 @@ impl<'hir> Stmt<'hir> {
|
||||||
Self { kind, span }
|
Self { kind, span }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kind(&self) -> &StmtKind<'hir> {
|
pub fn kind(&self) -> &StmtKind<'hir> {
|
||||||
&self.kind
|
&self.kind
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ type Memory = [Wrapping<u8>; MEM_SIZE];
|
||||||
// `repr(C)` to make sure rustc never reorders the fields weirdly
|
// `repr(C)` to make sure rustc never reorders the fields weirdly
|
||||||
// maybe useless, but seems to give tiny wins
|
// maybe useless, but seems to give tiny wins
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct Interpreter<'c, W, R, P> {
|
struct Interpreter<'lir, W, R, P> {
|
||||||
code: &'c Lir<'c>,
|
code: &'lir Lir<'lir>,
|
||||||
profile_collector: P,
|
profile_collector: P,
|
||||||
ip: usize,
|
ip: usize,
|
||||||
ptr: usize,
|
ptr: usize,
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ pub enum Stmt {
|
||||||
const _: [(); 8] = [(); std::mem::size_of::<Stmt>()];
|
const _: [(); 8] = [(); std::mem::size_of::<Stmt>()];
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Lir<'c> {
|
pub struct Lir<'lir> {
|
||||||
stmts: BumpVec<'c, Stmt>,
|
stmts: BumpVec<'lir, Stmt>,
|
||||||
debug: BumpVec<'c, Span>,
|
debug: BumpVec<'lir, Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Lir<'_> {
|
impl Debug for Lir<'_> {
|
||||||
|
|
@ -70,12 +70,12 @@ impl Lir<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate<'c>(alloc: &'c Bump, ir: &Hir<'_>) -> Lir<'c> {
|
pub fn generate<'lir>(alloc: &'lir Bump, ir: &Hir<'_>) -> Lir<'lir> {
|
||||||
let stmts = Vec::new_in(alloc);
|
let stmts = Vec::new_in(alloc);
|
||||||
let debug = Vec::new_in(alloc);
|
let debug = Vec::new_in(alloc);
|
||||||
let mut lir = Lir { stmts, debug };
|
let mut lir = Lir { stmts, debug };
|
||||||
|
|
||||||
generate_stmts(&mut lir, &ir.stmts);
|
hir_to_lir(&mut lir, &ir.stmts);
|
||||||
lir.stmts.push(Stmt::End);
|
lir.stmts.push(Stmt::End);
|
||||||
lir.debug.push(Span::default());
|
lir.debug.push(Span::default());
|
||||||
|
|
||||||
|
|
@ -84,14 +84,14 @@ pub fn generate<'c>(alloc: &'c Bump, ir: &Hir<'_>) -> Lir<'c> {
|
||||||
lir
|
lir
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_stmts<'c>(lir: &mut Lir<'c>, ir: &[HirStmt<'_>]) {
|
fn hir_to_lir<'lir>(lir: &mut Lir<'lir>, ir: &[HirStmt<'_>]) {
|
||||||
for ir_stmt in ir {
|
for ir_stmt in ir {
|
||||||
ir_to_stmt(lir, ir_stmt);
|
hir_stmt_to_lir_stmt(lir, ir_stmt);
|
||||||
}
|
}
|
||||||
debug_assert_eq!(lir.stmts.len(), lir.debug.len());
|
debug_assert_eq!(lir.stmts.len(), lir.debug.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ir_to_stmt<'c>(lir: &mut Lir<'c>, ir_stmt: &HirStmt<'_>) {
|
fn hir_stmt_to_lir_stmt<'lir>(lir: &mut Lir<'lir>, ir_stmt: &HirStmt<'_>) {
|
||||||
let stmt = match &ir_stmt.kind {
|
let stmt = match &ir_stmt.kind {
|
||||||
HirStmtKind::Add(0, n) => Stmt::Add(*n),
|
HirStmtKind::Add(0, n) => Stmt::Add(*n),
|
||||||
HirStmtKind::Sub(0, n) => Stmt::Sub(*n),
|
HirStmtKind::Sub(0, n) => Stmt::Sub(*n),
|
||||||
|
|
@ -115,7 +115,7 @@ fn ir_to_stmt<'c>(lir: &mut Lir<'c>, ir_stmt: &HirStmt<'_>) {
|
||||||
lir.debug.push(ir_stmt.span);
|
lir.debug.push(ir_stmt.span);
|
||||||
|
|
||||||
// compile the loop body now
|
// compile the loop body now
|
||||||
generate_stmts(lir, &instr.stmts);
|
hir_to_lir(lir, &instr.stmts);
|
||||||
// if the loop body is empty, we jmp to ourselves, which is an infinite loop - as expected
|
// if the loop body is empty, we jmp to ourselves, which is an infinite loop - as expected
|
||||||
let first_loop_body_idx = skip_jmp_idx + 1;
|
let first_loop_body_idx = skip_jmp_idx + 1;
|
||||||
lir.stmts
|
lir.stmts
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1 @@
|
||||||
[<+++>-
|
+>.
|
||||||
>>>>>
|
|
||||||
+++[->+++++<]>[-]<
|
|
||||||
<<<<<
|
|
||||||
]
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue