From d0718adf7f12ee4d54ba05515c5f988ce96af510 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 16 Apr 2022 22:21:19 +0200 Subject: [PATCH] rename lir lifetimes --- rust2/src/hir/mod.rs | 2 +- rust2/src/lir/interpreter.rs | 4 ++-- rust2/src/lir/mod.rs | 18 +++++++++--------- rust2/test.bf | 6 +----- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/rust2/src/hir/mod.rs b/rust2/src/hir/mod.rs index a2df1a6..4c888f4 100644 --- a/rust2/src/hir/mod.rs +++ b/rust2/src/hir/mod.rs @@ -31,7 +31,7 @@ impl<'hir> Stmt<'hir> { Self { kind, span } } - fn kind(&self) -> &StmtKind<'hir> { + pub fn kind(&self) -> &StmtKind<'hir> { &self.kind } } diff --git a/rust2/src/lir/interpreter.rs b/rust2/src/lir/interpreter.rs index 046a918..e62d0c0 100644 --- a/rust2/src/lir/interpreter.rs +++ b/rust2/src/lir/interpreter.rs @@ -12,8 +12,8 @@ type Memory = [Wrapping; MEM_SIZE]; // `repr(C)` to make sure rustc never reorders the fields weirdly // maybe useless, but seems to give tiny wins #[repr(C)] -struct Interpreter<'c, W, R, P> { - code: &'c Lir<'c>, +struct Interpreter<'lir, W, R, P> { + code: &'lir Lir<'lir>, profile_collector: P, ip: usize, ptr: usize, diff --git a/rust2/src/lir/mod.rs b/rust2/src/lir/mod.rs index 30ed996..0a3fac3 100644 --- a/rust2/src/lir/mod.rs +++ b/rust2/src/lir/mod.rs @@ -49,9 +49,9 @@ pub enum Stmt { const _: [(); 8] = [(); std::mem::size_of::()]; #[derive(Clone)] -pub struct Lir<'c> { - stmts: BumpVec<'c, Stmt>, - debug: BumpVec<'c, Span>, +pub struct Lir<'lir> { + stmts: BumpVec<'lir, Stmt>, + debug: BumpVec<'lir, Span>, } 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 debug = Vec::new_in(alloc); 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.debug.push(Span::default()); @@ -84,14 +84,14 @@ pub fn generate<'c>(alloc: &'c Bump, ir: &Hir<'_>) -> Lir<'c> { 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 { - ir_to_stmt(lir, ir_stmt); + hir_stmt_to_lir_stmt(lir, ir_stmt); } 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 { HirStmtKind::Add(0, n) => Stmt::Add(*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); // 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 let first_loop_body_idx = skip_jmp_idx + 1; lir.stmts diff --git a/rust2/test.bf b/rust2/test.bf index 5a2c354..b56e5f8 100644 --- a/rust2/test.bf +++ b/rust2/test.bf @@ -1,5 +1 @@ -[<+++>- - >>>>> - +++[->+++++<]>[-]< - <<<<< - ] \ No newline at end of file ++>. \ No newline at end of file