refactor typing and compilation
This commit is contained in:
parent
e8deab19cc
commit
ba838292f6
8 changed files with 175 additions and 131 deletions
|
|
@ -4,10 +4,10 @@ use super::UnaryOperator;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct TypeError {
|
||||
file: Option<std::path::PathBuf>,
|
||||
module: ModulePath,
|
||||
function: Option<String>,
|
||||
kind: TypeErrorKind,
|
||||
pub file: Option<std::path::PathBuf>,
|
||||
pub module: ModulePath,
|
||||
pub function: Option<String>,
|
||||
pub kind: TypeErrorKind,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TypeError {
|
||||
|
|
@ -62,7 +62,7 @@ impl TypeErrorBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum TypeErrorKind {
|
||||
InvalidBinaryOperator {
|
||||
operator: BinaryOperator,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ use crate::ast::*;
|
|||
mod error;
|
||||
use crate::typing::error::{TypeError, TypeErrorKind};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum Type {
|
||||
/// Not a real type, used for parsing pass
|
||||
|
|
@ -76,8 +79,10 @@ impl FunctionDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CheckedModule(pub Module);
|
||||
|
||||
impl Module {
|
||||
pub fn type_check(&mut self) -> Result<(), TypeError> {
|
||||
pub fn type_check(mut self) -> Result<CheckedModule, TypeError> {
|
||||
let mut ctx = TypingContext::new(self.path.clone());
|
||||
ctx.file = self.file.clone();
|
||||
|
||||
|
|
@ -96,7 +101,7 @@ impl Module {
|
|||
ctx.variables.clear();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(CheckedModule(self))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue