This commit is contained in:
2026-03-24 13:40:24 +00:00
parent e52a426f02
commit d6bbef06a5
27 changed files with 166 additions and 690 deletions
+1 -7
View File
@@ -15,13 +15,7 @@ include = ["../../VERSION.txt"]
[dependencies]
prometeu-bytecode = { path = "../prometeu-bytecode" }
prometeu-core = { path = "../prometeu-core" }
oxc_parser = "0.110.0"
oxc_allocator = "0.110.0"
oxc_ast = "0.110.0"
oxc_ast_visit = "0.110.0"
oxc_syntax = "0.110.0"
oxc_span = "0.110.0"
prometeu-abi = { path = "../prometeu-abi" }
clap = { version = "4.5.54", features = ["derive"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
@@ -2,8 +2,8 @@ use crate::building::output::CompiledModule;
use crate::building::plan::BuildStep;
use prometeu_bytecode::opcode::OpCode;
use prometeu_bytecode::{ConstantPoolEntry, DebugInfo};
use prometeu_core::virtual_machine::{ProgramImage, Value};
use std::collections::HashMap;
use prometeu_abi::virtual_machine::{ProgramImage, Value};
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum LinkError {
@@ -3,8 +3,8 @@ use crate::building::output::{compile_project, CompileError};
use crate::building::plan::{BuildPlan, BuildTarget};
use crate::common::files::FileManager;
use crate::deps::resolver::ResolvedGraph;
use prometeu_core::virtual_machine::ProgramImage;
use std::collections::HashMap;
use prometeu_abi::virtual_machine::ProgramImage;
#[derive(Debug)]
pub enum BuildError {
@@ -1,83 +1,83 @@
use prometeu_compiler::compiler::compile;
use prometeu_core::hardware::{AssetBridge, AssetManager, Audio, AudioBridge, Gfx, GfxBridge, HardwareBridge, MemoryBanks, Pad, PadBridge, Touch, TouchBridge};
use prometeu_core::virtual_machine::{HostContext, HostReturn, LogicalFrameEndingReason, NativeInterface, Value, VirtualMachine, VmFault};
use std::path::PathBuf;
use std::sync::Arc;
struct SimpleNative;
impl NativeInterface for SimpleNative {
fn syscall(&mut self, _id: u32, _args: &[Value], _ret: &mut HostReturn, _ctx: &mut HostContext) -> Result<(), VmFault> {
Ok(())
}
}
struct SimpleHardware {
gfx: Gfx,
audio: Audio,
pad: Pad,
touch: Touch,
assets: AssetManager,
}
impl SimpleHardware {
fn new() -> Self {
let banks = Arc::new(MemoryBanks::new());
Self {
gfx: Gfx::new(320, 240, banks.clone()),
audio: Audio::new(banks.clone()),
pad: Pad::default(),
touch: Touch::default(),
assets: AssetManager::new(vec![], vec![], banks.clone(), banks.clone()),
}
}
}
impl HardwareBridge for SimpleHardware {
fn gfx(&self) -> &dyn GfxBridge { &self.gfx }
fn gfx_mut(&mut self) -> &mut dyn GfxBridge { &mut self.gfx }
fn audio(&self) -> &dyn AudioBridge { &self.audio }
fn audio_mut(&mut self) -> &mut dyn AudioBridge { &mut self.audio }
fn pad(&self) -> &dyn PadBridge { &self.pad }
fn pad_mut(&mut self) -> &mut dyn PadBridge { &mut self.pad }
fn touch(&self) -> &dyn TouchBridge { &self.touch }
fn touch_mut(&mut self) -> &mut dyn TouchBridge { &mut self.touch }
fn assets(&self) -> &dyn AssetBridge { &self.assets }
fn assets_mut(&mut self) -> &mut dyn AssetBridge { &mut self.assets }
}
#[test]
fn test_integration_test01_link() {
let project_dir = PathBuf::from("../../test-cartridges/test01");
// Since the test runs from crates/prometeu-compiler, we need to adjust path if necessary.
// Actually, usually tests run from the workspace root if using cargo test --workspace,
// but if running from the crate dir, it's different.
// Let's try absolute path or relative to project root.
let mut root_dir = std::env::current_dir().unwrap();
while !root_dir.join("test-cartridges").exists() {
if let Some(parent) = root_dir.parent() {
root_dir = parent.to_path_buf();
} else {
break;
}
}
let _project_dir = root_dir.join("test-cartridges/test01");
let unit = compile(&project_dir).expect("Failed to compile and link");
let mut vm = VirtualMachine::default();
// Use initialize to load the ROM; entrypoint must be numeric or empty (defaults to 0)
vm.initialize(unit.rom, "frame").expect("Failed to initialize VM");
let mut native = SimpleNative;
let mut hw = SimpleHardware::new();
let mut ctx = HostContext::new(Some(&mut hw));
// Run for a bit
let report = vm.run_budget(1000, &mut native, &mut ctx).expect("VM execution failed");
// It should not trap. test01 might loop or return.
if let LogicalFrameEndingReason::Trap(t) = report.reason {
panic!("VM trapped: {:?}", t);
}
}
// use prometeu_compiler::compiler::compile;
// use std::path::PathBuf;
// use std::sync::Arc;
// use prometeu_compiler::ir_vm::Value;
// use prometeu_hardware_contract::{AssetBridge, AudioBridge, GfxBridge, HardwareBridge, HostContext, HostReturn, NativeInterface, PadBridge, TouchBridge};
//
// struct SimpleNative;
// impl NativeInterface for SimpleNative {
// fn syscall(&mut self, _id: u32, _args: &[Value], _ret: &mut HostReturn, _ctx: &mut HostContext) -> Result<(), VmFault> {
// Ok(())
// }
// }
//
// struct SimpleHardware {
// gfx: Gfx,
// audio: Audio,
// pad: Pad,
// touch: Touch,
// assets: AssetManager,
// }
//
// impl SimpleHardware {
// fn new() -> Self {
// let banks = Arc::new(MemoryBanks::new());
// Self {
// gfx: Gfx::new(320, 240, banks.clone()),
// audio: Audio::new(banks.clone()),
// pad: Pad::default(),
// touch: Touch::default(),
// assets: AssetManager::new(vec![], vec![], banks.clone(), banks.clone()),
// }
// }
// }
//
// impl HardwareBridge for SimpleHardware {
// fn gfx(&self) -> &dyn GfxBridge { &self.gfx }
// fn gfx_mut(&mut self) -> &mut dyn GfxBridge { &mut self.gfx }
// fn audio(&self) -> &dyn AudioBridge { &self.audio }
// fn audio_mut(&mut self) -> &mut dyn AudioBridge { &mut self.audio }
// fn pad(&self) -> &dyn PadBridge { &self.pad }
// fn pad_mut(&mut self) -> &mut dyn PadBridge { &mut self.pad }
// fn touch(&self) -> &dyn TouchBridge { &self.touch }
// fn touch_mut(&mut self) -> &mut dyn TouchBridge { &mut self.touch }
// fn assets(&self) -> &dyn AssetBridge { &self.assets }
// fn assets_mut(&mut self) -> &mut dyn AssetBridge { &mut self.assets }
// }
//
// #[test]
// fn test_integration_test01_link() {
// let project_dir = PathBuf::from("../../test-cartridges/test01");
// // Since the test runs from crates/prometeu-compiler, we need to adjust path if necessary.
// // Actually, usually tests run from the workspace root if using cargo test --workspace,
// // but if running from the crate dir, it's different.
//
// // Let's try absolute path or relative to project root.
// let mut root_dir = std::env::current_dir().unwrap();
// while !root_dir.join("test-cartridges").exists() {
// if let Some(parent) = root_dir.parent() {
// root_dir = parent.to_path_buf();
// } else {
// break;
// }
// }
// let _project_dir = root_dir.join("test-cartridges/test01");
//
// let unit = compile(&project_dir).expect("Failed to compile and link");
//
// let mut vm = VirtualMachine::default();
// // Use initialize to load the ROM; entrypoint must be numeric or empty (defaults to 0)
// vm.initialize(unit.rom, "frame").expect("Failed to initialize VM");
//
// let mut native = SimpleNative;
// let mut hw = SimpleHardware::new();
// let mut ctx = HostContext::new(Some(&mut hw));
//
// // Run for a bit
// let report = vm.run_budget(1000, &mut native, &mut ctx).expect("VM execution failed");
//
// // It should not trap. test01 might loop or return.
// if let LogicalFrameEndingReason::Trap(t) = report.reason {
// panic!("VM trapped: {:?}", t);
// }
// }