aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a33e963c9439221ce9a50d7291b7d07658d3bdca (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::io::{Write, stdout, stdin};

use chrysanthemum::*;
use chrysanthemum::ast::*;
use chrysanthemum::bidirectional::*;
use chrysanthemum::simple::*;

fn main() {
    println!("chrysanthemum");
    let mut input = String::new();
    let empty_context = Context::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();
                match infer(&empty_context, parser::parse_lambda(&input).unwrap()) {
                    Ok(kind) => println!("infers! {}", kind),
                    Err(e) => println!("{:?}", e),
                }
            },
            "c" | "t" | "check" => {
                println!("enter fully annotated expression to typecheck");
                print!("\x1b[1m====> \x1b[22m");
                stdout().flush().unwrap();

                input.clear();
                stdin().read_line(&mut input).unwrap();
                let kind = infer(&empty_context, parser::parse_lambda(&input).unwrap());
                match kind {
                    Ok(kind) => {
                        match check(&empty_context, parser::parse_lambda(&input).unwrap(), &kind) {
                            Ok(_) => println!("checks!"),
                            Err(e) => println!("{:?}", e),
                        }
                    },
                    Err(_) => println!("failed to infer high-level type!")
                }
            },
            "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();
                match execute(&empty_context, parser::parse_lambda(&input).unwrap()) {
                    Ok(term) => println!("{}", term),
                    Err(e) => println!("{:?}", e)
                }
            },
            _ => println!("invalid option {}. please try again.", input.trim())
        }
    }
}