diff --git a/.gitignore b/.gitignore index 058252d..17a81ca 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target docsite/site/generated docsite/site/public rerast_rules/ +src/build/stdlib.rs diff --git a/Cargo.lock b/Cargo.lock index 62c6c41..d04a53a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,6 +364,14 @@ name = "ryu" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "same-file" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scoped_threadpool" version = "0.1.9" @@ -491,6 +499,7 @@ dependencies = [ "serde_yaml 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "simple-error 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -519,6 +528,16 @@ name = "version_check" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "walkdir" +version = "2.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" @@ -543,6 +562,14 @@ name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -610,6 +637,7 @@ dependencies = [ "checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1" "checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" "checksum ryu 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c066b8e2923f05d4718a06d2622f189ff362bc642bfade6c6629f0440f3827" +"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)" = "22d340507cea0b7e6632900a176101fea959c7065d93ba555072da90aaaafc87" "checksum serde_json 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "44dd2cfde475037451fa99b7e5df77aa3cfd1536575fa8e7a538ab36dcde49ae" @@ -629,10 +657,12 @@ dependencies = [ "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "541b12c998c5b56aa2b4e6f18f03664eef9a4fd0a246a55594efae6cc2d964b5" "checksum yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57ab38ee1a4a266ed033496cf9af1828d8d6e6c1cfa5f643a2809effcae4d628" diff --git a/Cargo.toml b/Cargo.toml index 935160a..d447fc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ documentation = "https://docs.rs/crate/ucg" readme = "README.md" keywords = ["compiler", "config"] license = "Apache-2.0" +include = ["std/**/*.ucg", "std/*.ucg"] +build = "bin/build_main.rs" [dependencies] abortable_parser = "~0.2.2" @@ -22,6 +24,10 @@ base64 = "0.10.0" regex = "1" dirs = "1.0.4" +[build-dependencies] +walkdir = "2.2.7" +dirs = "1.0.4" + [dev-dependencies] bencher = "~0.1.5" cpuprofiler = "0.0.3" diff --git a/bin/build_main.rs b/bin/build_main.rs new file mode 100644 index 0000000..8dc135b --- /dev/null +++ b/bin/build_main.rs @@ -0,0 +1,30 @@ +extern crate walkdir; + +use walkdir::WalkDir; + +fn generate_rust_module() -> String { + let mut rust_lib = String::new(); + rust_lib.push_str("use std::collections::HashMap;\n"); + rust_lib.push_str("pub fn get_libs() -> HashMap {\n"); + rust_lib.push_str("\tlet mut stdlib = HashMap::new();\n"); + for entry in WalkDir::new("std").into_iter().filter_map(|e| e.ok()) { + // Okay we want to add these as include bytes in a simulated + // filesystem for our binary to use. + let path = entry.into_path(); + // We only include files that are not test files. + if path.is_file() && !path.ends_with("_test.ucg") { + let path_str = path.to_string_lossy(); + let include = format!("\tstdlib.insert(\n\t\t\"{}\".to_string(),\n\t\tinclude_str!(\"../../{}\"));\n", path_str, path_str); + rust_lib.push_str(&include); + } + } + rust_lib.push_str("\tstdlib\n"); + rust_lib.push_str("}"); + println!("{}", rust_lib); + rust_lib +} + +fn main() { + let contents = generate_rust_module(); + std::fs::write("src/build/stdlib.rs", contents.as_bytes()).unwrap(); +} \ No newline at end of file diff --git a/src/build/mod.rs b/src/build/mod.rs index d0f9ea3..dc3e181 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -39,6 +39,7 @@ use crate::parse::parse; pub mod assets; pub mod ir; pub mod scope; +mod stdlib; pub use self::ir::Val; @@ -143,6 +144,7 @@ macro_rules! eval_binary_expr { }; } +// TODO(jwall): Use the builder patter here. Just like AstWalker. impl<'a> FileBuilder<'a> { /// Constructs a new Builder. pub fn new>(