diff --git a/REF.md b/REF.md index 3e2224a..7d7a011 100644 --- a/REF.md +++ b/REF.md @@ -51,5 +51,3 @@ done ``` - - diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index c1ea035..706b032 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -4,7 +4,7 @@ mod utils; use anyhow::bail; use crate::{cli::{CliArgs, CompilationTarget}, types::ast::Program}; -use std::{collections::HashMap, fs::File, io::{BufWriter, Write}, path::{Path, PathBuf}}; +use std::{collections::HashMap, fs::File, io::{BufWriter, Write}, path::{Path, PathBuf}, process::Command}; use self::utils::run_cmd; @@ -49,7 +49,28 @@ pub fn compile_program(cli_args: &CliArgs, prog_map: HashMap<&Path, Program>) -> info!("Finished building program"); if cli_args.run { - run_cmd(format!("./{}", bin_p.to_string_lossy()), cli_args.passthrough.clone())?; + // run_cmd(format!("./{}", bin_p.to_string_lossy()), cli_args.passthrough.clone())?; + let bin = bin_p.to_string_lossy().to_string(); + let mut cmd = Command::new(format!("./{}", bin.clone())); + let cmd = cmd.args(cli_args.passthrough.clone()); + + let child = match cmd.spawn() { + Ok(c) => c, + Err(e) => { + error!("Unable to run {cmd:?}: {e}"); + bail!(""); + } + }; + let ret = child.wait_with_output().expect("fuck i know"); + + + if !ret.status.success() { + error!("Process running {bin:?} exited abnormaly, run with -v 2 for more output"); + bail!("") + } else { + info!("Process exited successfully") + } + } diff --git a/test.mcl b/test.mcl index 4e0980e..625e165 100644 --- a/test.mcl +++ b/test.mcl @@ -16,24 +16,24 @@ include "std.mcl" // fn putd with int returns void then drop done fn main with int ptr returns int then - // 1 2 add - // 69 _dbg_print + 1 2 add + 69 _dbg_print "Hewo\n" puts - // if 3 4 eq do - // "omg what impossible!\n" - // else if 1 1 eq do - // "whaaaaaaaaa\n" - // else - // "finally, some good soup\n" - // done - // puts + if 3 4 eq do + "omg what impossible!\n" + else if 1 1 eq do + "whaaaaaaaaa\n" + else + "finally, some good soup\n" + done + puts - // 10 - // while dup 0 gt do - // "uwu" puts - // dup _dbg_print - // 1 sub - // done + 10 + while dup 0 gt do + "uwu " puts + dup _dbg_print + 1 sub + done done