feat: Initialize compiler GUI project
Sets up the basic structure for the compiler GUI application using eframe. This includes the main application loop, a default UI layout with a source code editor and an output log panel, and the foundational AST (Abstract Syntax Tree) definitions for types, nodes, and an evaluation mechanism.
This commit is contained in:
+115
@@ -0,0 +1,115 @@
|
||||
use eframe::egui;
|
||||
|
||||
pub mod ast;
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"Compiler GUI",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::new(CompilerApp::default()))),
|
||||
)
|
||||
}
|
||||
|
||||
struct CompilerApp {
|
||||
source_code: String,
|
||||
output_log: String,
|
||||
}
|
||||
|
||||
impl Default for CompilerApp {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
source_code: String::new(),
|
||||
output_log: String::from("Ready to compile..."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for CompilerApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// Bottom Panel: Output Log & Controls (Resizable)
|
||||
egui::TopBottomPanel::bottom("bottom_panel")
|
||||
.resizable(true)
|
||||
.min_height(150.0)
|
||||
.default_height(250.0)
|
||||
.show(ctx, |ui| {
|
||||
ui.add_space(5.0);
|
||||
|
||||
// Compile Button (at the top of the bottom panel)
|
||||
if ui.button("Compile").clicked() {
|
||||
use crate::ast::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
// 1. Create shared identity
|
||||
let identity = Arc::new(NodeIdentity { line: 1, col: 1 });
|
||||
|
||||
// 2. Build AST: (if true 42 nil)
|
||||
let ast = Node {
|
||||
identity: identity.clone(),
|
||||
kind: UntypedKind::If {
|
||||
cond: Box::new(Node {
|
||||
identity: identity.clone(),
|
||||
kind: UntypedKind::Constant(Value::Bool(true)),
|
||||
}),
|
||||
then_br: Box::new(Node {
|
||||
identity: identity.clone(),
|
||||
kind: UntypedKind::Constant(Value::Int(42)),
|
||||
}),
|
||||
else_br: Some(Box::new(Node {
|
||||
identity: identity.clone(),
|
||||
kind: UntypedKind::Constant(Value::Nil),
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
// 3. Evaluate
|
||||
let mut context = Context {};
|
||||
let result = ast.eval(&mut context);
|
||||
|
||||
self.output_log = format!(
|
||||
"AST Test:\nSource: (if true 42 nil)\nResult: {}\n\nCompiler log:\nStarted at {:?}",
|
||||
result,
|
||||
std::time::SystemTime::now(),
|
||||
);
|
||||
}
|
||||
|
||||
ui.add_space(5.0);
|
||||
ui.separator();
|
||||
ui.label("Output / Logs:");
|
||||
|
||||
// Log Output Area
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("output_log_scroll")
|
||||
.show(ui, |ui| {
|
||||
ui.add_sized(
|
||||
ui.available_size(),
|
||||
egui::TextEdit::multiline(&mut self.output_log)
|
||||
.font(egui::TextStyle::Monospace)
|
||||
.desired_width(f32::INFINITY)
|
||||
.interactive(false), // Read-only
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// Central Panel: Source Code Editor (Fills remaining space)
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Source Code Editor");
|
||||
ui.label("Input Source:");
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("source_code_scroll")
|
||||
.show(ui, |ui| {
|
||||
ui.add_sized(
|
||||
ui.available_size(),
|
||||
egui::TextEdit::multiline(&mut self.source_code)
|
||||
.font(egui::TextStyle::Monospace)
|
||||
.desired_width(f32::INFINITY)
|
||||
.lock_focus(true),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user