Skip to content
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

Box anonymous function #299

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **[BREAKING CHANGE]** `TokenType::StringLiteral::multi_line` has been replaced with `TokenType::StringLiteral::multi_line_depth`. It serves the same purpose except instead of being an `Option<usize>`, it is now a standard `usize`. It is advised to simply check `quote_type == StringLiteralQuoteType::Brackets` to get the previous behavior.
- **[BREAKING CHANGE]** Flattened `AstError` into just what used to be `AstError::UnexpectedToken`.
- **[BREAKING CHANGE]** `Symbol::PlusEqual` and friends are now only available when using Luau.
- **[BREAKING CHANGE]** `Expression::Function((TokenReference, FunctionBody))` variant is now Boxed to ``Expression::Function(Box<(TokenReference, FunctionBody)>)` to reduce type sizes and reduce stack overflows
- Shebangs provide their trailing trivia more accurately to the rest of full-moon.
- Attempting to display `StringLiteralQuoteType::Brackets` now returns an error rather than being marked as unreachable.
- Significantly optimized the entire codebase, helping both time to parse and wasting less stack, especially in debug mode.
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub enum Expression {

/// An anonymous function, such as `function() end)`
#[display(fmt = "{}{}", "_0.0", "_0.1")]
Function((TokenReference, FunctionBody)),
Function(Box<(TokenReference, FunctionBody)>),

/// A call of a function, such as `call()`
#[display(fmt = "{_0}")]
Expand Down
5 changes: 4 additions & 1 deletion full-moon/src/ast/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,10 @@ fn parse_primary_expression(state: &mut ParserState) -> ParserResult<Expression>
}
};

ParserResult::Value(Expression::Function((function_token, function_body)))
ParserResult::Value(Expression::Function(Box::new((
function_token,
function_body,
))))
}

TokenType::Symbol {
Expand Down
14 changes: 7 additions & 7 deletions full-moon/src/ast/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ impl Visit for Expression {
expression.visit(visitor);
}

Expression::Function((function_token, function_body)) => {
function_token.visit(visitor);
function_body.visit(visitor);
Expression::Function(func) => {
func.0.visit(visitor);
func.1.visit(visitor);
}

Expression::FunctionCall(function_call) => {
Expand Down Expand Up @@ -176,10 +176,10 @@ impl VisitMut for Expression {
expression: expression.visit_mut(visitor),
},

Expression::Function((function_token, function_body)) => Expression::Function((
function_token.visit_mut(visitor),
function_body.visit_mut(visitor),
)),
Expression::Function(func) => Expression::Function(Box::new((
func.0.visit_mut(visitor),
func.1.visit_mut(visitor),
))),

Expression::FunctionCall(function_call) => {
Expression::FunctionCall(function_call.visit_mut(visitor))
Expand Down
Loading