Implement validated wordcode execution with shared code objects and frames
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 14m27s

This commit is contained in:
2026-10-18 20:41:56 +08:00
parent 50e8fcb5e7
commit 6fa95b64b0
18 changed files with 2327 additions and 152 deletions
+79
View File
@@ -0,0 +1,79 @@
use std::sync::Arc;
use crate::{EndorCode, ObjectRef, Value};
/// NULL is a call-protocol marker and can never escape as a language value.
/// Each Value::Object in a live frame owns one execution root.
#[derive(Debug, Clone)]
pub(crate) enum StackEntry {
Null,
Value(Value),
}
/// Internal activation record, analogous to _PyInterpreterFrame. It has no
/// EndorObject header; introspection objects can be added independently later.
#[derive(Debug)]
pub struct EndorFrame {
pub(crate) function: ObjectRef,
/// Index of the caller in the execution's frame vector, never a pointer.
pub(crate) previous: Option<usize>,
pub(crate) code: ObjectRef,
pub(crate) executable: Arc<EndorCode>,
pub(crate) globals: ObjectRef,
pub(crate) builtins: Option<ObjectRef>,
pub(crate) name: String,
pub(crate) instruction_offset: usize,
pub(crate) current_offset: usize,
pub(crate) localsplus: Vec<Option<Value>>,
pub(crate) stack: Vec<StackEntry>,
}
impl EndorFrame {
pub fn previous(&self) -> Option<usize> {
self.previous
}
pub fn function(&self) -> ObjectRef {
self.function
}
pub fn code(&self) -> ObjectRef {
self.code
}
pub fn globals(&self) -> ObjectRef {
self.globals
}
pub fn builtins(&self) -> Option<ObjectRef> {
self.builtins
}
pub fn instruction_offset(&self) -> usize {
self.instruction_offset
}
pub fn localsplus(&self) -> &[Option<Value>] {
&self.localsplus
}
pub fn stack_depth(&self) -> usize {
self.stack.len()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExecutionLocation {
pub function: String,
pub filename: String,
pub first_line: usize,
pub instruction_offset: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExecutionLimits {
pub max_frames: usize,
pub max_instructions: usize,
}
impl Default for ExecutionLimits {
fn default() -> Self {
Self {
max_frames: 1000,
max_instructions: usize::MAX,
}
}
}