Support for defer parsing lambda functions#4105
Merged
chakrabot merged 3 commits intochakra-core:release/1.7from Nov 2, 2017
Merged
Support for defer parsing lambda functions#4105chakrabot merged 3 commits intochakra-core:release/1.7from
chakrabot merged 3 commits intochakra-core:release/1.7from
Conversation
Fix up the parser to enable the defer parse methods to handle lambda functions. All lambdas are allowed to be deferred, even lambdas with compact parameter lists or function bodies. Should also allow lambda functions to be redeferred, which is really the main reason to do this work. One of the related changes is in `Parser::Parse`. I changed this function to skip calling `ParseStmtList` in the case where we are defer parsing a single function. In these cases we know that we are going to parse a function so we don't need to start parsing a set of statements, then one statement, then one expression, then one terminal, etc until we finally start parsing the function via `ParseFncDecl`. Instead we can just jump directly to `ParseFncDecl` after setting up the correct flags. By doing this, we can avoid reparsing the lambda parameter list (because we never assume it will be an ordinary expression list) which saves us the headache of bookkeeping the block and function ids. One other change of note is in `ScopeInfo::SaveSymbolInfo`. We now need to save symbol info for the `arguments` symbol since a lambda may be deferred in a function and lambdas capture the `arguments` value from their parent. I suppose we could move the `arguments` default binding into a regular special symbol at some point in the future.
pleath
reviewed
Nov 1, 2017
| BOOL FuncInfo::IsLambda() const | ||
| { | ||
| return root->sxFnc.IsLambda(); | ||
| BOOL FuncInfo::IsLambda() const { |
Contributor
There was a problem hiding this comment.
Nit (sorry), please keep curly style consistent.
Contributor
Author
There was a problem hiding this comment.
Ah, some style crept-in from JavaScript. I'll clean this one.
pleath
reviewed
Nov 1, 2017
| } | ||
|
|
||
| template<bool buildAST> | ||
| void Parser::CreateSpecialSymbolDeclarations(ParseNodePtr pnodeFnc, bool isGlobal) |
Contributor
There was a problem hiding this comment.
Note that in a deferred function we still need to do binding (for all symbols) so that pid ref stacks can be popped, and bindings to symbols in outer functions will be correct.
Contributor
Author
There was a problem hiding this comment.
Ok, good point. I'll rollback the change to this.
pleath
approved these changes
Nov 2, 2017
Contributor
Author
|
Thank you, @pleath |
chakrabot
pushed a commit
that referenced
this pull request
Nov 2, 2017
Merge pull request #4105 from boingoing:DeferParseLambda_3 Fix up the parser to enable the defer parse methods to handle lambda functions. All lambdas are allowed to be deferred, even lambdas with compact parameter lists or function bodies. Should also allow lambda functions to be redeferred, which is really the main reason to do this work. One of the related changes is in `Parser::Parse`. I changed this function to skip calling `ParseStmtList` in the case where we are defer parsing a single function. In these cases we know that we are going to parse a function so we don't need to start parsing a set of statements, then one statement, then one expression, then one terminal, etc until we finally start parsing the function via `ParseFncDecl`. Instead we can just jump directly to `ParseFncDecl` after setting up the correct flags. By doing this, we can avoid reparsing the lambda parameter list (because we never assume it will be an ordinary expression list) which saves us the headache of bookkeeping the block and function ids. One other change of note is in `ScopeInfo::SaveSymbolInfo`. We now need to save symbol info for the `arguments` symbol since a lambda may be deferred in a function and lambdas capture the `arguments` value from their parent. I suppose we could move the `arguments` default binding into a regular special symbol at some point in the future.
chakrabot
pushed a commit
that referenced
this pull request
Nov 2, 2017
…a functions Merge pull request #4105 from boingoing:DeferParseLambda_3 Fix up the parser to enable the defer parse methods to handle lambda functions. All lambdas are allowed to be deferred, even lambdas with compact parameter lists or function bodies. Should also allow lambda functions to be redeferred, which is really the main reason to do this work. One of the related changes is in `Parser::Parse`. I changed this function to skip calling `ParseStmtList` in the case where we are defer parsing a single function. In these cases we know that we are going to parse a function so we don't need to start parsing a set of statements, then one statement, then one expression, then one terminal, etc until we finally start parsing the function via `ParseFncDecl`. Instead we can just jump directly to `ParseFncDecl` after setting up the correct flags. By doing this, we can avoid reparsing the lambda parameter list (because we never assume it will be an ordinary expression list) which saves us the headache of bookkeeping the block and function ids. One other change of note is in `ScopeInfo::SaveSymbolInfo`. We now need to save symbol info for the `arguments` symbol since a lambda may be deferred in a function and lambdas capture the `arguments` value from their parent. I suppose we could move the `arguments` default binding into a regular special symbol at some point in the future.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix up the parser to enable the defer parse methods to handle lambda functions. All lambdas are allowed to be deferred, even lambdas with compact parameter lists or function bodies.
Should also allow lambda functions to be redeferred, which is really the main reason to do this work.
One of the related changes is in
Parser::Parse. I changed this function to skip callingParseStmtListin the case where we are defer parsing a single function. In these cases we know that we are going to parse a function so we don't need to start parsing a set of statements, then one statement, then one expression, then one terminal, etc until we finally start parsing the function viaParseFncDecl. Instead we can just jump directly toParseFncDeclafter setting up the correct flags. By doing this, we can avoid reparsing the lambda parameter list (because we never assume it will be an ordinary expression list) which saves us the headache of bookkeeping the block and function ids.One other change of note is in
ScopeInfo::SaveSymbolInfo. We now need to save symbol info for theargumentssymbol since a lambda may be deferred in a function and lambdas capture theargumentsvalue from their parent. I suppose we could move theargumentsdefault binding into a regular special symbol at some point in the future.