From ebbc675ffd4704085641c1f2bec3129caa2bb8cd Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:11:01 +0100 Subject: [PATCH] more work --- src/compile.rs | 28 +++++++++++++++++++++++----- test.sl | 4 +++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/compile.rs b/src/compile.rs index db68f80..de042a2 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -187,12 +187,16 @@ impl Compiler { fn lookup_local(&self, name: &Ident) -> CResult { for locals in self.locals.iter().rev() { + dbg!("searching"); if let Some(&position) = locals.get(name) { return Ok(position); } } - Err(CompileError) + Err(CompileError::new( + name.span, + format!("variable {} not found", name.sym), + )) } fn current_stack_top(&self) -> usize { @@ -221,18 +225,32 @@ enum StackChange { } #[derive(Debug)] -pub struct CompileError; +pub struct CompileError { + span: Span, + message: String, + note: Option, +} + +impl CompileError { + fn new(span: Span, message: String) -> Self { + Self { + span, + message, + note: None, + } + } +} impl CompilerError for CompileError { fn span(&self) -> Span { - todo!() + self.span } fn message(&self) -> String { - todo!() + self.message.clone() } fn note(&self) -> Option { - todo!() + self.note.clone() } } diff --git a/test.sl b/test.sl index 8e8a2ae..8ac0832 100644 --- a/test.sl +++ b/test.sl @@ -1 +1,3 @@ -let x = 2 * 3; \ No newline at end of file +let x = 2 * 3; + +let tz = x * 5; \ No newline at end of file