Compare commits

...

2 Commits

Author SHA1 Message Date
8690bb71cf Fix nullptr type 2025-07-28 01:46:17 +03:00
9c2f47534a Update how line number is shown in errors 2025-07-28 01:43:30 +03:00
2 changed files with 20 additions and 19 deletions

View File

@ -1,4 +1,4 @@
use reid_lib::{builder::InstructionValue, CmpPredicate, ConstValue, Instr}; use reid_lib::{builder::InstructionValue, CmpPredicate, ConstValue, Instr, Type};
use crate::{ use crate::{
codegen::{ErrorKind, StackValueKind}, codegen::{ErrorKind, StackValueKind},
@ -284,7 +284,10 @@ impl IntrinsicFunction for IntrinsicNullPtr {
let zero = scope.block.build(Instr::Constant(ConstValue::I8(0))).unwrap(); let zero = scope.block.build(Instr::Constant(ConstValue::I8(0))).unwrap();
let instr = scope let instr = scope
.block .block
.build(Instr::IntToPtr(zero, self.0.get_type(scope.type_values))) .build(Instr::IntToPtr(
zero,
Type::Ptr(Box::new(self.0.get_type(scope.type_values))),
))
.unwrap(); .unwrap();
Ok(StackValue(StackValueKind::Literal(instr), self.0.clone())) Ok(StackValue(StackValueKind::Literal(instr), self.0.clone()))
} }

View File

@ -194,32 +194,30 @@ impl std::fmt::Display for ReidError {
None None
}; };
if curr_module != Some(meta.source_module_id) { let module_name = if curr_module != Some(meta.source_module_id) {
curr_module = Some(meta.source_module_id); curr_module = Some(meta.source_module_id);
if let Some(module) = self.map.module_map.get(&meta.source_module_id) { if let Some(module) = self.map.module_map.get(&meta.source_module_id) {
writeln!( module.name.clone()
f,
"Errors in module {}:",
color_err(format!("{}", module.name))?
)?;
} else { } else {
writeln!(f, "Errors detected: {}", color_err("in general")?)?; "unknown".to_owned()
} }
} } else {
"unknown".to_owned()
};
writeln!(f, "Errors detected: {}", color_err(format!("{}", module_name))?)?;
writeln!(f)?; writeln!(f)?;
write!(f, " Error: ")?; write!(f, " Error: ")?;
writeln!(f, "{}", color_err(format!("{}", error))?)?; writeln!(f, "{}", color_err(format!("{}", error))?)?;
write!( write!(
f, f,
"{:>20}{}", "{:>20} {}:{}",
color_warn("At: ")?, color_warn("At: ")?,
position module_name,
.map(|p| fmt_positions(p)) position.map(|p| fmt_positions(p)).unwrap_or(String::from("{unknown}")),
.unwrap_or(String::from("{unknown}")),
)?; )?;
if let (Some(position), Some(source)) = if let (Some(position), Some(source)) = (position, &module.and_then(|m| m.source.clone())) {
(position, &module.and_then(|m| m.source.clone()))
{
writeln!(f, "{}", fmt_lines(source, position, 6)?)?; writeln!(f, "{}", fmt_lines(source, position, 6)?)?;
} }
} }
@ -286,9 +284,9 @@ fn fmt_lines(
fn fmt_positions((start, end): (Position, Position)) -> String { fn fmt_positions((start, end): (Position, Position)) -> String {
if start == end { if start == end {
format!("ln {}, col {}", start.1, start.0) format!("{}:{}", start.1, start.0)
} else if start.1 == end.1 { } else if start.1 == end.1 {
format!("ln {}, col {}-{}", start.1, start.0, end.0) format!("{}:{} - {}", start.1, start.0, end.0)
} else { } else {
format!("{}:{} - {}:{}", start.1, start.0, end.1, end.0) format!("{}:{} - {}:{}", start.1, start.0, end.1, end.0)
} }