updated DSX tasks/build

This commit is contained in:
2026-08-09 09:17:01 +01:00
parent e3a87ca908
commit e20bf7d08f
4 changed files with 91 additions and 23 deletions
+5 -3
View File
@@ -1,9 +1,11 @@
[workspace]
members = [
"emulator/dsa_emulator", "emulator/dsa_gui", "emulator/dsa_cli",
"libraries/common", "libraries/dsa_formats",
"tooling/assembler", "tooling/disassembler", "tooling/linker", "tooling/compiler",
"tooling/dsx_build", "tooling/dsx_server", "tooling/dsx_client", "libraries/dsa_tasks", "libraries/zxq5_egui", "tooling/dsfl_compiler"]
"libraries/common", "libraries/dsa_formats", "libraries/zxq5_egui", "libraries/dsa_tasks",
"tooling/assembler", "tooling/disassembler", "tooling/linker",
"tooling/dscs_compiler", "tooling/dsfl_compiler", "tooling/bf_compiler",
"tooling/dsx_build", "tooling/dsx_server", "tooling/dsx_client"
]
resolver = "3"
+21 -9
View File
@@ -1,6 +1,6 @@
use crate::AgentSink::{Callback, Channel};
use std::fmt::Debug;
use std::sync::{Arc, mpsc};
use crate::AgentSink::{Callback, Channel};
pub struct ProcessAgent {
sink: Arc<AgentSink>,
@@ -8,17 +8,23 @@ pub struct ProcessAgent {
impl ProcessAgent {
pub fn new(tx: mpsc::Sender<String>) -> Self {
Self { sink: Arc::new(Channel(tx)) }
Self {
sink: Arc::new(Channel(tx)),
}
}
fn new_sync(f: impl Fn(&str) + Send + Sync + 'static) -> Self {
Self { sink: Arc::new(Callback(Box::new(f))) }
Self {
sink: Arc::new(Callback(Box::new(f))),
}
}
pub fn log(&self, msg: impl Into<String>) {
let msg = msg.into();
match &*self.sink {
Channel(tx) => { let _ = tx.send(msg); }
Channel(tx) => {
let _ = tx.send(msg);
}
Callback(f) => f(&msg),
}
}
@@ -26,10 +32,11 @@ impl ProcessAgent {
pub enum AgentSink {
Channel(mpsc::Sender<String>),
Callback(Box<dyn Fn(&str) + Send + Sync>)
Callback(Box<dyn Fn(&str) + Send + Sync>),
}
pub trait TraceableProcess: Debug + Send + 'static {
type Input: Send + 'static;
type Output: Send + 'static;
type Error: std::error::Error + Send + 'static;
@@ -37,16 +44,21 @@ pub trait TraceableProcess: Debug + Send + 'static {
format!("{self:?}")
}
fn run(self: Box<Self>, ctx: ProcessAgent) -> Result<Self::Output, Self::Error>;
fn run(
self: Box<Self>,
input: impl Into<Self::Input>,
ctx: ProcessAgent,
) -> Result<Self::Output, Self::Error>;
///
fn run_sync(self) -> Result<Self::Output, Self::Error>
fn run_sync(self, input: impl Into<Self::Input>) -> Result<Self::Output, Self::Error>
where
Self: Sized
Self: Sized,
{
Self::run(
Box::new(self),
ProcessAgent::new_sync(|line| println!("{line}") )
input,
ProcessAgent::new_sync(|line| println!("{line}")),
)
}
}
+7
View File
@@ -5,3 +5,10 @@ version.workspace = true
authors.workspace = true
[dependencies]
clap = { version = "4.6.0", features = ["derive"] }
common = { path = "../../libraries/common" }
dsa_formats = { path = "../../libraries/dsa_formats" }
dsa_tasks = { path = "../../libraries/dsa_tasks" }
assembler = { path = "../assembler" }
dsfl_compiler = { path = "../dsfl_compiler" }
bf_compiler = { path = "../bf_compiler" }
+57 -10
View File
@@ -1,14 +1,61 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
use dsa_formats::binary_dse::DseExecutable;
use dsa_tasks::{ProcessAgent, TraceableProcess};
use dsabf_compiler::BfCompiler;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
#[derive(Debug)]
pub struct DsxBuilder;
impl DsxBuilder {}
#[derive(Debug)]
pub enum DsxBuildError {
Generic(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
impl DsxBuildError {
fn new(msg: impl Into<String>) -> DsxBuildError {
DsxBuildError::Generic(msg.into())
}
}
impl std::error::Error for DsxBuildError {}
impl Display for DsxBuildError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}
impl TraceableProcess for DsxBuilder {
type Input = PathBuf;
type Output = DseExecutable;
type Error = DsxBuildError;
fn run(
self: Box<Self>,
input: impl Into<Self::Input>,
ctx: ProcessAgent,
) -> Result<Self::Output, Self::Error> {
if input.into() == FileType::Bf {
let bf_src = std::fs::read_to_string(&args.input_path).unwrap();
let result = BfCompiler::new(
args.input_path
.file_stem()
.unwrap()
.to_string_lossy()
.to_string(),
)
.run_sync(bf_src)
.unwrap();
println!("Successfully compiled {}", args.input_path.display());
println!("Writing result to {}", args.output_path.display());
std::fs::write(&args.output_path, result).unwrap();
BfCompiler::new()
}
}
}