Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ndc_lib/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ impl Interpreter {
}
}

let checkpoint = self.analyser.checkpoint();
for e in &mut expressions {
self.analyser.analyse(e)?;
if let Err(e) = self.analyser.analyse(e) {
self.analyser.restore(checkpoint);
return Err(e.into());
}
}

//dbg!(&expressions);
Expand Down
12 changes: 10 additions & 2 deletions ndc_lib/src/interpreter/semantic/analyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ impl Analyser {
pub fn from_scope_tree(scope_tree: ScopeTree) -> Self {
Self { scope_tree }
}

pub fn checkpoint(&self) -> ScopeTree {
self.scope_tree.clone()
}

pub fn restore(&mut self, checkpoint: ScopeTree) {
self.scope_tree = checkpoint;
}
}

impl Analyser {
Expand Down Expand Up @@ -559,7 +567,7 @@ fn extract_argument_arity(arguments: &ExpressionLocation) -> usize {
values.len()
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ScopeTree {
current_scope_idx: usize,
global_scope: Scope,
Expand Down Expand Up @@ -749,7 +757,7 @@ impl ScopeTree {
}
}

#[derive(Debug)]
#[derive(Debug, Clone)]
struct Scope {
parent_idx: Option<usize>,
identifiers: Vec<(String, StaticType)>,
Expand Down