diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-15 22:33:17 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-15 22:33:17 +0100 |
| commit | 3c5a33f008b40e272d3a720aa81fb5a8568a4527 (patch) | |
| tree | d75f443ac15c8939e3315d8447eddc50019b652f /src | |
| parent | 4d2121c548492c591d3366f6a3b919b098c349d6 (diff) | |
| download | sylt-3c5a33f008b40e272d3a720aa81fb5a8568a4527.tar.gz | |
give better error messages
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 95290a0..faca7f8 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -361,16 +361,21 @@ impl Compiler { } fn error(&mut self, kind: ErrorKind, message: Option<String>) { + self.error_on_line(kind, self.line(), message); + } + + fn error_on_line(&mut self, kind: ErrorKind, line: usize, message: Option<String>) { if self.panic { return } self.panic = true; self.errors.push(Error { kind, file: self.current_file.clone(), - line: self.line(), + line, message, }); } + fn peek(&self) -> Token { self.peek_at(0) } @@ -1363,6 +1368,18 @@ impl Compiler { add_op(self, &mut block, Op::Return); block.ty = Type::Function(Vec::new(), Box::new(Type::Void)); + if self.unkowns.len() != 0 { + let errors: Vec<_> = self.unkowns.iter().map(|(name, (_, line))| + (ErrorKind::SyntaxError(*line, Token::Identifier(name.clone())), + *line, + format!("Usage of undefined 'blob': '{}'.", name,) + )) + .collect(); + for (e, l, m) in errors.iter() { + self.error_on_line(e.clone(), *l, Some(m.clone())); + } + } + self.blocks.insert(0, Rc::new(RefCell::new(block))); if self.errors.is_empty() { |
