mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 07:49:17 +03:00
feat(editor): add constrain module
This commit is contained in:
parent
36e6739212
commit
bb51f15494
32
editor/src/lang/constrain.rs
Normal file
32
editor/src/lang/constrain.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::lang::pool::{Pool, PoolVec};
|
||||
use crate::lang::{ast::Expr2, expr::Env, types::Type2};
|
||||
|
||||
use roc_can::expected::Expected;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_region::all::Region;
|
||||
use roc_types::types::Category;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Constraint {
|
||||
Eq(Type2, Expected<Type2>, Category, Region),
|
||||
// Store(Type, Variable, &'static str, u32),
|
||||
// Lookup(Symbol, Expected<Type>, Region),
|
||||
// Pattern(Region, PatternCategory, Type, PExpected<Type>),
|
||||
True, // Used for things that always unify, e.g. blanks and runtime errors
|
||||
// SaveTheEnvironment,
|
||||
// Let(Box<LetConstraint>),
|
||||
// And(Vec<Constraint>),
|
||||
}
|
||||
|
||||
pub fn constrain_expr(env: &mut Env, expr: &Expr2, expected: Expected<Type2>) -> Constraint {
|
||||
use Constraint::*;
|
||||
|
||||
match expr {
|
||||
Expr2::Str(_) => Eq(str_type(env.pool), expected, Category::Str, Region::zero()),
|
||||
_ => todo!("implement constaints for {:?}", expr),
|
||||
}
|
||||
}
|
||||
|
||||
fn str_type(pool: &mut Pool) -> Type2 {
|
||||
Type2::Apply(Symbol::STR_STR, PoolVec::empty(pool))
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
pub mod ast;
|
||||
pub mod constrain;
|
||||
mod def;
|
||||
pub mod expr;
|
||||
mod module;
|
||||
@ -6,4 +7,4 @@ mod pattern;
|
||||
pub mod pool;
|
||||
pub mod roc_file;
|
||||
pub mod scope;
|
||||
mod types;
|
||||
pub mod types;
|
||||
|
Loading…
Reference in New Issue
Block a user