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

feat: destructuring of structs and messages #856

Merged
merged 30 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0af4816
feat: grammar
Gusarich Sep 19, 2024
74e7d26
feat: implement destructuring and add e2e test
Gusarich Sep 20, 2024
618611d
chore: add more test cases
Gusarich Sep 20, 2024
ce74a73
feat: interpreter and iterator
Gusarich Sep 20, 2024
62ab487
chore: add test with message
Gusarich Sep 20, 2024
546b740
chore: update changelog
Gusarich Sep 20, 2024
129902a
Update src/generator/writers/writeFunction.ts
Gusarich Sep 23, 2024
13b2cf6
feat: rework destructuring to support mapping of fields
Gusarich Oct 8, 2024
1169f81
fix: apply suggestions from code review
Gusarich Oct 10, 2024
70f0ad0
feat: fixes after updating grammar
Gusarich Oct 10, 2024
8c355cb
feat: make destruct identifiers to a map instead of an array
Gusarich Oct 10, 2024
32f80b4
chore: add more typechecker test cases
Gusarich Oct 10, 2024
2151c54
chore: add one more typechecker test and rename them
Gusarich Oct 10, 2024
c3ee0af
chore: add one more typechecker test
Gusarich Oct 10, 2024
9bae96e
fix: compare specified type and expression type
Gusarich Oct 10, 2024
f6d07c5
chore: one more typechecker test
Gusarich Oct 11, 2024
72a03e0
chore: pretty printer test
Gusarich Oct 11, 2024
10a8219
feat: implement renamer and add test case
Gusarich Oct 11, 2024
7091ed5
chore: more e2e test cases
Gusarich Oct 11, 2024
f66979b
fix: handle wildcard names in interpreter
Gusarich Oct 11, 2024
7cb3a91
chore: add interpreter test cases
Gusarich Oct 11, 2024
107c110
fix: compare identifiers map correctly in ast comparison
Gusarich Oct 11, 2024
c2499fd
chore: use .toMatchObject for convenience
Gusarich Oct 11, 2024
43567ac
fix: correctly handle `_` names
Gusarich Oct 14, 2024
4d01919
fix: do not skip resolving for wildcard identifiers
Gusarich Oct 14, 2024
aca6e69
fix: adjust test code after fix
Gusarich Oct 14, 2024
d5b3d75
chore: change the error test
Gusarich Oct 14, 2024
bd223f4
feat: rework identifiers map and handle duplicate source ids
Gusarich Oct 14, 2024
72ea7b1
fix: adjust comparing and hashing and a few tests
Gusarich Oct 14, 2024
0cbf128
Update src/grammar/ast.ts
Gusarich Oct 14, 2024
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 @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Docs: the `description` property to the frontmatter of the each page for better SEO: PR [#916](https://github.com/tact-lang/tact/pull/916)
- Docs: Google Analytics tags per every page: PR [#921](https://github.com/tact-lang/tact/pull/921)
- Ability to specify a compile-time method ID expression for getters: PR [#922](https://github.com/tact-lang/tact/pull/922) and PR [#932](https://github.com/tact-lang/tact/pull/932)
- Destructuring of structs and messages: PR [#856](https://github.com/tact-lang/tact/pull/856)

### Changed

Expand Down
20 changes: 20 additions & 0 deletions src/generator/writers/writeFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,26 @@ export function writeStatement(

return;
}
case "statement_destruct": {
const t = getExpType(ctx.ctx, f.expression);
if (t.kind !== "ref") {
throwInternalCompilerError(
`invalid destruct expression kind: ${t.kind}`,
f.expression.loc,
);
}
const ty = getType(ctx.ctx, t.name);
const ids = ty.fields.map((field) => {
const id = f.identifiers.get(field.name);
return id === undefined || isWildcard(id[1])
? "_"
: funcIdOf(id[1]);
});
ctx.append(
`var (${ids.join(", ")}) = ${writeCastedExpression(f.expression, t, ctx)};`,
);
return;
}
}

throw Error("Unknown statement kind");
Expand Down
Loading
Loading