implement PLN-0034 internal allocation evidence

This commit is contained in:
2026-04-20 08:50:01 +01:00
parent 09821cf9cc
commit 811af09ea7
13 changed files with 125 additions and 8 deletions
+1 -1
View File
@@ -21,4 +21,4 @@ pub use disassembler::disassemble;
pub use layout::{compute_function_layouts, FunctionLayout};
pub use model::{BytecodeLoader, FunctionMeta, LoadError, SyscallDecl};
pub use program_image::ProgramImage;
pub use value::{HeapRef, Value};
pub use value::{string_materialization_count, HeapRef, Value};
@@ -75,7 +75,7 @@ impl From<BytecodeModule> for ProgramImage {
ConstantPoolEntry::Int64(v) => Value::Int64(*v),
ConstantPoolEntry::Float64(v) => Value::Float(*v),
ConstantPoolEntry::Boolean(v) => Value::Boolean(*v),
ConstantPoolEntry::String(v) => Value::String(v.clone().into()),
ConstantPoolEntry::String(v) => Value::string(v.clone()),
ConstantPoolEntry::Int32(v) => Value::Int32(*v),
})
.collect();
@@ -1,8 +1,11 @@
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fmt::Write;
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
use std::sync::Arc;
static STRING_MATERIALIZATION_COUNT: AtomicU64 = AtomicU64::new(0);
/// Opaque handle that references an object stored in the VM heap.
///
/// This is an index-based handle. It does not imply ownership and carries
@@ -76,6 +79,14 @@ impl PartialOrd for Value {
}
impl Value {
pub fn string<S>(value: S) -> Self
where
S: Into<Arc<str>>,
{
STRING_MATERIALIZATION_COUNT.fetch_add(1, AtomicOrdering::Relaxed);
Value::String(value.into())
}
pub fn as_float(&self) -> Option<f64> {
match self {
Value::Int32(i) => Some(*i as f64),
@@ -137,6 +148,10 @@ impl Value {
}
}
pub fn string_materialization_count() -> u64 {
STRING_MATERIALIZATION_COUNT.load(AtomicOrdering::Relaxed)
}
#[cfg(test)]
mod tests {
use super::*;