Skip to content

Commit

Permalink
Merge pull request #495 from KisaragiEffective/feat/cli/max-stack-size
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective authored Jun 27, 2024
2 parents 6d1550e + b7464b2 commit 1dde0f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions package/origlang-cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// clap issue?: https://github.com/clap-rs/clap/issues/4733
#![warn(clippy::almost_swapped)]

use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::string::FromUtf8Error;
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -57,10 +58,19 @@ impl Args {
task.execute(())?;
Ok(())
}
SubCom::Execute { input_file, input_source } => {
SubCom::Execute { input_file, input_source, max_stack_size_on_main_thread } => {
let task = Interpret;
let source = load_either(input_file, input_source);
task.execute(source)?;
if let Some(ssize) = max_stack_size_on_main_thread {
let a = std::thread::scope(move |a| {
std::thread::Builder::new().stack_size(ssize.get()).spawn_scoped(a, move || {
task.execute(source)
}).unwrap().join()
});
a.map_err(TaskExecutionError::ThreadJoin)??;
} else {
task.execute(source)?;
}
Ok(())
}
SubCom::Emit { emit, input_file, input_source, optimize_level } => {
Expand All @@ -82,7 +92,9 @@ pub enum SubCom {
#[clap(long, group = "evaluate_source")]
input_file: Option<PathBuf>,
#[clap(long, group = "evaluate_source")]
input_source: Option<String>
input_source: Option<String>,
#[clap(long)]
max_stack_size_on_main_thread: Option<NonZeroUsize>,
},
/// Emits unstable intermediate representation for only debug purposes.
Emit {
Expand Down
3 changes: 3 additions & 0 deletions package/origlang-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use thiserror::Error;
use origlang_parser::error::ParserError;
use origlang_typecheck::type_check::error::TypeCheckError;
Expand All @@ -15,4 +16,6 @@ pub enum TaskExecutionError {
TypeCheck(#[from] TypeCheckError),
#[error("{0}")]
Runtime(#[from] RuntimeError),
#[error("Thread returned error")]
ThreadJoin(Box<dyn Any + Send>),
}

0 comments on commit 1dde0f4

Please sign in to comment.