feat(vm): integrate metered strings and native retention for PLN-0176 step 19
This commit is contained in:
@@ -3,7 +3,6 @@ use crate::os::{GameLifecycleEvent, SystemOS};
|
||||
use crate::task::TaskId;
|
||||
use crate::vm_session::VmSession;
|
||||
use crate::{RenderWorkerConfig, RenderWorkerController};
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_hal::app_mode::AppMode;
|
||||
use prometeu_hal::telemetry::{CertificationConfig, TelemetryFrame};
|
||||
use prometeu_hal::{
|
||||
@@ -100,7 +99,7 @@ impl<'a> VmFacade<'a> {
|
||||
self.active_session().map(|session| session.vm.pc())
|
||||
}
|
||||
|
||||
pub fn active_operand_stack_top(&self, n: usize) -> Vec<Value> {
|
||||
pub fn active_operand_stack_top(&self, n: usize) -> prometeu_hal::ValueSnapshot {
|
||||
self.active_session().map(|session| session.vm.operand_stack_top(n)).unwrap_or_default()
|
||||
}
|
||||
|
||||
|
||||
@@ -561,7 +561,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
.ok_or_else(|| VmFault::Panic("Invalid handle".into()))?
|
||||
.clone();
|
||||
match self.fs.read_file(&path) {
|
||||
Ok(data) => ret.push_string(String::from_utf8_lossy(&data).into_owned()),
|
||||
Ok(data) => ret.push_utf8_lossy(&data)?,
|
||||
Err(_) => ret.push_null(),
|
||||
}
|
||||
Ok(())
|
||||
@@ -588,8 +588,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
let path = expect_string(args, 0, "path")?;
|
||||
match self.fs.list_dir(&path) {
|
||||
Ok(entries) => {
|
||||
let names: Vec<String> = entries.into_iter().map(|e| e.name).collect();
|
||||
ret.push_string(names.join(";"));
|
||||
ret.push_joined(entries.iter().map(|entry| entry.name.as_str()), ";")?;
|
||||
}
|
||||
Err(_) => ret.push_null(),
|
||||
}
|
||||
@@ -645,14 +644,14 @@ impl NativeInterface for VmRuntimeHost<'_> {
|
||||
let max_bytes = expect_non_negative_usize(args, 2, "max_bytes")?;
|
||||
if self.current_cartridge_app_mode != AppMode::Game {
|
||||
ret.push_int(MemcardStatus::AccessDenied as i64);
|
||||
ret.push_string(String::new());
|
||||
ret.push_string("")?;
|
||||
ret.push_int(0);
|
||||
return Ok(());
|
||||
}
|
||||
let read =
|
||||
self.memcard.slot_read(self.fs, self.current_app_id, slot, offset, max_bytes);
|
||||
ret.push_int(read.status as i64);
|
||||
ret.push_string(hex_encode(&read.bytes));
|
||||
ret.push_hex(&read.bytes)?;
|
||||
ret.push_int(read.bytes_read as i64);
|
||||
Ok(())
|
||||
}
|
||||
@@ -866,16 +865,6 @@ fn expect_non_negative_usize(args: &[Value], index: usize, field: &str) -> Resul
|
||||
Ok(val as usize)
|
||||
}
|
||||
|
||||
fn hex_encode(bytes: &[u8]) -> String {
|
||||
const HEX: &[u8; 16] = b"0123456789abcdef";
|
||||
let mut out = String::with_capacity(bytes.len() * 2);
|
||||
for &b in bytes {
|
||||
out.push(HEX[(b >> 4) as usize] as char);
|
||||
out.push(HEX[(b & 0x0f) as usize] as char);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn hex_decode(s: &str) -> Result<Vec<u8>, VmFault> {
|
||||
fn nibble(c: u8) -> Option<u8> {
|
||||
match c {
|
||||
|
||||
Reference in New Issue
Block a user