updated DSX tasks/build
This commit is contained in:
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"emulator/dsa_emulator", "emulator/dsa_gui", "emulator/dsa_cli",
|
"emulator/dsa_emulator", "emulator/dsa_gui", "emulator/dsa_cli",
|
||||||
"libraries/common", "libraries/dsa_formats",
|
"libraries/common", "libraries/dsa_formats", "libraries/zxq5_egui", "libraries/dsa_tasks",
|
||||||
"tooling/assembler", "tooling/disassembler", "tooling/linker", "tooling/compiler",
|
"tooling/assembler", "tooling/disassembler", "tooling/linker",
|
||||||
"tooling/dsx_build", "tooling/dsx_server", "tooling/dsx_client", "libraries/dsa_tasks", "libraries/zxq5_egui", "tooling/dsfl_compiler"]
|
"tooling/dscs_compiler", "tooling/dsfl_compiler", "tooling/bf_compiler",
|
||||||
|
"tooling/dsx_build", "tooling/dsx_server", "tooling/dsx_client"
|
||||||
|
]
|
||||||
|
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::AgentSink::{Callback, Channel};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{Arc, mpsc};
|
use std::sync::{Arc, mpsc};
|
||||||
use crate::AgentSink::{Callback, Channel};
|
|
||||||
|
|
||||||
pub struct ProcessAgent {
|
pub struct ProcessAgent {
|
||||||
sink: Arc<AgentSink>,
|
sink: Arc<AgentSink>,
|
||||||
@@ -8,17 +8,23 @@ pub struct ProcessAgent {
|
|||||||
|
|
||||||
impl ProcessAgent {
|
impl ProcessAgent {
|
||||||
pub fn new(tx: mpsc::Sender<String>) -> Self {
|
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 {
|
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>) {
|
pub fn log(&self, msg: impl Into<String>) {
|
||||||
let msg = msg.into();
|
let msg = msg.into();
|
||||||
match &*self.sink {
|
match &*self.sink {
|
||||||
Channel(tx) => { let _ = tx.send(msg); }
|
Channel(tx) => {
|
||||||
|
let _ = tx.send(msg);
|
||||||
|
}
|
||||||
Callback(f) => f(&msg),
|
Callback(f) => f(&msg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,10 +32,11 @@ impl ProcessAgent {
|
|||||||
|
|
||||||
pub enum AgentSink {
|
pub enum AgentSink {
|
||||||
Channel(mpsc::Sender<String>),
|
Channel(mpsc::Sender<String>),
|
||||||
Callback(Box<dyn Fn(&str) + Send + Sync>)
|
Callback(Box<dyn Fn(&str) + Send + Sync>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TraceableProcess: Debug + Send + 'static {
|
pub trait TraceableProcess: Debug + Send + 'static {
|
||||||
|
type Input: Send + 'static;
|
||||||
type Output: Send + 'static;
|
type Output: Send + 'static;
|
||||||
type Error: std::error::Error + Send + 'static;
|
type Error: std::error::Error + Send + 'static;
|
||||||
|
|
||||||
@@ -37,16 +44,21 @@ pub trait TraceableProcess: Debug + Send + 'static {
|
|||||||
format!("{self:?}")
|
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
|
where
|
||||||
Self: Sized
|
Self: Sized,
|
||||||
{
|
{
|
||||||
Self::run(
|
Self::run(
|
||||||
Box::new(self),
|
Box::new(self),
|
||||||
ProcessAgent::new_sync(|line| println!("{line}") )
|
input,
|
||||||
|
ProcessAgent::new_sync(|line| println!("{line}")),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,3 +5,10 @@ version.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[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" }
|
||||||
@@ -1,14 +1,61 @@
|
|||||||
pub fn add(left: u64, right: u64) -> u64 {
|
use dsa_formats::binary_dse::DseExecutable;
|
||||||
left + right
|
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)]
|
impl DsxBuildError {
|
||||||
mod tests {
|
fn new(msg: impl Into<String>) -> DsxBuildError {
|
||||||
use super::*;
|
DsxBuildError::Generic(msg.into())
|
||||||
|
}
|
||||||
#[test]
|
}
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
impl std::error::Error for DsxBuildError {}
|
||||||
assert_eq!(result, 4);
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user