From e9589ebcae580637f4237dc89cdd6b231867b85a Mon Sep 17 00:00:00 2001 From: mlokr Date: Sun, 7 Jul 2024 14:26:43 +0200 Subject: [PATCH] brahmaputra --- hblang/src/codegen.rs | 8 ++++++++ hblang/src/parser.rs | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 47301c41..864ad501 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1639,6 +1639,14 @@ impl Codegen { self.find_or_declare(target.pos(), idx, Err(field), "") .compress(), )), + ty::Kind::Global(idx) => Some(Value::ty({ + let global = &self.tys.globals[idx as usize]; + ty::Id::from(u32::from_ne_bytes( + self.output.code[global.offset as usize..][..4] + .try_into() + .unwrap(), + )) + })), e => unimplemented!("{e:?}"), } } diff --git a/hblang/src/parser.rs b/hblang/src/parser.rs index f833f7ee..16c2dab7 100644 --- a/hblang/src/parser.rs +++ b/hblang/src/parser.rs @@ -876,7 +876,23 @@ impl<'a> std::fmt::Display for Expr<'a> { Self::Ident { name, .. } => write!(f, "{name}"), Self::Block { stmts, .. } => { write!(f, "{{")?; - fmt_trailing_list(f, "}", stmts, std::fmt::Display::fmt) + writeln!(f)?; + INDENT.with(|i| i.set(i.get() + 1)); + let res = (|| { + for stmt in list { + for _ in 0..INDENT.with(|i| i.get()) { + write!(f, "\t")?; + } + fmt(stmt, f)?; + } + Ok(()) + })(); + INDENT.with(|i| i.set(i.get() - 1)); + for _ in 0..INDENT.with(|i| i.get()) { + write!(f, "\t")?; + } + write!(f, "{end}")?; + res } Self::Number { value, .. } => write!(f, "{value}"), Self::Bool { value, .. } => write!(f, "{value}"),