Refactor Binder to support recursion and add stdlib operators

This commit introduces two main changes:

1.  **Binder Refactoring**: The `Binder` has been refactored to support
    recursive definitions by pre-declaring names in the scope before
    binding their values. This ensures that a name is visible to itself
    when its definition is being processed.

2.  **Stdlib Operator Implementation**: Several standard library
    operators, including `+`, `-`, `*`, `/`, `>`, and `<`, have been
    implemented. These operators now correctly handle both `Int` and
    `Float` types for numerical operations and comparisons.
    Additionally, the display formatting for `Value::List` and
    `Value::Record` has been improved for better readability. The
    default source code in `main.rs` has also been updated to include a
    Fibonacci example, demonstrating the new recursive capabilities.
This commit is contained in:
Michael Schimmel
2026-02-17 13:22:04 +01:00
parent 9afde5a301
commit 3cca0e06c2
4 changed files with 120 additions and 19 deletions
+26 -4
View File
@@ -27,7 +27,25 @@ struct CompilerApp {
impl Default for CompilerApp {
fn default() -> Self {
Self {
source_code: String::new(),
source_code: String::from(r#"
(do
(def fib (fn [n]
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2))))))
(def result (fib 10))
(def data {
:name "Fibonacci"
:input 10
:output result
:sequence [0 1 1 2 3 5 8 13 21 34 55]
})
data
)
"#),
output_log: String::from("Ready to compile..."),
env: Environment::new(),
is_first_frame: true,
@@ -68,8 +86,12 @@ impl eframe::App for CompilerApp {
}
ui.add_space(5.0);
ui.separator();
ui.label("Output / Logs:");
ui.horizontal(|ui| {
ui.label("Output / Logs:");
if ui.button("Copy to Clipboard").clicked() {
ui.ctx().copy_text(self.output_log.clone());
}
});
// Log Output Area
egui::ScrollArea::vertical()
@@ -80,7 +102,7 @@ impl eframe::App for CompilerApp {
egui::TextEdit::multiline(&mut self.output_log)
.font(egui::TextStyle::Monospace)
.desired_width(f32::INFINITY)
.interactive(false), // Read-only
.interactive(true)
);
});
});