aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock64
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs7
3 files changed, 72 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f7d2ec1..66a4cc8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -202,6 +202,17 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -368,6 +379,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -386,6 +403,46 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -524,6 +581,7 @@ dependencies = [
"criterion",
"logos",
"owo-colors",
+ "rand",
"sylt_macro",
]
@@ -595,6 +653,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
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<Error>> {
+ let mut path = std::env::temp_dir();
+ path.push(format!("test_{}.sy", rand::random::<u32>()));
+ 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<Error>> {
let sections = sectionizer::sectionize(path);
match compiler::Compiler::new(sections).compile("main", path, &functions) {