Interpreter - Access methods through get expressions
This commit is contained in:
parent
e371217df0
commit
58c1bbcf68
1 changed files with 11 additions and 7 deletions
|
@ -71,14 +71,18 @@ impl Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get(&self, name: &Token) -> SloxResult<Value> {
|
pub(super) fn get(&self, name: &Token) -> SloxResult<Value> {
|
||||||
match self.fields.get(&name.lexeme) {
|
if let Some(value) = self.fields.get(&name.lexeme) {
|
||||||
Some(value) => Ok(value.clone()),
|
return Ok(value.clone());
|
||||||
None => Err(SloxError::with_token(
|
}
|
||||||
|
if let Some(method) = self.class.borrow().methods.get(&name.lexeme) {
|
||||||
|
return Ok(Value::from(method.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(SloxError::with_token(
|
||||||
ErrorKind::Runtime,
|
ErrorKind::Runtime,
|
||||||
name,
|
name,
|
||||||
"undefined property".to_owned(),
|
"undefined property".to_owned(),
|
||||||
)),
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn set(&mut self, name: &Token, value: Value) {
|
pub(super) fn set(&mut self, name: &Token, value: Value) {
|
||||||
|
|
Loading…
Reference in a new issue