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 --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') 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