DEV: Make it an error to reuse a name in a scope.

This commit is contained in:
Jeremy Wall 2019-07-05 21:49:10 -05:00
parent da3e235942
commit 56174cbe52
2 changed files with 9 additions and 3 deletions

View File

@ -101,7 +101,7 @@ pub enum Op {
Bang, Bang,
Jump(usize), Jump(usize),
JumpIfTrue(usize), JumpIfTrue(usize),
// TODO(jwall): Short circuiting operations // FIXME(jwall): Short circuiting operations
// - And(usize) // - And(usize)
// - Or(usize) // - Or(usize)
// Spacer operation, Does nothing. // Spacer operation, Does nothing.
@ -173,7 +173,7 @@ impl<'a> VM<'a> {
Op::Field => self.op_field()?, Op::Field => self.op_field()?,
Op::Element => self.op_element()?, Op::Element => self.op_element()?,
Op::Cp => self.op_copy()?, Op::Cp => self.op_copy()?,
// TODO(jwall): Should this whould take a user provided message? //TODO(jwall): Should this whould take a user provided message?
Op::Bang => return Err(Error {}), Op::Bang => return Err(Error {}),
Op::InitThunk(jp) => self.op_thunk(idx, *jp)?, Op::InitThunk(jp) => self.op_thunk(idx, *jp)?,
Op::Noop => { Op::Noop => {
@ -527,7 +527,9 @@ impl<'a> VM<'a> {
} }
fn binding_push(&mut self, name: String, val: Value) -> Result<(), Error> { fn binding_push(&mut self, name: String, val: Value) -> Result<(), Error> {
// FIXME(jwall): Error if the symbol already exists. if self.symbols.is_bound(&name) {
return Err(Error {});
}
self.symbols.add(name, val); self.symbols.add(name, val);
Ok(()) Ok(())
} }

View File

@ -106,6 +106,10 @@ impl Stack {
} }
} }
pub fn is_bound(&self, name: &str) -> bool {
self.curr.get(name).is_some()
}
pub fn push(&mut self) { pub fn push(&mut self) {
let mut nb = Bindings::new(); let mut nb = Bindings::new();
std::mem::swap(&mut nb, &mut self.curr); std::mem::swap(&mut nb, &mut self.curr);