aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-script/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-14 03:13:04 +0300
committerValentin Popov <valentin@popov.link>2026-11-14 03:13:04 +0300
commit446081d70a4bb6a1bc54fa486e9b439dc02cb31a (patch)
tree202b506f813eaa977d4ecf6afd7d80787ff7485e /crates/fparkan-script/src
parent85f3d6a8b4c09604a560e03596357b7bcb62c496 (diff)
downloadfparkan-446081d70a4bb6a1bc54fa486e9b439dc02cb31a.tar.xz
fparkan-446081d70a4bb6a1bc54fa486e9b439dc02cb31a.zip
feat(runtime): start missions with explicit Init stubs
Diffstat (limited to 'crates/fparkan-script/src')
-rw-r--r--crates/fparkan-script/src/lib.rs71
1 files changed, 55 insertions, 16 deletions
diff --git a/crates/fparkan-script/src/lib.rs b/crates/fparkan-script/src/lib.rs
index 71e694d9..33da97bf 100644
--- a/crates/fparkan-script/src/lib.rs
+++ b/crates/fparkan-script/src/lib.rs
@@ -185,6 +185,18 @@ pub enum ScriptInitResolution {
},
}
+/// Proven writes before the first unsupported instruction of a selected `Init`.
+pub struct ScriptInitPrefix {
+ /// Zero-based selected event index.
+ pub event_index: usize,
+ /// Opaque event word retained from the package.
+ pub event_word: u32,
+ /// Ordered writes from instructions that ran.
+ pub writes: Vec<ScriptInitWrite>,
+ /// Zero-based instruction index and reason, if execution stopped early.
+ pub stopped_at: Option<(usize, ScriptInitResolveError)>,
+}
+
/// A typed failure or unsupported form in the recovered `Init` subset.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ScriptInitResolveError {
@@ -733,9 +745,8 @@ impl VarSet {
/// Resolves the first case-sensitive `Init` event's recovered write subset.
///
/// Handler(19) writes use the caller's original setter-boundary words. A
- /// sentinel selector is accepted only for the proven formula assignment
- /// with control and copy-source words both equal to `0xffffffff`; the
- /// referenced row is evaluated only when that instruction is reached.
+ /// sentinel selector accepts immediate and formula assignments. A
+ /// referenced formula row is evaluated only when its instruction is reached.
/// Formula atoms read defaults and earlier successful writes in this event.
///
/// # Errors
@@ -748,10 +759,40 @@ impl VarSet {
input: Handler19InitInput,
formulas: Option<&FormulaTable>,
) -> Result<ScriptInitResolution, ScriptInitResolveError> {
+ Ok(match self.resolve_init_prefix(package, input, formulas)? {
+ None => ScriptInitResolution::Missing,
+ Some(ScriptInitPrefix {
+ event_index,
+ stopped_at: Some((instruction_index, error)),
+ ..
+ }) => ScriptInitResolution::Unsupported {
+ event_index,
+ instruction_index,
+ error,
+ },
+ Some(prefix) => ScriptInitResolution::Executed {
+ event_index: prefix.event_index,
+ event_word: prefix.event_word,
+ writes: prefix.writes,
+ },
+ })
+ }
+
+ /// Resolves the supported prefix for a caller that can report a partial `Init`.
+ ///
+ /// # Errors
+ ///
+ /// Malformed instructions still return an error without publishing writes.
+ pub fn resolve_init_prefix(
+ &self,
+ package: &ScriptPackage,
+ input: Handler19InitInput,
+ formulas: Option<&FormulaTable>,
+ ) -> Result<Option<ScriptInitPrefix>, ScriptInitResolveError> {
let Some((event_index, event)) = package.events.iter().enumerate().find(|(_, event)| {
event.name_raw.split(|byte| *byte == 0).next() == Some(&b"Init"[..])
}) else {
- return Ok(ScriptInitResolution::Missing);
+ return Ok(None);
};
let mut values = self
@@ -759,7 +800,12 @@ impl VarSet {
.iter()
.map(|declaration| declaration.default_value)
.collect::<Vec<_>>();
- let mut writes = Vec::new();
+ let mut prefix = ScriptInitPrefix {
+ event_index,
+ event_word: event.event_word,
+ writes: Vec::new(),
+ stopped_at: None,
+ };
for (instruction_index, instruction) in event.instructions.iter().enumerate() {
match self.resolve_init_instruction(instruction, input, formulas, &values)? {
InitInstructionResolution::Executed(instruction_writes) => {
@@ -772,23 +818,16 @@ impl VarSet {
};
*value = write.value;
}
- writes.extend(instruction_writes);
+ prefix.writes.extend(instruction_writes);
}
InitInstructionResolution::Unsupported(error) => {
- return Ok(ScriptInitResolution::Unsupported {
- event_index,
- instruction_index,
- error,
- });
+ prefix.stopped_at = Some((instruction_index, error));
+ break;
}
}
}
- Ok(ScriptInitResolution::Executed {
- event_index,
- event_word: event.event_word,
- writes,
- })
+ Ok(Some(prefix))
}
fn resolve_init_instruction(