Skip to content

Commit

Permalink
Starting pyo3 generator
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Nov 6, 2023
1 parent 32d32de commit 422c271
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 44 deletions.
46 changes: 24 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"ligen/utils",
"ligen/traits",
"ecosystem/python/parser",
"ecosystem/python/exporter",
"ecosystem/rust/cargo",
"ecosystem/rust/example",
# "ecosystem/rust/exporter",
Expand All @@ -29,28 +30,29 @@ documentation = "https://docs.rs/ligen"
readme = "README.md"

[workspace.dependencies]
ligen = { path = "ligen" }
ligen-common = { path = "ligen/common" }
ligen-ir = { path = "ligen/ir" }
ligen-macro = { path = "ligen/macro" }
ligen-parsing = { path = "ligen/parsing" }
ligen-traits = { path = "ligen/traits" }
ligen-utils = { path = "ligen/utils" }
#ligen-c = { path = "ecosystem/c/generator" }
#ligen-cmake = { path = "ecosystem/c/cmake" }
ligen-python-parser = { path = "ecosystem/python/parser" }
#ligen-rust-exporter = { path = "ecosystem/rust/exporter" }
ligen-rust-parser = { path = "ecosystem/rust/parser" }
ligen-cargo = { path = "ecosystem/rust/cargo" }
ligen-gui-runtime = { path = "tools/editor/dependencies/gui-runtime" }
serde = { version = "1", features = ["derive"] }
enum-as-inner = "0.6.0"
serde_json = "1"
shrinkwraprs = "0.3"
derive_more = "0.99"
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"
syn = { version = "1.0.73", features = [ "full" ] }
ligen = { path = "ligen" }
ligen-common = { path = "ligen/common" }
ligen-ir = { path = "ligen/ir" }
ligen-macro = { path = "ligen/macro" }
ligen-parsing = { path = "ligen/parsing" }
ligen-traits = { path = "ligen/traits" }
ligen-utils = { path = "ligen/utils" }
#ligen-c = { path = "ecosystem/c/generator" }
#ligen-cmake = { path = "ecosystem/c/cmake" }
ligen-python-parser = { path = "ecosystem/python/parser" }
ligen-python-exporter = { path = "ecosystem/python/exporter" }
#ligen-rust-exporter = { path = "ecosystem/rust/exporter" }
ligen-rust-parser = { path = "ecosystem/rust/parser" }
ligen-cargo = { path = "ecosystem/rust/cargo" }
ligen-gui-runtime = { path = "tools/editor/dependencies/gui-runtime" }
serde = { version = "1", features = ["derive"] }
enum-as-inner = "0.6.0"
serde_json = "1"
shrinkwraprs = "0.3"
derive_more = "0.99"
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"
syn = { version = "1.0.73", features = [ "full" ] }

[patch.crates-io]
# If you want to use the bleeding edge version of egui and eframe:
Expand Down
16 changes: 16 additions & 0 deletions ecosystem/python/exporter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "ligen-python-exporter"
version = "0.1.0"
edition.workspace = true
description.workspace = true
authors.workspace = true
license.workspace = true
documentation.workspace = true
readme.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ligen-ir.workspace = true
ligen-traits.workspace = true
ligen-common.workspace = true
39 changes: 39 additions & 0 deletions ecosystem/python/exporter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pub mod prelude;
use std::{path::PathBuf, str::FromStr};

use ligen_ir::{Module, Library};
use prelude::*;

use ligen_traits::generator::file_generator::{TemplateRegister, Template, TemplateBasedGenerator};


#[derive(Debug, Default)]
pub struct PythonGenerator;

impl TemplateRegister for PythonGenerator {
fn register_templates(&self, _template: &mut Template) -> Result<()> {
// register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library);
Ok(())
}
}

impl TemplateBasedGenerator for PythonGenerator {
fn register_functions(&self, _library: &Library, _template: &mut Template) {
//register_functions!(template, mapped_type, marshal_output);
}

fn base_path(&self) -> PathBuf {
PathBuf::from("python".to_string())
}

fn module_generation_path(&self, _library: &Library, _module: &Module) -> PathBuf {
// let is_root_module = library.root_module == *module;
// let name = if is_root_module { "lib.rs" } else { "mod.rs" };
let path = PathBuf::from_str("src").unwrap();
// path = path.join(PathBuf::from(module.path.clone().without_first()));
// path = path.join(name);
// FIXME: This is not working.
println!("{}", path.display());
path
}
}
1 change: 1 addition & 0 deletions ecosystem/python/exporter/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use ligen_common::*;
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use std::path::PathBuf;
#[macro_export]
macro_rules! register_template {
($template:ident, $identifier:ident) => {
// TODO: Stop using expect and use ? instead?
// $template.register_template_string(stringify!($identifier), include_str!(concat!("templates/", stringify!($identifier), ".hbs"))).expect(concat!("Failed to load ", stringify!($identifier), " template."));
$template.register_template(stringify!($identifier), include_str!(concat!("templates/", stringify!($identifier), ".hbs")));
}
}
Expand Down
12 changes: 7 additions & 5 deletions tools/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ documentation.workspace = true
readme.workspace = true

[dependencies]
ligen-gui-runtime.workspace = true
ligen-ir.workspace = true
serde.workspace = true
ligen-parsing.workspace = true
ligen-cargo.workspace = true
ligen-gui-runtime.workspace = true
ligen-ir.workspace = true
serde.workspace = true
ligen-parsing.workspace = true
ligen-cargo.workspace = true
ligen-python-parser.workspace = true
ligen-traits.workspace = true
ligen-python-exporter.workspace = true
egui_tiles = "0.2.0"
stacker = "0.1.15"
boolinator = "2.4.0"
25 changes: 25 additions & 0 deletions tools/editor/src/gui/ui/layout/editor/generators/generator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use ligen_traits::generator::file_generator::FileGenerator;

