diff --git a/src/ast/types.rs b/src/ast/types.rs index 0315ad4..60aeed6 100644 --- a/src/ast/types.rs +++ b/src/ast/types.rs @@ -146,7 +146,7 @@ impl Value { Value::Function { .. } => StaticType::Any, // Dynamic function Value::Object(o) => StaticType::Object(o.type_name()), Value::Cell(c) => c.borrow().static_type(), - Value::TailCallRequest(_) => panic!("Internal VM state leaked: TailCallRequest"), + Value::TailCallRequest(_) => StaticType::Any, // Internal state, but typable as Any } } } @@ -181,7 +181,7 @@ impl fmt::Display for Value { Value::Function(_) => write!(f, ""), Value::Object(o) => write!(f, "<{}>", o.type_name()), Value::Cell(c) => write!(f, "{}", c.borrow()), - Value::TailCallRequest(_) => panic!("Internal VM state leaked: TailCallRequest"), + Value::TailCallRequest(_) => write!(f, ""), } } } diff --git a/src/main.rs b/src/main.rs index b4643ce..7cda528 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,24 @@ impl CompilerApp { let mut vm = myc::ast::vm::VM::new(self.env.global_values.clone()); let mut observer = myc::ast::vm::TracingObserver::new(); let res = vm.run_with_observer(&mut observer, &linked); - self.trace_logs = observer.logs; + + // Batch-truncate logs for GUI performance (once after execution) + let mut logs = observer.logs; + if logs.len() > 1000 { + logs.truncate(1000); + logs.push("... [Trace truncated to 1,000 entries] ...".to_string()); + } + + for line in &mut logs { + if line.len() > 255 { + if let Some((idx, _)) = line.char_indices().nth(255) { + line.truncate(idx); + line.push_str("..."); + } + } + } + + self.trace_logs = logs; self.active_tab = AppTab::Trace; res? } else { @@ -362,20 +379,14 @@ impl eframe::App for CompilerApp { ); }, AppTab::Trace => { - let mut combined = self.trace_logs.join("\n"); - let mut layouter = |ui: &egui::Ui, buffer: &dyn egui::TextBuffer, _wrap_width: f32| { - let layout_job = highlight_myc(ui.ctx(), buffer.as_str()); - ui.painter().layout_job(layout_job) - }; - - ui.add_sized( - ui.available_size(), - egui::TextEdit::multiline(&mut combined) - .font(egui::TextStyle::Monospace) - .desired_width(f32::INFINITY) - .interactive(false) - .layouter(&mut layouter) - ); + egui::ScrollArea::vertical() + .id_salt("trace_log_scroll") + .show(ui, |ui| { + ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace); + for line in &self.trace_logs { + ui.label(line); + } + }); } } });