aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: f31e16367622ef653dce3a87e61bd0b1c5fc12e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::io::{Write, stdout, stdin};
use crate::ast::*;

mod ast;
mod classes;
mod effects;
mod parser;
mod simple;

fn main() {
    println!("type-systems");
    let mut input = String::new();
    loop {
        println!("infer, check, or execute? (i/c/e)");
        print!("\x1b[1m==> \x1b[22m");
        stdout().flush().unwrap();

        input.clear();
        stdin().read_line(&mut input).unwrap();
        match input.trim() {
            "i" | "g" | "infer" => {
                println!("enter partially annotated expression to fully infer");
                print!("\x1b[1m====> \x1b[22m");
                stdout().flush().unwrap();

                input.clear();
                stdin().read_line(&mut input).unwrap();
                simple::infer(Context::new(), parser::parse(&input));
            },
            "c" | "t" | "check" | "typecheck" => {
                println!("enter fully annotated expression to typecheck");
                print!("\x1b[1m====> \x1b[22m");
                stdout().flush().unwrap();

                input.clear();
                stdin().read_line(&mut input).unwrap();
                simple::check(Context::new(), parser::parse(&input));
            },
            "e" | "r" | "execute" | "run" => {
                println!("enter expression to execute");
                print!("\x1b[1m====> \x1b[22m");
                stdout().flush().unwrap();

                input.clear();
                stdin().read_line(&mut input).unwrap();
                simple::execute(Context::new(), parser::parse(&input));
            },
            _ => println!("invalid option {}. please try again.", input.trim())
        }
    }
}