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
Implement Array Destructuring [WIP] #1788
Conversation
@@ -0,0 +1,5 @@ | |||
const arr = [1, 2]; | |||
const a = arr[0], b = arr[1]; | |||
const x = [3, 4][0], y = [3, 4][1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to hear some suggestion how to implement a "dummy" variable to avoid the double invocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically compile the Statement
s directly, i.e. not trying to "transpile" on the parser level, so we not only get a 1:1 roundtrip when serializing the AST again, but also do not have to deal with temporary AST nodes like the one that would be necessary here. Here, the compiler would typically implement a compileDestructuringAssignment
method directly compiling to Binaryen IR, which may then use a temporary Wasm local.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. From what I hear I need to set the NodeKind
to DESTRUCTED_VARIABLE
. And then handle it in compileStatement()
switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add a flag to the statement and keep the type to VARIABLE
@dcodeIO May I ask for your help with passing a test here. The same |
src/parser.ts
Outdated
var localCallableVarDeclaration: VariableDeclaration | undefined; | ||
var localCallableIdentifier: IdentifierExpression | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssemblyScript doesn't support undefined
. Only null
. And due to compiler support self-bootstrapping you should never use undefined
even in compiler's codebase.
Update from mastte
@MaxGraey @dcodeIO took me a while to get the tests to pass (needed to rebase - I guess the tests runs agains master merge not my current branch dah...). I know you asked to use a local I can revert back to use a local // part of "compileElementAccessExpression()" method in compilers.ts
let thisArg = this.compileExpressionMaybeCached(targetExpression, thisType, destructingKey); // Try to hit a cache result Where The only issues is that I got an error from the optimization test because "the Binaryen IR tree is not flat". |
# Conflicts: # src/compiler.ts # tests/compiler/array-destructuring.optimized.wat # tests/compiler/array-destructuring.ts
This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions! |
This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards. |
Per #1473, Im stated to implement destructuring assignment.
At this step, I will implement the array destructuring.
Please feel free to comment on the progress.