Skip to content

Commit

Permalink
adding a function to get the typed ast in order for lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
JCBurnside committed Feb 27, 2024
1 parent fbc5d22 commit 958f7b9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ pub fn get_untyped_ast(input:&str,file_name:&str) -> ast::ModuleDeclaration{
Parser::from_stream(ts).module(file_name.to_string())
}

pub fn get_ast(input:&str, file_name:&str) -> typed_ast::TypedModuleDeclaration {
let ts = TokenStream::from_source(input);
let module = Parser::from_stream(ts).module(file_name.to_string());
// TODO! get prelude.
let dep_tree= module.get_dependencies().into_iter().map(|(k,v)| (k,v.into_iter().collect())).collect();
let ops : HashMap<_,_> = [
("+".to_string(), vec![
types::INT32.fn_ty(&types::INT32.fn_ty(&types::INT32))
])
].into();
let mut infer_context = inference::Context::new(dep_tree, HashMap::new(), HashMap::new(), ops.clone(), HashMap::new());
let ast = infer_context.inference(module);
TypedModuleDeclaration::from(ast, &HashMap::new(), &ops)
}

pub fn from_file<'ctx>(
file: &PathBuf,
Expand Down

0 comments on commit 958f7b9

Please sign in to comment.