Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disable-codegen option #270

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/lune/src/cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ enum PromptState {

/// Launch an interactive REPL (default)
#[derive(Debug, Clone, Default, Parser)]
pub struct ReplCommand {}
pub struct ReplCommand {
/// If native codegen should be disabled. This is useful for benchmarking.
#[clap(long)]
disable_codegen: bool,
}

impl ReplCommand {
pub async fn run(self) -> Result<ExitCode> {
Expand All @@ -38,7 +42,7 @@ impl ReplCommand {
let mut prompt_state = PromptState::Regular;
let mut source_code = String::new();

let mut lune_instance = Runtime::new();
let mut lune_instance = Runtime::new(!self.disable_codegen);

loop {
let prompt = match prompt_state {
Expand Down
5 changes: 4 additions & 1 deletion crates/lune/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ use super::utils::files::{discover_script_path_including_lune_dirs, strip_sheban
pub struct RunCommand {
/// Script name or full path to the file to run
script_path: String,
/// If native codegen should be disabled. This is useful for benchmarking.
#[clap(long)]
disable_codegen: bool,
/// Arguments to pass to the script, stored in process.args
script_args: Vec<String>,
}
Expand All @@ -41,7 +44,7 @@ impl RunCommand {
};

// Create a new lune runtime with all globals & run the script
let mut rt = Runtime::new().with_args(self.script_args);
let mut rt = Runtime::new(!self.disable_codegen).with_args(self.script_args);

let result = rt
.run(&script_display_name, strip_shebang(script_contents))
Expand Down
8 changes: 5 additions & 3 deletions crates/lune/src/rt/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ self_cell! {
}

impl RuntimeInner {
fn create() -> LuaResult<Self> {
fn create(codegen: bool) -> LuaResult<Self> {
let lua = Rc::new(Lua::new());

lua.enable_jit(codegen);

lua.set_app_data(Rc::downgrade(&lua));
lua.set_app_data(Vec::<String>::new());

Expand Down Expand Up @@ -110,9 +112,9 @@ impl Runtime {
*/
#[must_use]
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
pub fn new(codegen: bool) -> Self {
Self {
inner: RuntimeInner::create().expect("Failed to create runtime"),
inner: RuntimeInner::create(codegen).expect("Failed to create runtime"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/lune/src/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn run(patched_bin: impl AsRef<[u8]>) -> Result<ExitCode> {
let args = env::args().skip(1).collect::<Vec<_>>();
let meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary");

let mut rt = Runtime::new().with_args(args);
let mut rt = Runtime::new(true).with_args(args);

let result = rt.run("STANDALONE", meta.bytecode).await;

Expand Down
2 changes: 1 addition & 1 deletion crates/lune/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ macro_rules! create_tests {
// The rest of the test logic can continue as normal
let full_name = format!("{}/tests/{}.luau", workspace_dir.display(), $value);
let script = read_to_string(&full_name).await?;
let mut lune = Runtime::new().with_args(
let mut lune = Runtime::new(true).with_args(
ARGS
.clone()
.iter()
Expand Down