From 6b4b3d9d01057c27909bab7675c2ad3ec5e910a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 28 Feb 2021 17:37:24 +0100 Subject: run strings from temporary files --- Cargo.lock | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/lib.rs | 7 +++++++ 3 files changed, 72 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f7d2ec1..66a4cc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,6 +201,17 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "half" version = "1.7.1" @@ -367,6 +378,12 @@ dependencies = [ "plotters-backend", ] +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + [[package]] name = "proc-macro2" version = "1.0.24" @@ -385,6 +402,46 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.5.0" @@ -524,6 +581,7 @@ dependencies = [ "criterion", "logos", "owo-colors", + "rand", "sylt_macro", ] @@ -594,6 +652,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasm-bindgen" version = "0.2.70" diff --git a/Cargo.toml b/Cargo.toml index f6b763f..b14b588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ name = "sylt" [dependencies] logos = "0.11.4" owo-colors = { git="https://github.com/FredTheDino/owo-colors.git" } +rand = "0.8" sylt_macro = { path = "sylt_macro" } criterion = { version = "0.3", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 629d39f..76486dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,13 @@ pub fn run_file(path: &Path, print: bool, functions: Vec<(String, RustFunction)> run(path, print, functions) } +pub fn run_string(source: &str, print: bool, functions: Vec<(String, RustFunction)>) -> Result<(), Vec> { + let mut path = std::env::temp_dir(); + path.push(format!("test_{}.sy", rand::random::())); + std::fs::write(path.clone(), source).expect("Failed to write source to temporary file"); + run(&path, print, functions) +} + fn run(path: &Path, print: bool, functions: Vec<(String, RustFunction)>) -> Result<(), Vec> { let sections = sectionizer::sectionize(path); match compiler::Compiler::new(sections).compile("main", path, &functions) { -- cgit v1.2.1