schala/schala-lang/src/reduced_ir/test.rs

45 lines
902 B
Rust
Raw Normal View History

#![cfg(test)]
use super::*;
2021-10-27 15:39:09 -07:00
use crate::{symbol_table::SymbolTable, type_inference::TypeContext};
fn build_ir(input: &str) -> ReducedIR {
2021-10-27 15:39:09 -07:00
let ast = crate::util::quick_ast(input);
2021-10-27 15:39:09 -07:00
let mut symbol_table = SymbolTable::new();
let mut type_context = TypeContext::new();
2021-10-27 15:39:09 -07:00
symbol_table.process_ast(&ast, &mut type_context).unwrap();
2021-10-29 22:03:34 -07:00
let reduced = reduce(&ast, &symbol_table, &type_context);
2021-10-27 15:39:09 -07:00
reduced.debug(&symbol_table);
reduced
}
#[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);
}