mod limits;
mod result;
mod rule_set;
mod tracing;
use crate::error::{ParseError, RunError};
use crate::execution::RunningExecution;
use crate::inspect::{RuleCount, RuleView};
use crate::parser::parse_rules_impl;
use crate::rule::Rule;
use crate::runtime::RuntimeInput;
use crate::source::ProgramSource;
pub(crate) use rule_set::RuleSet;
pub use limits::{
DEFAULT_MAX_INPUT_LEN, DEFAULT_MAX_RETURN_LEN, DEFAULT_MAX_STATE_LEN, DEFAULT_MAX_STEPS,
DEFAULT_MAX_TRACE_SNAPSHOT_LEN, ReturnByteLimit, RunLimits, RuntimeInputByteLimit,
RuntimeStateByteLimit, StepCount, StepLimit, TraceSnapshotByteLimit, TraceSnapshotLimits,
};
pub use result::{ReturnOutput, RunOutcome, RunResult, RuntimeStateSnapshot};
#[derive(Debug, PartialEq, Eq)]
pub struct Program {
rule_set: RuleSet,
}
impl Program {
pub(crate) fn from_rule_set(rule_set: RuleSet) -> Self {
Self { rule_set }
}
pub fn parse(source: ProgramSource<'_>) -> Result<Self, ParseError> {
Ok(Self::from_rule_set(parse_rules_impl(source)?))
}
#[must_use]
pub fn rule_count(&self) -> RuleCount {
self.rule_set.rule_count()
}
#[must_use]
pub fn once_rule_count(&self) -> RuleCount {
self.rule_set.once_rule_count()
}
pub fn rules(&self) -> impl Iterator<Item = RuleView<'_>> + '_ {
self.rule_set.as_slice().iter().map(Rule::view)
}
pub(crate) fn rule_slice(&self) -> &[Rule] {
self.rule_set.as_slice()
}
pub fn start_execution(
&self,
input: &RuntimeInput,
limits: RunLimits,
) -> Result<RunningExecution<'_>, RunError> {
RunningExecution::new(self, input, limits)
}
pub fn run(&self, input: &RuntimeInput, limits: RunLimits) -> Result<RunResult, RunError> {
RunningExecution::new(self, input, limits)?.finish()
}
}