From 888b38ad4cfde16498e6b38db7e9c77ffe4c2429 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sat, 21 Dec 2024 23:55:02 +0100 Subject: [PATCH] frgot to transition @nameof to slices Signed-off-by: Jakub Doka --- lang/src/lib.rs | 4 ++-- lang/src/parser.rs | 1 - lang/src/son.rs | 15 ++++++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lang/src/lib.rs b/lang/src/lib.rs index 0434d2897..fad931c4d 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -127,7 +127,7 @@ pub mod backend { mod utils; mod debug { - use {core::fmt::Debug, std::string::String}; + use core::fmt::Debug; pub fn panicking() -> bool { #[cfg(feature = "std")] @@ -141,7 +141,7 @@ mod debug { } #[cfg(all(debug_assertions, feature = "std"))] - pub type Trace = std::rc::Rc<(std::backtrace::Backtrace, String)>; + pub type Trace = std::rc::Rc<(std::backtrace::Backtrace, std::string::String)>; #[cfg(not(all(debug_assertions, feature = "std")))] pub type Trace = (); diff --git a/lang/src/parser.rs b/lang/src/parser.rs index f72883135..5bf4e181a 100644 --- a/lang/src/parser.rs +++ b/lang/src/parser.rs @@ -17,7 +17,6 @@ use { ptr::NonNull, sync::atomic::AtomicUsize, }, - std::panic, }; pub type Pos = u32; diff --git a/lang/src/son.rs b/lang/src/son.rs index 19628015a..41597ff96 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -31,7 +31,6 @@ use { format_args as fa, mem, }, hbbytecode::DisasmError, - std::panic, }; const DEFAULT_ACLASS: usize = 0; @@ -1350,7 +1349,7 @@ impl<'a> Codegen<'a> { let elem = self.tys.ins.slices[s].elem; let off = self.offset(bs.id, 0); let base = self.tys.make_ptr(elem); - let bs = std::dbg!(self.load_mem(off, base)); + let bs = self.load_mem(off, base); Some(self.offset_ptr(bs, elem, idx.id)) } ty::Kind::Struct(s) => { @@ -1426,18 +1425,24 @@ impl<'a> Codegen<'a> { let ty = self.ty(ty); self.gen_inferred_const(ctx, ty::Id::U8, ty.kind()) } - Expr::Directive { name: "nameof", args: [ty], .. } => { + Expr::Directive { pos, name: "nameof", args: [ty], .. } => { let ty = self.ty(ty); let mut data = core::mem::take(&mut self.pool.lit_buf); self.tys.name_of(ty, self.files, &mut data); - data.push(0); let (global, ty) = self.create_string_global(&data); + let len = self.ci.nodes.new_const_lit(ty, data.len() as i64); data.clear(); self.pool.lit_buf = data; - Some(Value::new(global).ty(ty)) + let slc = self.tys.make_array(ty::Id::U8, ArrayLen::MAX); + let mem = self.new_stack(pos, slc); + for (off, value) in [(0u32, Value::ptr(global).ty(ty)), (8, len)] { + let region = self.offset(mem, off); + self.store_mem(region, value.ty, value.id); + } + Some(Value::ptr(mem).ty(slc)) } Expr::Directive { name: "sizeof", args: [ty], .. } => { let ty = self.ty(ty);