use crate::prelude::*;
use crate::gui::ui::editor::{widget::Widget, settings::Settings};

pub struct Generator {
generator: Box<dyn FileGenerator>
}

impl Generator {
pub fn new<T: FileGenerator + 'static>(generator: T) -> Self {
let generator = Box::new(generator);
Self { generator }
}
}

impl Widget for Generator {
type Input = ligen_ir::Library;
fn show(&mut self, settings: &Settings, ui: &mut egui::Ui, input: &mut Self::Input) {
ui.label("Generator");
if ui.button("Generate").clicked() {

}
}
}
37 changes: 37 additions & 0 deletions tools/editor/src/gui/ui/layout/editor/generators/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pub mod generator;
pub use generator::*;
use ligen_python_exporter::PythonGenerator;

use crate::gui::ui::panes::{Pane, PaneManager};

use super::{settings::Settings, widget::Widget};

pub struct Generators {
generators: Vec<Generator>
}

impl Default for Generators {
fn default() -> Self {
let generators = vec![
Generator::new(PythonGenerator::default())
];
Self { generators }
}
}

impl Generators {
pub fn new() -> Self {
Default::default()
}
}

impl Widget for Generators {
type Input = ligen_ir::Library;
fn show(&mut self, settings: &Settings, ui: &mut ligen_gui_runtime::egui::Ui, input: &mut Self::Input) {
for (index, generator) in self.generators.iter_mut().enumerate() {
ui.push_id(index, |ui| {
generator.show(&settings, ui, input);
});
}
}
}
11 changes: 7 additions & 4 deletions tools/editor/src/gui/ui/layout/editor/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ use crate::gui::ui::List;

use crate::gui::ui::panes::{Pane, PaneManager};

use super::generators::Generators;
use super::settings::Settings;
use super::widget::Widget;

#[derive(Default)]
pub struct Editor {
library: ligen_ir::Library,
filter: String,
display_settings: Settings,
settings: Settings,
symbols: Symbols
}

Expand All @@ -47,7 +48,7 @@ impl Editor {
let filter = Default::default();
let symbols = Symbols::new(&library);
let display_settings = Default::default();
Self { library, symbols, filter, display_settings }
Self { library, symbols, filter, settings: display_settings }
}
}

Expand Down Expand Up @@ -75,9 +76,11 @@ impl Pane for Editor {
});
});
ui.separator();
self.display_settings.show(ui);
self.settings.show(ui);
ui.separator();
Library::new().show(&self.display_settings, ui, &mut self.library);
Library::new().show(&self.settings, ui, &mut self.library);
ui.separator();
Generators::new().show(&self.settings, ui, &mut self.library);
ui.separator();
ui.horizontal(|ui| {
ui.label("Filter");
Expand Down
3 changes: 2 additions & 1 deletion tools/editor/src/gui/ui/layout/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub mod ir;
pub mod settings;
pub mod widget;
pub mod menu_button;
pub mod parsing;
pub mod parsers;
pub mod generators;
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ use crate::gui::ui::panes::PaneManager;

use super::{ir::Editor, widget::Widget, settings::Settings};

pub struct Parsing {
pub struct Parsers {
parsers: Vec<Parser>
}

impl Default for Parsing {
impl Default for Parsers {
fn default() -> Self {
let parsers = vec![
Parser::new(Box::<PythonParser>::default())
Parser::new(PythonParser::default())
];
Self { parsers }
}
}

impl Parsing {
impl Parsers {
pub fn new() -> Self {
Default::default()
}
}

impl Pane for Parsing {
impl Pane for Parsers {
fn title(&self) -> String {
"Parsing".to_string()
"Parsers".to_string()
}
fn show(&mut self, ui: &mut ligen_gui_runtime::egui::Ui, pane_manager: &mut PaneManager) -> egui_tiles::UiResponse {
let mut settings = Settings::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ pub struct Parser {
}

impl Parser {
pub fn new(parser: Box<dyn for<'a> parser::Parser<&'a Path, Output = ligen_ir::Library>>) -> Self {
pub fn new<T>(parser: T) -> Self
where T: for<'a> parser::Parser<&'a Path, Output = ligen_ir::Library> + 'static
{
let config = parser.config();
let parser = Box::new(parser);
Self { parser, config }
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/editor/src/gui/ui/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::gui::ui::panes::Panes;
use crate::prelude::*;

use self::editor::ir::Editor;
use self::editor::parsing::Parsing;
use self::editor::parsers::Parsers;

#[derive(Serialize, Deserialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
Expand All @@ -23,7 +23,7 @@ impl Default for Layout {
fn default() -> Self {
let menu = Menu::new();
let mut panes = Panes::new();
panes.new_pane(Box::new(Parsing::new()));
panes.new_pane(Box::new(Parsers::new()));
Self { menu, panes }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/editor/src/gui/ui/layout/panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tree_behavior::*;

pub trait Pane {
fn title(&self) -> String;
fn show(&mut self, ui: &mut egui::Ui, pane_manager: &mut PaneManager) -> egui_tiles::UiResponse;
fn show(&mut self, ui: &mut egui::Ui, panes: &mut PaneManager) -> egui_tiles::UiResponse;
}

#[derive(Default)]
Expand Down

0 comments on commit 422c271

Please sign in to comment.