2021-10-21 15:23:48 -07:00
|
|
|
#![cfg(test)]
|
|
|
|
|
|
|
|
use super::*;
|
2021-10-27 15:39:09 -07:00
|
|
|
use crate::{symbol_table::SymbolTable, type_inference::TypeContext};
|
2021-10-21 15:23:48 -07:00
|
|
|
|
|
|
|
fn build_ir(input: &str) -> ReducedIR {
|
2021-10-27 15:39:09 -07:00
|
|
|
let ast = crate::util::quick_ast(input);
|
2021-10-21 15:23:48 -07:00
|
|
|
|
2021-10-27 15:39:09 -07:00
|
|
|
let mut symbol_table = SymbolTable::new();
|
|
|
|
let mut type_context = TypeContext::new();
|
2021-10-21 15:23:48 -07:00
|
|
|
|
2021-10-27 15:39:09 -07:00
|
|
|
symbol_table.process_ast(&ast, &mut type_context).unwrap();
|
2021-10-21 15:23:48 -07:00
|
|
|
|
2021-10-27 15:39:09 -07:00
|
|
|
let reduced = reduce(&ast, &symbol_table);
|
|
|
|
reduced.debug(&symbol_table);
|
|
|
|
reduced
|
|
|
|
}
|
2021-10-21 15:23:48 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ir() {
|
|
|
|
let src = r#"
|
|
|
|
|
|
|
|
let global_one = 10 + 20
|
|
|
|
let global_two = "the string hello"
|
|
|
|
|
|
|
|
fn a_function(i, j, k) {
|
|
|
|
fn nested(x) {
|
|
|
|
x + 10
|
|
|
|
}
|
|
|
|
i + j * nested(k)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn another_function(e) {
|
|
|
|
let local_var = 420
|
|
|
|
e * local_var
|
|
|
|
}
|
|
|
|
|
|
|
|
another_function()
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let reduced = build_ir(src);
|
2021-10-24 22:55:12 -07:00
|
|
|
assert_eq!(reduced.functions.len(), 3);
|
|
|
|
//assert!(1 == 2);
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|