-
Notifications
You must be signed in to change notification settings - Fork 387
feat: loop keyword in runtime and comptime code
#7096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ed507d
f2f8ca8
bc138cd
3d89a75
9a86440
a19d232
a87ce0e
03776ca
65063b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1550,6 +1550,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { | |
| HirStatement::Constrain(constrain) => self.evaluate_constrain(constrain), | ||
| HirStatement::Assign(assign) => self.evaluate_assign(assign), | ||
| HirStatement::For(for_) => self.evaluate_for(for_), | ||
| HirStatement::Loop(expression) => self.evaluate_loop(expression), | ||
| HirStatement::Break => self.evaluate_break(statement), | ||
| HirStatement::Continue => self.evaluate_continue(statement), | ||
| HirStatement::Expression(expression) => self.evaluate(expression), | ||
|
|
@@ -1741,6 +1742,34 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { | |
| Ok(Value::Unit) | ||
| } | ||
|
|
||
| fn evaluate_loop(&mut self, expr: ExprId) -> IResult<Value> { | ||
| let was_in_loop = std::mem::replace(&mut self.in_loop, true); | ||
| let in_lsp = self.elaborator.interner.is_in_lsp_mode(); | ||
| let mut counter = 0; | ||
|
|
||
| loop { | ||
| self.push_scope(); | ||
|
|
||
| match self.evaluate(expr) { | ||
| Ok(_) => (), | ||
| Err(InterpreterError::Break) => break, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
| Err(InterpreterError::Continue) => continue, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
| Err(other) => return Err(other), | ||
| } | ||
|
|
||
| self.pop_scope(); | ||
|
|
||
| counter += 1; | ||
| if in_lsp && counter == 10_000 { | ||
| let location = self.elaborator.interner.expr_location(&expr); | ||
| return Err(InterpreterError::LoopHaltedForUiResponsiveness { location }); | ||
| } | ||
| } | ||
|
|
||
| self.in_loop = was_in_loop; | ||
| Ok(Value::Unit) | ||
| } | ||
|
|
||
| fn evaluate_break(&mut self, id: StmtId) -> IResult<Value> { | ||
| if self.in_loop { | ||
| Err(InterpreterError::Break) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.