MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / eval

Method eval

cli/src/engine.rs:71–92  ·  view source on GitHub ↗

Recompile prior history with `src` so imports and defs persist; only new lines reach `on_line`.

(&mut self, src: &str, mut on_line: F)

Source from the content-addressed store, hash-verified

69
70 /// Recompile prior history with `src` so imports and defs persist; only new lines reach `on_line`.
71 pub fn eval<F: FnMut(&str)>(&mut self, src: &str, mut on_line: F) -> Result<Outcome> {
72 let full = if self.history.is_empty() {
73 src.to_string()
74 } else {
75 format!("{}\n{}", self.history, src)
76 };
77 let literal = serde_json::to_string(&full)?;
78 let expr = format!("__edgeRun({literal})");
79 self.tab.evaluate(&expr, false).map_err(|e| anyhow!("starting eval: {e}"))?;
80
81 let mut all: Vec<String> = Vec::new();
82 let outcome = drain(&self.tab, &mut |line| all.push(line.to_string()))?;
83 for line in all.iter().skip(self.history_lines) {
84 on_line(line);
85 }
86 if outcome.err.is_none() {
87 if !self.history.is_empty() { self.history.push('\n'); }
88 self.history.push_str(src);
89 self.history_lines = all.len();
90 }
91 Ok(outcome)
92 }
93
94 /// Wipe accumulated history and runtime modules; next eval starts in a fresh namespace.
95 pub fn reset(&mut self) -> Result<()> {

Callers 2

runFunction · 0.80
runFunction · 0.80

Calls 6

drainFunction · 0.85
pushMethod · 0.80
is_noneMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected