Function compile_and_run
pub fn compile_and_run(
source: &str,
output_dir: &Path,
) -> Result<String, CompileError>Expand description
Compile and run a LOGOS program end-to-end.
This function performs the full compilation workflow:
- Compile LOGOS to Rust via
compile_to_dir - Run
cargo buildwith JSON diagnostics - Translate any rustc errors to LOGOS-friendly messages
- Run the compiled program via
cargo run
§Arguments
source- LOGOS source code as a stringoutput_dir- Directory to create the temporary Cargo project in
§Returns
The stdout output of the executed program.
§Errors
Returns CompileError if:
- Compilation fails (see
compile_to_dir) - Rust compilation fails (
CompileError::BuildorCompileError::Ownership) - The program crashes at runtime (
CompileError::Runtime)
§Diagnostic Translation
When rustc reports errors (e.g., E0382 for use-after-move), this function
uses the diagnostic module to translate them into
LOGOS-friendly Socratic error messages.
§Example
let source = "## Main\nShow \"Hello, World!\".";
let output = compile_and_run(source, Path::new("/tmp/run"))?;
assert_eq!(output.trim(), "Hello, World!");