diff --git a/Cargo.toml b/Cargo.toml index 528bf3b..674d39d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/libraries/dsa_tasks/src/lib.rs b/libraries/dsa_tasks/src/lib.rs index 90bfae3..4a071c0 100644 --- a/libraries/dsa_tasks/src/lib.rs +++ b/libraries/dsa_tasks/src/lib.rs @@ -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, @@ -8,17 +8,23 @@ pub struct ProcessAgent { impl ProcessAgent { pub fn new(tx: mpsc::Sender) -> 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) { 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), - Callback(Box) + Callback(Box), } 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, ctx: ProcessAgent) -> Result; + fn run( + self: Box, + input: impl Into, + ctx: ProcessAgent, + ) -> Result; /// - fn run_sync(self) -> Result + fn run_sync(self, input: impl Into) -> Result where - Self: Sized + Self: Sized, { Self::run( Box::new(self), - ProcessAgent::new_sync(|line| println!("{line}") ) + input, + ProcessAgent::new_sync(|line| println!("{line}")), ) } -} \ No newline at end of file +} diff --git a/tooling/dsx_build/Cargo.toml b/tooling/dsx_build/Cargo.toml index fc9b25b..ed611fe 100644 --- a/tooling/dsx_build/Cargo.toml +++ b/tooling/dsx_build/Cargo.toml @@ -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" } \ No newline at end of file diff --git a/tooling/dsx_build/src/lib.rs b/tooling/dsx_build/src/lib.rs index b93cf3f..a8aff0f 100644 --- a/tooling/dsx_build/src/lib.rs +++ b/tooling/dsx_build/src/lib.rs @@ -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) -> 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, + input: impl Into, + ctx: ProcessAgent, + ) -> Result { + + 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() + } } }