Initial commit
This commit is contained in:
commit
85b08fe00b
29 changed files with 750 additions and 0 deletions
7
crates/typing/Cargo.toml
Normal file
7
crates/typing/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "shiny-typing"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
shiny-std.workspace = true
|
33
crates/typing/src/bin.rs
Normal file
33
crates/typing/src/bin.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
//! # Binary types
|
||||
|
||||
use shiny_std::arena::make_comb;
|
||||
|
||||
use crate::ptr;
|
||||
|
||||
make_comb! {
|
||||
/// Type with additionally equipped ID.
|
||||
pub struct Field {
|
||||
pub ty: ptr::Ty,
|
||||
pub id: ptr::Id,
|
||||
}
|
||||
|
||||
/// Product type. Pretty much just `lhs_ty * rhs_ty`.
|
||||
/// The following properties must be upheld:
|
||||
///
|
||||
/// 1. lhs * rhs = rhs * lhs <- commutativity
|
||||
/// 2. (a * b) * c = a * (b * c) <- associativity
|
||||
pub struct Prod {
|
||||
pub lhs: ptr::Ty,
|
||||
pub rhs: ptr::Ty,
|
||||
}
|
||||
|
||||
/// Sum type. Pretty much just `lhs_ty + rhs_ty`.
|
||||
/// The following properties must be upheld:
|
||||
///
|
||||
/// 1. lhs + rhs = rhs + rhs <- commutativity
|
||||
/// 2. (a + b) + c = a + (b + c) <- associativity
|
||||
pub struct Sum {
|
||||
pub lhs: ptr::Ty,
|
||||
pub rhs: ptr::Ty,
|
||||
}
|
||||
}
|
1
crates/typing/src/check/ctx.rs
Normal file
1
crates/typing/src/check/ctx.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub struct Ctx {}
|
4
crates/typing/src/check/mod.rs
Normal file
4
crates/typing/src/check/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//! # Type checking.
|
||||
|
||||
pub mod ctx;
|
||||
pub mod shape;
|
7
crates/typing/src/check/shape.rs
Normal file
7
crates/typing/src/check/shape.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use crate::ptr;
|
||||
|
||||
use super::ctx::Ctx;
|
||||
|
||||
pub fn fits(lhs: ptr::Ty, rhs: ptr::Ty) -> bool {
|
||||
todo!()
|
||||
}
|
15
crates/typing/src/infer/ctx.rs
Normal file
15
crates/typing/src/infer/ctx.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use shiny_std::arena::intern;
|
||||
|
||||
use crate::{bin, int, ptr};
|
||||
|
||||
enum Ty {
|
||||
Prod(bin::Prod),
|
||||
Sum(bin::Sum),
|
||||
Field(bin::Field),
|
||||
Int(int::Int),
|
||||
}
|
||||
|
||||
/// Inference context.
|
||||
pub struct Ctx {
|
||||
tys: intern::Arena<Ty, ptr::Ty>,
|
||||
}
|
3
crates/typing/src/infer/mod.rs
Normal file
3
crates/typing/src/infer/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
//! # Type inference.
|
||||
|
||||
mod ctx;
|
14
crates/typing/src/int.rs
Normal file
14
crates/typing/src/int.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
//! # Integer types.
|
||||
|
||||
/// Sign of the integer.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Signedness {
|
||||
/// The number has sign.
|
||||
Signed,
|
||||
/// The number has no sign.
|
||||
Unsigned,
|
||||
}
|
||||
|
||||
/// Integer.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Int(pub Signedness);
|
10
crates/typing/src/lib.rs
Normal file
10
crates/typing/src/lib.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
pub mod bin;
|
||||
pub mod un;
|
||||
|
||||
pub mod int;
|
||||
pub mod pat;
|
||||
|
||||
pub mod ptr;
|
||||
|
||||
pub mod check;
|
||||
pub mod infer;
|
32
crates/typing/src/pat.rs
Normal file
32
crates/typing/src/pat.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use shiny_arena::make_comb;
|
||||
|
||||
use crate::ptr;
|
||||
|
||||
make_comb! {
|
||||
/// Product type pattern.
|
||||
pub struct Prod {
|
||||
pub lhs: ptr::Pat,
|
||||
pub rhs: ptr::Pat,
|
||||
}
|
||||
|
||||
/// Sum type pattern.
|
||||
pub struct Sum {
|
||||
pub lhs: ptr::Pat,
|
||||
pub rhs: ptr::Pat,
|
||||
}
|
||||
|
||||
/// Exact type. Matches only if matched type
|
||||
/// equals to specified.
|
||||
pub struct ExactTy(pub ptr::Ty);
|
||||
|
||||
/// Field type. matches `{ name : ty_pat }`
|
||||
pub struct Field {
|
||||
pub name: ptr::Id,
|
||||
pub ty: ptr::Pat,
|
||||
}
|
||||
|
||||
/// "Value" pattern. Works like [`ExactTy`], but
|
||||
/// additionally checks whether value of that type is equal
|
||||
/// to specified value.
|
||||
pub struct Value(pub ptr::Value);
|
||||
}
|
21
crates/typing/src/ptr.rs
Normal file
21
crates/typing/src/ptr.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
//! # Pointers to needed information.
|
||||
//!
|
||||
//! If values are equal, then their pointers are equal.
|
||||
//! This means that there's unambiguous mapping from id to value and
|
||||
//! back.
|
||||
|
||||
use shiny_std::arena::ptr::define;
|
||||
|
||||
define! {
|
||||
/// Pointer to a type.
|
||||
pub struct Ty;
|
||||
|
||||
/// Pointer to ID.
|
||||
pub struct Id;
|
||||
|
||||
/// Pointer to a pattern.
|
||||
pub struct Pat;
|
||||
|
||||
/// Pointer to a *complete* value.
|
||||
pub struct Value;
|
||||
}
|
1
crates/typing/src/un.rs
Normal file
1
crates/typing/src/un.rs
Normal file
|
@ -0,0 +1 @@
|
|||
//! # Unary types
|
Loading…
Add table
Add a link
Reference in a new issue