From 441a1eacfe065d19670bcc9d216d24bb0f9ad3db Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Wed, 22 Nov 2023 15:41:19 +0530 Subject: [PATCH] fix: finalize updated standalone runtime system --- src/cli/build.rs | 4 +--- src/cli/mod.rs | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/cli/build.rs b/src/cli/build.rs index 724ca5c..c25f8d6 100644 --- a/src/cli/build.rs +++ b/src/cli/build.rs @@ -13,9 +13,7 @@ pub async fn build_standalone + Into>( ) -> Result<()> { // First, we read the contents of the lune interpreter as our starting point let mut patched_bin = fs::read(env::current_exe()?).await?; - let base_bin_offset = u64::try_from(patched_bin.len() - 1)?; - - println!("base offset: {}", base_bin_offset); + let base_bin_offset = u64::try_from(patched_bin.len())?; // The signature which separates indicates the presence of bytecode to execute // If a binary contains this signature, that must mean it is a standalone binar diff --git a/src/cli/mod.rs b/src/cli/mod.rs index a0946d6..caee24c 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -182,35 +182,25 @@ impl Cli { } if bytecode_offset != 0 && bytecode_size != 0 { - Lune::new() + let result = Lune::new() .with_args(self.script_args.clone()) .run( "STANDALONE", &bin[usize::try_from(bytecode_offset).unwrap() ..usize::try_from(bytecode_offset + bytecode_size).unwrap()], ) - .await?; + .await; + + return Ok(match result { + Err(err) => { + eprintln!("{err}"); + ExitCode::FAILURE + } + Ok(code) => code, + }); } return repl::show_interface().await; - - // Check to see if the lune executable includes the signature - // return match bin - // .clone() - // .par_windows(signature.len()) - // // .rev() - // .position_any(|block| block == signature) - // { - // // If we find the signature, all bytes after the 5 signature bytes must be bytecode - // Some(offset) => { - // // let offset = bin.len() - 1 - back_offset; - // } - - // // If we did not generate any typedefs, know we're not a precompiled bin and - // // we know that the user did not provide any other options, and in that - // // case we should enter the REPL - // None => repl::show_interface().await, - // }; } // Figure out if we should read from stdin or from a file, // reading from stdin is marked by passing a single "-"