diff --git a/Cargo.toml b/Cargo.toml index 6fdf83f78ad..a10c8e99f6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ members = [ "noirc_errors", "noirc_driver", "acir", + "std_lib", ] \ No newline at end of file diff --git a/noirc_frontend/Cargo.toml b/noirc_frontend/Cargo.toml index 15a7a3267e7..6cabf4ff68e 100644 --- a/noirc_frontend/Cargo.toml +++ b/noirc_frontend/Cargo.toml @@ -10,4 +10,5 @@ edition = "2018" noir_field = {path = "../noir_field"} acir = {path = "../acir"} noirc_errors = {path = "../noirc_errors"} -thiserror = "1.0.21" \ No newline at end of file +thiserror = "1.0.21" +std_lib = {path = "../std_lib"} \ No newline at end of file diff --git a/noirc_frontend/src/analyser/mod.rs b/noirc_frontend/src/analyser/mod.rs index 110588e8735..95fec9f6852 100644 --- a/noirc_frontend/src/analyser/mod.rs +++ b/noirc_frontend/src/analyser/mod.rs @@ -100,16 +100,13 @@ fn load_local_functions_into_symbol_table(ast: &Program, table: &mut SymbolTable } fn load_low_level_libraries_into_symbol_table(table: &mut SymbolTable) { - + use std_lib::LIB_NOIR; // Import std here - // XXX: Should be a better way to fetch the absolute path here. - // May have to wait until proper module dependency graph is added - let std_lib = std::fs::read_to_string("../../../std/lib.noir").unwrap(); - + // // Parse and add low level functions into a symbol table - // We could define the AST for this in the host language + // XXX: We could alternatively define the AST for this in the host language - let mut parser = crate::Parser::with_input(&std_lib); + let mut parser = crate::Parser::with_input(&LIB_NOIR); let (program) = parser.parse_program().unwrap(); let (checked_program, std_table) = check_program(program, true).unwrap(); // We do nothing with the checked program for two reasons: Every module should have a copy of std_lib diff --git a/std_lib/Cargo.toml b/std_lib/Cargo.toml new file mode 100644 index 00000000000..07b5b126d10 --- /dev/null +++ b/std_lib/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "std_lib" +version = "0.1.0" +authors = ["Kevaundray Wedderburn "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/std/lib.noir b/std_lib/src/lib.noir similarity index 100% rename from std/lib.noir rename to std_lib/src/lib.noir diff --git a/std_lib/src/lib.rs b/std_lib/src/lib.rs new file mode 100644 index 00000000000..06a4b3d4715 --- /dev/null +++ b/std_lib/src/lib.rs @@ -0,0 +1 @@ +pub const LIB_NOIR : &'static str = include_str!("lib.noir"); \ No newline at end of file