mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
DEV: Refactor get_binding to simplify the logic.
This commit is contained in:
parent
c1414bdde4
commit
f866275df2
@ -1080,14 +1080,13 @@ impl VM {
|
|||||||
name: &str,
|
name: &str,
|
||||||
pos: &Position,
|
pos: &Position,
|
||||||
) -> Result<(Rc<Value>, Position), Error> {
|
) -> Result<(Rc<Value>, Position), Error> {
|
||||||
if name == "self" {
|
let tpl = if name == "self" {
|
||||||
if let Some((val, pos)) = self.self_stack.last() {
|
self.self_stack.last().cloned()
|
||||||
return Ok((val.clone(), pos.clone()));
|
} else {
|
||||||
}
|
self.symbols.get(name)
|
||||||
return Err(Error::new(format!("No such binding {}", name), pos.clone()));
|
};
|
||||||
}
|
match tpl {
|
||||||
match self.symbols.get(name) {
|
Some((v, pos)) => Ok((v, pos)),
|
||||||
Some((ref v, ref pos)) => Ok((v.clone(), pos.clone())),
|
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(format!("No such binding {}", name), pos.clone()));
|
return Err(Error::new(format!("No such binding {}", name), pos.clone()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user