mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DEV: Make it an error to reuse a name in a scope.
This commit is contained in:
parent
da3e235942
commit
56174cbe52
@ -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(())
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user