feat: some boilerplate for typechecking

This commit is contained in:
rvcas
2022-10-13 18:34:25 -04:00
committed by Lucas
parent ed2ef4fa9b
commit 4df3de0a03
13 changed files with 264 additions and 34 deletions

View File

@@ -481,6 +481,7 @@ pub struct IfBranch<Expr> {
pub location: Span,
}
#[derive(Debug)]
pub struct TypedRecordUpdateArg {
pub label: String,
pub location: Span,

View File

@@ -1,4 +0,0 @@
pub enum Origin {
Src,
Test,
}

View File

@@ -0,0 +1,17 @@
use std::collections::HashMap;
use crate::{ast::ModuleKind, tipo};
pub fn prelude() -> tipo::Module {
let mut prelude = tipo::Module {
name: vec!["gleam".to_string()],
package: "".to_string(),
kind: ModuleKind::Lib,
types: HashMap::new(),
types_constructors: HashMap::new(),
values: HashMap::new(),
accessors: HashMap::new(),
};
prelude
}

View File

@@ -10,6 +10,7 @@ use crate::{
tipo::{ModuleValueConstructor, PatternConstructor, Type, ValueConstructor},
};
#[derive(Debug)]
pub enum TypedExpr {
Int {
location: Span,

View File

@@ -1,5 +1,5 @@
pub mod ast;
pub mod build;
pub mod builtins;
pub mod error;
pub mod expr;
pub mod lexer;

View File

@@ -1,9 +1,9 @@
use std::{cell::RefCell, collections::HashMap, sync::Arc};
use crate::{
ast::{Constant, FieldMap, Span, TypedConstant},
build::Origin,
};
use crate::ast::{Constant, FieldMap, ModuleKind, Span, TypedConstant};
pub mod error;
pub mod infer;
#[derive(Debug, Clone, PartialEq)]
pub enum Type {
@@ -105,9 +105,10 @@ pub enum ValueConstructorVariant {
},
}
#[derive(Debug, Clone)]
pub struct Module {
pub name: Vec<String>,
pub origin: Origin,
pub kind: ModuleKind,
pub package: String,
pub types: HashMap<String, TypeConstructor>,
pub types_constructors: HashMap<String, Vec<String>>,
@@ -115,6 +116,7 @@ pub struct Module {
pub accessors: HashMap<String, AccessorsMap>,
}
#[derive(Debug, Clone)]
pub struct TypeConstructor {
pub public: bool,
pub origin: Span,
@@ -123,12 +125,14 @@ pub struct TypeConstructor {
pub typ: Arc<Type>,
}
#[derive(Debug, Clone)]
pub struct AccessorsMap {
pub public: bool,
pub tipo: Arc<Type>,
pub accessors: HashMap<String, RecordAccessor>,
}
#[derive(Debug, Clone)]
pub struct RecordAccessor {
// TODO: smaller int. Doesn't need to be this big
pub index: u64,
@@ -136,6 +140,7 @@ pub struct RecordAccessor {
pub tipo: Arc<Type>,
}
#[derive(Debug)]
pub enum PatternConstructor {
Record {
name: String,
@@ -143,6 +148,7 @@ pub enum PatternConstructor {
},
}
#[derive(Debug)]
pub enum ModuleValueConstructor {
Record {
name: String,

View File

@@ -0,0 +1,72 @@
use std::sync::Arc;
use miette::Diagnostic;
use crate::ast::{Span, TodoKind};
use super::Type;
#[derive(Debug, thiserror::Error, Diagnostic)]
pub enum Error {}
#[derive(Debug, PartialEq, Clone)]
pub enum Warning {
Todo {
kind: TodoKind,
location: Span,
typ: Arc<Type>,
},
ImplicitlyDiscardedResult {
location: Span,
},
UnusedLiteral {
location: Span,
},
NoFieldsRecordUpdate {
location: Span,
},
AllFieldsRecordUpdate {
location: Span,
},
UnusedType {
location: Span,
imported: bool,
name: String,
},
UnusedConstructor {
location: Span,
imported: bool,
name: String,
},
UnusedImportedValue {
location: Span,
name: String,
},
UnusedImportedModule {
location: Span,
name: String,
},
UnusedPrivateModuleConstant {
location: Span,
name: String,
},
UnusedPrivateFunction {
location: Span,
name: String,
},
UnusedVariable {
location: Span,
name: String,
},
}

View File

@@ -0,0 +1,19 @@
use std::collections::HashMap;
use crate::ast::{ModuleKind, TypedModule, UntypedModule};
use super::{
error::{Error, Warning},
Module,
};
pub fn module(
// ids: &UniqueIdGenerator,
mut module: UntypedModule,
kind: ModuleKind,
package: &str,
modules: &HashMap<String, Module>,
warnings: &mut Vec<Warning>,
) -> Result<TypedModule, Error> {
todo!()
}