summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 8d8486e9e856b4c946ccb93136b4cd80a560a39a (plain)
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
// Copyright ⓒ 2017 David Li.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

pub mod ast;
pub mod semantic;
pub mod taiga;

use std::cell::RefCell;
use std::io::{self, BufRead, Write};
use std::rc::Rc;

fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    loop {
        let mut translate = semantic::translate::Translate::<semantic::frame::Amd64Frame>::new();
        let toplevel = Rc::new(RefCell::new(semantic::translate::Level::Top));
        let level = translate.make_level(toplevel, vec![]);
        let mut input = String::new();
        print!("taiga> ");
        io::stdout().flush().unwrap();
        if let Ok(n) = handle.read_line(&mut input) {
            if n == 0 { break; }
            let program = taiga::parse_Program(&input);
            println!("{:?}", program);
            if let Ok(program) = program {
                let result = semantic::analysis::translate(&mut translate, level, &program);
                println!("{:?}", result);
            }
        }
        else {
            break;
        }
    }
}