diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-14 21:10:07 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-15 16:57:56 +0100 |
| commit | 7ec991b8d6654aaf27a005804347346e16500a47 (patch) | |
| tree | bf36be24f2a8dffa4589aecfce75d0f0bf55f440 /src/error.rs | |
| parent | 4e6071aee97a26610aeee423d830a695b8c4d563 (diff) | |
| download | sylt-7ec991b8d6654aaf27a005804347346e16500a47.tar.gz | |
Start of typesystem
There's a type system, that kinda works
There needs to be better parsing of types, since not all types are
currently parsable. Some of them are, and the simple stuff works!
:D
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/error.rs b/src/error.rs index 979ca07..6d8a14c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,11 +1,13 @@ use std::fmt; use std::path::PathBuf; use crate::vm::{Op, Value}; +use crate::compiler::Type; use crate::tokenizer::Token; #[derive(Debug, Clone)] pub enum ErrorKind { - TypeError(Op, Vec<Value>), + TypeError(Op, Vec<Type>), + RuntimeTypeError(Op, Vec<Value>), Assert, InvalidProgram, Unreachable, @@ -24,7 +26,13 @@ pub struct Error { impl fmt::Display for ErrorKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ErrorKind::TypeError(op, values) => { + ErrorKind::TypeError(op, types) => { + let types = types + .iter() + .fold(String::new(), |a, v| { format!("{}, {:?}", a, v) }); + write!(f, "Cannot apply {:?} to types {}", op, types) + } + ErrorKind::RuntimeTypeError(op, values) => { let values = values .iter() .fold(String::new(), |a, v| { format!("{}, {:?}", a, v) }); @@ -52,7 +60,7 @@ impl fmt::Display for Error { Some(s) => format!("\n{}", s), None => String::from(""), }; - write!(f, "{:?}:{} [Runtime Error] {}{}", self.file, self.line, self.kind, message) + write!(f, "{:?}:{} {}{}", self.file, self.line, self.kind, message) } } |
