This commit is contained in:
Nilton Constantino
2026-02-02 17:52:20 +00:00
parent f80cb64f66
commit 66a77709f0
50 changed files with 806 additions and 225 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
mod prometeu_hub;
mod window_manager;
pub use prometeu_hub::PrometeuHub;
pub use prometeu_hub::PrometeuHub;
@@ -5,7 +5,7 @@ use crate::log::{LogLevel, LogService, LogSource};
use crate::model::{BankType, Cartridge, Color};
use crate::prometeu_os::NativeInterface;
use crate::telemetry::{CertificationConfig, Certifier, TelemetryFrame};
use crate::virtual_machine::{Value, VirtualMachine, HostReturn, SyscallId, VmFault, expect_int, expect_bool};
use crate::virtual_machine::{expect_bool, expect_int, HostReturn, SyscallId, Value, VirtualMachine, VmFault};
use std::collections::HashMap;
use std::time::Instant;
@@ -1,5 +1,5 @@
use crate::virtual_machine::opcode_spec::{OpCodeSpecExt, OpcodeSpec};
use prometeu_bytecode::opcode::OpCode;
use crate::virtual_machine::opcode_spec::{OpcodeSpec, OpCodeSpecExt};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecodeError {
@@ -1,6 +1,6 @@
use crate::virtual_machine::call_frame::CallFrame;
use prometeu_bytecode::v0::FunctionMeta;
use prometeu_bytecode::abi::{TrapInfo, TRAP_INVALID_LOCAL};
use prometeu_bytecode::v0::FunctionMeta;
/// Computes the absolute stack index for the start of the current frame's locals (including args).
pub fn local_base(frame: &CallFrame) -> usize {
@@ -10,11 +10,11 @@ pub mod verifier;
use crate::hardware::HardwareBridge;
pub use program::ProgramImage;
pub use prometeu_bytecode::abi::TrapInfo;
pub use prometeu_bytecode::opcode::OpCode;
pub use value::Value;
pub use virtual_machine::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
pub use prometeu_bytecode::abi::TrapInfo;
pub use verifier::VerifierError;
pub use virtual_machine::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
pub type SyscallId = u32;
@@ -1,8 +1,8 @@
use crate::virtual_machine::Value;
use prometeu_bytecode::v0::{FunctionMeta, DebugInfo, BytecodeModule, ConstantPoolEntry};
use prometeu_bytecode::abi::TrapInfo;
use std::sync::Arc;
use prometeu_bytecode::v0::{BytecodeModule, ConstantPoolEntry, DebugInfo, Export, FunctionMeta};
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Debug, Clone, Default)]
pub struct ProgramImage {
@@ -91,3 +91,33 @@ impl From<BytecodeModule> for ProgramImage {
)
}
}
impl From<ProgramImage> for BytecodeModule {
fn from(program: ProgramImage) -> Self {
let const_pool = program.constant_pool.iter().map(|v| match v {
Value::Null => ConstantPoolEntry::Null,
Value::Int64(v) => ConstantPoolEntry::Int64(*v),
Value::Float(v) => ConstantPoolEntry::Float64(*v),
Value::Boolean(v) => ConstantPoolEntry::Boolean(*v),
Value::String(v) => ConstantPoolEntry::String(v.clone()),
Value::Int32(v) => ConstantPoolEntry::Int32(*v),
Value::Bounded(v) => ConstantPoolEntry::Int32(*v as i32),
Value::Gate(_) => ConstantPoolEntry::Null,
}).collect();
let exports = program.exports.iter().map(|(symbol, &func_idx)| Export {
symbol: symbol.clone(),
func_idx,
}).collect();
BytecodeModule {
version: 0,
const_pool,
functions: program.functions.as_ref().to_vec(),
code: program.rom.as_ref().to_vec(),
debug_info: program.debug_info.clone(),
exports,
imports: vec![],
}
}
}
@@ -1,7 +1,7 @@
use prometeu_bytecode::v0::FunctionMeta;
use crate::virtual_machine::bytecode::decoder::{decode_at, DecodeError};
use prometeu_bytecode::opcode::OpCode;
use std::collections::{HashMap, VecDeque, HashSet};
use prometeu_bytecode::v0::FunctionMeta;
use std::collections::{HashMap, HashSet, VecDeque};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum VerifierError {
@@ -3,8 +3,8 @@ use crate::virtual_machine::call_frame::CallFrame;
use crate::virtual_machine::scope_frame::ScopeFrame;
use crate::virtual_machine::value::Value;
use crate::virtual_machine::{NativeInterface, ProgramImage, VmInitError};
use prometeu_bytecode::abi::{TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_OOB, TRAP_TYPE};
use prometeu_bytecode::opcode::OpCode;
use prometeu_bytecode::abi::{TrapInfo, TRAP_OOB, TRAP_DIV_ZERO, TRAP_TYPE, TRAP_INVALID_FUNC, TRAP_BAD_RET_SLOTS};
/// Reason why the Virtual Machine stopped execution during a specific run.
/// This allows the system to decide if it should continue execution in the next tick
@@ -914,10 +914,10 @@ impl VirtualMachine {
#[cfg(test)]
mod tests {
use super::*;
use prometeu_bytecode::v0::FunctionMeta;
use prometeu_bytecode::abi::SourceSpan;
use crate::hardware::HardwareBridge;
use crate::virtual_machine::{Value, HostReturn, VmFault, expect_int};
use crate::virtual_machine::{expect_int, HostReturn, Value, VmFault};
use prometeu_bytecode::abi::SourceSpan;
use prometeu_bytecode::v0::FunctionMeta;
struct MockNative;
impl NativeInterface for MockNative {
+4 -4
View File
@@ -1,11 +1,11 @@
use prometeu_core::virtual_machine::{VirtualMachine, LogicalFrameEndingReason};
use prometeu_core::hardware::HardwareBridge;
use prometeu_core::Hardware;
use prometeu_core::virtual_machine::HostReturn;
use prometeu_core::virtual_machine::NativeInterface;
use prometeu_core::virtual_machine::Value;
use prometeu_core::virtual_machine::HostReturn;
use std::path::Path;
use prometeu_core::virtual_machine::{LogicalFrameEndingReason, VirtualMachine};
use prometeu_core::Hardware;
use std::fs;
use std::path::Path;
struct MockNative;
impl NativeInterface for MockNative {