feat: add managed types, source classes and scoped native calls
This commit is contained in:
@@ -51,6 +51,19 @@ impl CompareOp {
|
||||
/// Rust Drop releases host resources when the payload is destroyed.
|
||||
/// Equal payloads must provide compatible hashes, or reject hashing explicitly.
|
||||
pub trait ObjectPayload: Any + fmt::Debug + Send + Sync {
|
||||
/// Shared-reference facades may expose the current referent's type. The
|
||||
/// referent must also be held by traced managed edges. Ordinary objects
|
||||
/// keep their immutable header type; this does not change inheritance.
|
||||
fn type_target(&self, _store: &crate::ObjectStore) -> Result<Option<ObjectRef>, VmError> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Optional context-aware native entry. The VM clones this dispatcher before
|
||||
/// borrowing the store mutably; callbacks never borrow a live payload.
|
||||
fn native_callable(&self) -> Option<std::sync::Arc<dyn crate::NativeCallable>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
/// A diagnostic label only, with no language type or inheritance semantics.
|
||||
@@ -104,6 +117,18 @@ pub trait ObjectPayload: Any + fmt::Debug + Send + Sync {
|
||||
fn assign_from(&self, _source: &dyn ObjectPayload) -> Result<bool, VmError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// Optional managed shared-reference assignment. Return a built-in Cell
|
||||
/// owned by this payload after validating the source and any domain cycles.
|
||||
/// The store writes the source object to the Cell transactionally. This
|
||||
/// keeps mutable edges inside the GC graph, unlike native assign_from.
|
||||
fn assignment_cell(
|
||||
&self,
|
||||
_source: ObjectRef,
|
||||
_store: &crate::ObjectStore,
|
||||
) -> Result<Option<ObjectRef>, VmError> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -166,15 +191,25 @@ impl ObjectPayload for EndorNativeFunctionObject {
|
||||
}
|
||||
}
|
||||
|
||||
/// Common runtime state. There is deliberately no language type pointer.
|
||||
/// Common runtime state. Embedders may attach an immutable managed type.
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectHeader {
|
||||
pub(crate) identity: ObjectRef,
|
||||
pub(crate) strong_refs: usize,
|
||||
pub(crate) external_refs: usize,
|
||||
pub(crate) change_version: u64,
|
||||
pub(crate) type_object: Option<ObjectRef>,
|
||||
}
|
||||
|
||||
impl ObjectHeader {
|
||||
pub fn type_object(&self) -> Option<ObjectRef> {
|
||||
self.type_object
|
||||
}
|
||||
|
||||
pub fn change_version(&self) -> u64 {
|
||||
self.change_version
|
||||
}
|
||||
|
||||
pub fn identity(&self) -> ObjectRef {
|
||||
self.identity
|
||||
}
|
||||
@@ -190,7 +225,7 @@ impl ObjectHeader {
|
||||
}
|
||||
|
||||
/// Runtime object foundation, analogous in role to CPython's common object
|
||||
/// structure, without its type system or binary layout. The heap boxes this
|
||||
/// structure, without its binary layout. The heap boxes this
|
||||
/// structure so its address remains stable throughout its lifetime.
|
||||
#[derive(Debug)]
|
||||
pub struct EndorObject {
|
||||
@@ -213,6 +248,9 @@ impl EndorObject {
|
||||
/// allocation and refreshed on VM-managed payload replacement; attributes
|
||||
/// are maintained by the VM's reference accounting.
|
||||
pub fn trace(&self, visit: &mut dyn FnMut(ObjectRef)) {
|
||||
if let Some(reference) = self.header.type_object {
|
||||
visit(reference);
|
||||
}
|
||||
for reference in &self.payload_edges {
|
||||
visit(*reference);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user