mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
added stack overflow error
This commit is contained in:
parent
3066ba9032
commit
6386df22c0
3 changed files with 10 additions and 8 deletions
|
|
@ -48,6 +48,8 @@ pub enum RuntimeError {
|
|||
UndefinedAttribute { class: Rc<LoxClass>, name: Box<str> },
|
||||
#[error("RuntimeError: {value} is not a valid superclass")]
|
||||
InvalidSuperclass { value: Value },
|
||||
#[error("RuntimeError: stack overflow")]
|
||||
StackOverflow,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ impl Eval for Expr {
|
|||
let mut methods: FxHashMap<String, Value> = FxHashMap::default();
|
||||
|
||||
// this is the scope "this" will get injected in
|
||||
env.enter_scope();
|
||||
env.enter_scope()?;
|
||||
|
||||
for method_expr in method_exprs.iter() {
|
||||
let method = method_expr.eval(env)?;
|
||||
|
|
@ -280,7 +280,7 @@ impl Eval for Stmt {
|
|||
env.define(name.clone(), initializer);
|
||||
}
|
||||
Stmt::Block { statements } => {
|
||||
env.enter_scope();
|
||||
env.enter_scope()?;
|
||||
for statement in statements {
|
||||
if let Err(err) = statement.eval(env) {
|
||||
env.exit_scope();
|
||||
|
|
@ -318,7 +318,7 @@ pub fn call_fun(fun: Rc<LoxFunction>, env: &mut Environment) -> EvalResult<Value
|
|||
});
|
||||
}
|
||||
|
||||
env.enter_scope();
|
||||
env.enter_scope()?;
|
||||
|
||||
env.define(fun.name(), Value::Function(fun.clone()));
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ use thiserror::Error;
|
|||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ResolverError {
|
||||
#[error("Can't read variable {name} in its own initializer.")]
|
||||
#[error("ResolverError: Can't read variable {name} in its own initializer.")]
|
||||
VarInOwnInitializer { name: Box<str> },
|
||||
#[error("Variable {name} not defined")]
|
||||
#[error("ResolverError: Variable {name} not defined")]
|
||||
UnresolvableVariable { name: Box<str> },
|
||||
#[error("Return outside of function definition")]
|
||||
#[error("ResolverError: Return outside of function definition")]
|
||||
ReturnOutsideFunction,
|
||||
#[error("this outside of method")]
|
||||
#[error("ResolverError: this outside of method")]
|
||||
ThisOutsideMethod,
|
||||
#[error("super outside of subclass method")]
|
||||
#[error("ResolverError: super outside of subclass method")]
|
||||
SuperOutsideMethod,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue