From 958f7b9e20ab152e8c54b5cb10e67e03e2f83dbc Mon Sep 17 00:00:00 2001 From: pixelsystem Date: Mon, 26 Feb 2024 22:27:58 -0500 Subject: [PATCH] adding a function to get the typed ast in order for lsp --- compiler/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 44e815f..8a0884c 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -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,