progress on DSSML compiler
This commit is contained in:
@@ -19,18 +19,19 @@ dsa_tasks = { path = "../../libraries/dsa_tasks" }
|
||||
|
||||
zxq5_egui = { path = "../../libraries/zxq5_egui" }
|
||||
assembler = { path = "../../tooling/assembler" }
|
||||
dscs_compiler = { path = "../../tooling/dscs_compiler"}
|
||||
dsfl_compiler = { path = "../../tooling/dsfl_compiler" }
|
||||
dsa_emulator = { version = "0.3.0", path = "../dsa_emulator" }
|
||||
disassembler = { version = "0.3.0", path = "../../tooling/disassembler" }
|
||||
|
||||
clap = { version = "4.5.60", features = ["derive"] }
|
||||
ron = "0.12.0"
|
||||
egui = "0.35.0"
|
||||
eframe = "0.35.0"
|
||||
egui_tiles = "0.16.0"
|
||||
egui_code_editor = "0.3.7"
|
||||
egui_file = "0.27.0"
|
||||
egui_extras = "0.35.0"
|
||||
egui = "0.36.1"
|
||||
eframe = "0.36.1"
|
||||
egui_tiles = "0.17.1"
|
||||
egui_code_editor = "0.4.1"
|
||||
egui_file = "0.28.0"
|
||||
egui_extras = "0.36.1"
|
||||
|
||||
egui-file-dialog = "0.14.1"
|
||||
egui_commonmark = { version = "0.24.0", features = ["better_syntax_highlighting", "macros"] }
|
||||
egui-file-dialog = "0.15.0"
|
||||
egui_commonmark = { version = "0.25.0", features = ["better_syntax_highlighting", "macros"] }
|
||||
@@ -29,6 +29,36 @@ impl ProcessSpawner {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProcessJob<Proc, OnComplete>
|
||||
where
|
||||
Proc: TraceableProcess,
|
||||
OnComplete: FnOnce(Result<Proc::Output, Proc::Error>) -> Action + Send + 'static,
|
||||
{
|
||||
input: Proc::Input,
|
||||
proc: Proc,
|
||||
on_complete: OnComplete,
|
||||
}
|
||||
|
||||
impl<Proc, OnComplete> ProcessJob<Proc, OnComplete>
|
||||
where
|
||||
Proc: TraceableProcess,
|
||||
OnComplete: FnOnce(Result<Proc::Output, Proc::Error>) -> Action + Send + 'static,
|
||||
{
|
||||
pub fn new(input: Proc::Input, proc: Proc, on_complete: OnComplete) -> Self {
|
||||
Self {
|
||||
input,
|
||||
proc,
|
||||
on_complete,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_action(self) -> Action {
|
||||
Action::SpawnProcess(ProcessSpawner::new(move |pm| {
|
||||
pm.spawn(self.proc.label(), self.proc, self.input, self.on_complete)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ProcessHandle {
|
||||
id: usize,
|
||||
name: String,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::state::Action;
|
||||
use crate::state::DataSource::Data;
|
||||
use crate::ui::process_manager::ProcessSpawner;
|
||||
use crate::ui::process_manager::{ProcessJob, ProcessSpawner};
|
||||
use crate::ui::tiles::TilePane;
|
||||
use crate::ui::tiles::editor::syntax::SyntaxFrom;
|
||||
use assembler::prelude::Assembler;
|
||||
@@ -12,6 +12,7 @@ use egui_tiles::TileId;
|
||||
use std::any::Any;
|
||||
use std::fs::File;
|
||||
use std::path::{Path, PathBuf};
|
||||
use dscs_compiler::DSCSCompiler;
|
||||
use theme::THEME;
|
||||
use zxq5_egui::buttons::PaddedWidget;
|
||||
|
||||
@@ -67,32 +68,48 @@ impl Editor {
|
||||
&mut self.buffer
|
||||
}
|
||||
|
||||
// pub fn get_build_command(file_path: PathBuf) -> impl TraceableProcess {
|
||||
// let filename = file_path.file_name().unwrap().to_str().unwrap();
|
||||
// match file_path.extension().unwrap().to_str().unwrap() {
|
||||
// "dsa" => Assembler::new(filename),
|
||||
// "dsfl" => DsflCompiler::new(filename),
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn create_build_action(
|
||||
&self,
|
||||
filename: PathBuf,
|
||||
on_complete: impl FnOnce(DseExecutable) -> Action + Send + 'static,
|
||||
) -> Action {
|
||||
ProcessSpawner::new(move |pm| {
|
||||
let builder = Assembler::new(filename.file_name().unwrap().to_str().unwrap());
|
||||
pm.spawn(
|
||||
builder.label(),
|
||||
builder,
|
||||
filename,
|
||||
move |result| match result {
|
||||
Ok(bin) => on_complete(bin),
|
||||
Err(e) => Action::ShowError(e.to_string()),
|
||||
},
|
||||
);
|
||||
})
|
||||
.into_action()
|
||||
) -> Option<Action> {
|
||||
let Some(ext) = filename.extension() else {
|
||||
return None;
|
||||
};
|
||||
|
||||
match ext.to_str().unwrap() {
|
||||
"dsa" => {
|
||||
let builder = Assembler::new(filename.file_name().unwrap().to_str().unwrap());
|
||||
Some(ProcessJob::new(
|
||||
filename, builder,
|
||||
move |result| match result {
|
||||
Ok(bin) => on_complete(bin),
|
||||
Err(e) => Action::ShowError(e.to_string()),
|
||||
}
|
||||
).into_action())
|
||||
},
|
||||
"dsc" => {
|
||||
let builder = DSCSCompiler::new(filename.display().to_string(), false);
|
||||
Some(ProcessJob::new(
|
||||
filename.clone(), builder,
|
||||
move |result| match result {
|
||||
Ok(bin) => {
|
||||
let output = filename.with_extension("dsa");
|
||||
std::fs::write(&output, &bin).expect("Failed to write output");
|
||||
Action::OpenFile(output)
|
||||
},
|
||||
Err(e) => Action::ShowError(e.to_string()),
|
||||
}
|
||||
).into_action())
|
||||
|
||||
}
|
||||
_ => {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,9 +132,9 @@ impl TilePane for Editor {
|
||||
return;
|
||||
};
|
||||
|
||||
action = Some(self.create_build_action(filename, |res| {
|
||||
action = self.create_build_action(filename, |res| {
|
||||
Action::LoadBinary(Data(res.to_memory_image()))
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
if PaddedWidget::button("Build").ui(ui).clicked() {
|
||||
@@ -126,12 +143,12 @@ impl TilePane for Editor {
|
||||
return;
|
||||
};
|
||||
|
||||
action = Some(self.create_build_action(filename.clone(), move |res| {
|
||||
action = self.create_build_action(filename.clone(), move |res| {
|
||||
let filename = filename.with_extension("dsb");
|
||||
let mut writer = File::create(&filename).unwrap();
|
||||
res.write(&mut writer).unwrap();
|
||||
Action::OpenFile(filename)
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
PaddedWidget::label(
|
||||
|
||||
Reference in New Issue
Block a user