use shape_runtime::module_exports::ModuleContext;
use shape_runtime::typed_module_exports::TypedReturn;
use shape_value::KindedSlot;
fn capture_surface(op: &str) -> String {
format!(
"{op}: W17-snapshot-resume surface — kind-threaded \
slot_to_serializable / serializable_to_slot replacement for the \
deleted nanboxed_to_serializable / serializable_to_nanboxed \
pair has not landed. Tracked as W17-snapshot-resume per \
docs/cluster-audits/phase-2d-playbook.md §3. \
ADR-006 §2.7.4 (snapshot serialization deferral) + §2.7.5.1 \
(post-proof wire-format shape for new HeapKinds: HashSet, \
Iterator, Result, Option, Deque, Channel, PriorityQueue, \
Range, Reference, FilterExpr, SharedCell).",
)
}
fn marshal_return_surface(op: &str, return_shape: &str) -> String {
format!(
"{op}: W17-snapshot-resume surface — body successfully reads \
VM state via vm_state but the {return_shape} return arm needs the \
W17-marshal-return-arms follow-up at project_typed_return \
(executor/vm_impl/modules.rs). Tracked as W17-snapshot-resume per \
docs/cluster-audits/phase-2d-playbook.md §3. ADR-006 §2.7.4 \
(snapshot serialization deferral) + §2.7.5.1.",
)
}
pub(crate) fn state_capture_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.capture"));
};
if vm_state.current_frame().is_none() {
return Err(format!(
"state.capture: no current frame — state.capture must be \
called from within a function body. ADR-006 §2.7.4."
));
}
Err(marshal_return_surface("state.capture", "FrameState typed-object"))
}
pub(crate) fn state_capture_all_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.capture_all"));
};
let _frames = vm_state.all_frames();
let _bindings = vm_state.module_bindings();
let _icount = vm_state.instruction_count();
Err(marshal_return_surface("state.capture_all", "VmState typed-object"))
}
pub(crate) fn state_capture_module_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.capture_module"));
};
let _bindings = vm_state.module_bindings();
Err(marshal_return_surface(
"state.capture_module",
"ModuleState typed-object",
))
}
pub(crate) fn state_capture_call_stub(
_args: &[KindedSlot],
_ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
Err(marshal_return_surface(
"state.capture_call",
"CallPayload typed-object",
))
}
pub(crate) fn state_resume_stub(
args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(set_pending_resume) = ctx.set_pending_resume else {
return Err(capture_surface("state.resume"));
};
let Some(snapshot_slot) = args.first() else {
return Err(format!(
"state.resume: W17-snapshot-resume surface — missing required \
`vm: VmState` argument. ADR-006 §2.7.4."
));
};
set_pending_resume(snapshot_slot.clone());
Ok(TypedReturn::Concrete(
shape_runtime::typed_module_exports::ConcreteReturn::Unit,
))
}
pub(crate) fn state_resume_frame_stub(
args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(_set_pending_frame_resume) = ctx.set_pending_frame_resume else {
return Err(capture_surface("state.resume_frame"));
};
let Some(_frame_state_slot) = args.first() else {
return Err(format!(
"state.resume_frame: W17-snapshot-resume surface — missing \
required `f: FrameState` argument. ADR-006 §2.7.4."
));
};
Err(format!(
"state.resume_frame: W17-snapshot-resume surface — extracting \
(ip_offset, locals) from the FrameState typed-object argument \
needs the typed-object field-decode path that lands with \
W17-marshal-return-arms. ADR-006 §2.7.4."
))
}
pub(crate) fn state_caller_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.caller"));
};
let _caller = vm_state.caller_frame();
Err(marshal_return_surface(
"state.caller",
"FunctionRef? Option-typed",
))
}
pub(crate) fn state_args_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.args"));
};
let _args_captured = vm_state.current_args();
Err(marshal_return_surface("state.args", "Array<any>"))
}
pub(crate) fn state_locals_stub(
_args: &[KindedSlot],
ctx: &ModuleContext,
) -> Result<TypedReturn, String> {
let Some(vm_state) = ctx.vm_state else {
return Err(capture_surface("state.locals"));
};
let _locals = vm_state.current_locals();
Err(marshal_return_surface("state.locals", "Map<string, any>"))
}