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:
Michael Schimmel
2026-02-16 23:47:17 +01:00
commit 3fdfd01982
8 changed files with 4601 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
use std::sync::Arc;
use std::fmt::Debug;
use crate::ast::types::{Identity, Value};
/// A generic AST Node wrapper to preserve identity and metadata
#[derive(Debug, Clone)]
pub struct Node<K> {
pub identity: Identity,
pub kind: K,
}
/// The base for custom node types (extensions)
pub trait CustomNode: Debug + Send + Sync {
fn eval(&self, node: &Node<UntypedKind>, ctx: &mut Context) -> Value;
fn display_name(&self) -> &'static str;
}
/// Evaluation Context (Scope management)
pub struct Context {
// Add variables, scope management here later
}
/// The core AST variant enum for performance and structure
#[derive(Debug)]
pub enum UntypedKind {
Constant(Value),
Identifier(Arc<str>),
If {
cond: Box<Node<UntypedKind>>,
then_br: Box<Node<UntypedKind>>,
else_br: Option<Box<Node<UntypedKind>>>,
},
Call {
callee: Box<Node<UntypedKind>>,
args: Vec<Node<UntypedKind>>,
},
/// The "escape hatch" for decentralized node types
Extension(Box<dyn CustomNode>),
}
impl Node<UntypedKind> {
pub fn eval(&self, ctx: &mut Context) -> Value {
match &self.kind {
UntypedKind::Constant(v) => v.clone(),
UntypedKind::Identifier(_) => todo!("Lookup in Context"),
UntypedKind::If { cond, then_br, else_br } => {
if cond.eval(ctx).is_truthy() {
then_br.eval(ctx)
} else if let Some(eb) = else_br {
eb.eval(ctx)
} else {
Value::Nil
}
}
UntypedKind::Call { callee, args } => {
let _func = callee.eval(ctx);
let _eval_args: Vec<Value> = args.iter().map(|a| a.eval(ctx)).collect();
todo!("Execute func with args")
}
UntypedKind::Extension(ext) => ext.eval(self, ctx),
}
}
}