feat(vm)!: implement typed callables and single-context execution
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Add structural Fn signatures, typed capture environments, indirect calls and Trait dispatch while preserving logical parameter and result groups, ownership and budgets. Remove guest coroutine execution and legacy loading. Activate bounded sealed PBX v1 with mandatory capture metadata, preserve frame continuations and root return results, and migrate producers and shipped cartridges. Publish coordinated specs, handoffs and the completed runtime lesson. Validation: 880 workspace tests passed, 9 existing tests ignored; both cartridges completed six production-host frames.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
use crate::decoder::DecodedInstr;
|
||||
use crate::isa::core::{CoreOpCode as Op, CoreOpCodeSpecExt};
|
||||
use crate::load_limits::{IdDomain, LoadCode, LoadFailure, LoadReason};
|
||||
use crate::registry::{Registry, TypeId, TypeKind};
|
||||
use crate::registry::{FunctionId, Registry, TypeId, TypeKind};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct RegistryStackEffect {
|
||||
@@ -11,6 +11,27 @@ pub struct RegistryStackEffect {
|
||||
}
|
||||
|
||||
impl DecodedInstr<'_> {
|
||||
/// Capture effects require the enclosing function's resolved environment.
|
||||
pub fn registry_stack_effect_in(
|
||||
&self,
|
||||
registry: &Registry,
|
||||
function: FunctionId,
|
||||
) -> Result<Option<RegistryStackEffect>, LoadFailure> {
|
||||
if self.opcode == Op::GetCapture {
|
||||
let index = self
|
||||
.imm_u32()
|
||||
.map_err(|_| LoadFailure::new(LoadCode::InvalidCode, LoadReason::Truncated))?;
|
||||
let capture = registry
|
||||
.function_layout(function)
|
||||
.and_then(|f| f.captures.get(index as usize))
|
||||
.ok_or_else(|| {
|
||||
LoadFailure::new(LoadCode::InvalidReference, LoadReason::CaptureIndex)
|
||||
.member(index)
|
||||
})?;
|
||||
return Ok(Some(RegistryStackEffect { pops: 0, pushes: capture.slots }));
|
||||
}
|
||||
self.registry_stack_effect(registry)
|
||||
}
|
||||
/// Resolve an instruction's exact group widths and check immediate domains.
|
||||
/// None means this is not a Registry instruction, not a zero stack effect.
|
||||
/// This does not prove that the values on the stack satisfy the signature.
|
||||
@@ -43,6 +64,42 @@ impl DecodedInstr<'_> {
|
||||
e
|
||||
};
|
||||
let (pops, pushes) = match self.opcode {
|
||||
Op::MakeClosure => {
|
||||
let (function, ty) = self.imm_u32x2().map_err(|_| malformed())?;
|
||||
let (_, layout) = type_info(ty)?;
|
||||
if layout.callable.is_none() {
|
||||
return Err(bad_category(ty));
|
||||
}
|
||||
let target = registry.function_layout(FunctionId(function)).ok_or_else(|| {
|
||||
LoadFailure::new(LoadCode::InvalidReference, LoadReason::FunctionId)
|
||||
.reference(IdDomain::Function, function)
|
||||
})?;
|
||||
(target.capture_slots, 1)
|
||||
}
|
||||
Op::CallClosure => {
|
||||
let ty = self.imm_u32().map_err(|_| malformed())?;
|
||||
let (_, layout) = type_info(ty)?;
|
||||
let signature = layout.callable.as_ref().ok_or_else(|| bad_category(ty))?;
|
||||
(
|
||||
signature.parameter_slots.checked_add(1).ok_or_else(malformed)?,
|
||||
signature.result_slots,
|
||||
)
|
||||
}
|
||||
Op::GetCapture => {
|
||||
return Err(LoadFailure::new(LoadCode::InvalidReference, LoadReason::CaptureIndex))
|
||||
}
|
||||
Op::CallTrait => {
|
||||
let (ty, method) = self.imm_u32x2().map_err(|_| malformed())?;
|
||||
let (_, layout) = type_info(ty)?;
|
||||
let signature = layout
|
||||
.methods
|
||||
.get(method as usize)
|
||||
.ok_or_else(|| bad_category(ty).member(method))?;
|
||||
(
|
||||
signature.parameter_slots.checked_add(2).ok_or_else(malformed)?,
|
||||
signature.result_slots,
|
||||
)
|
||||
}
|
||||
Op::DynPack | Op::DynUnpack | Op::DynCanUnpack => {
|
||||
let id = self.imm_u32().map_err(|_| malformed())?;
|
||||
let (_, layout) = type_info(id)?;
|
||||
|
||||
Reference in New Issue
Block a user