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/fix/refactor: full rewrite of constant evaluator #432

Merged
merged 4 commits into from
Jun 18, 2024

Conversation

anton-trunov
Copy link
Member

@anton-trunov anton-trunov commented Jun 18, 2024

to fix various issues and support a larger Tact expression fragment. It is implemented as a classical tree-traversing interpreter. We take into account the semantics of TVM operations, including integer overflows.
As an optimizer it is not very efficient, though. But this will be handled separately.
Supported conditional expressions, unboxing operator, struct instances and struct field access.
Slices are not handled.

Closes #400.

Closes #284.

  • I have updated CHANGELOG.md
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • [ ] I did not do unrelated and/or undiscussed refactorings Had to do some renaming

to fix various issues and support a larger Tact expression fragment.
It is implemented as a classical tree-traversing interpreter.
We take into account the semantics of TVM operations, including
integer overflows.
As an optimizer it is not very efficient, though. But this will
be handled separately.
Supported conditional expressions, unboxing operator,
struct instances and struct field access.
Slices are not handled.
@anton-trunov anton-trunov self-assigned this Jun 18, 2024
@anton-trunov anton-trunov added this to the v1.4.0 milestone Jun 18, 2024
novusnota
novusnota previously approved these changes Jun 18, 2024
Copy link
Member

@novusnota novusnota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splendid work!

I wonder if this interpreter can be slightly adjusted elsewhere for evaluating Tact expressions with --expr or similar in the Tact compiler CLI. And this may even lead to a small REPL :)

@anton-trunov
Copy link
Member Author

I wonder if this interpreter can be slightly adjusted elsewhere for evaluating Tact expressions with --expr or similar in the Tact compiler CLI. And this may even lead to a small REPL :)

You just need to expose the evalConstantExpression function from constEval.ts via CLI. It will parse the input expression and feed the AST into evalConstantExpression. A really nice thing to do would be to also compile the expression and evaluate the code with Sandbox in the background to make sure the results are always the same. And if not -- throw an error and ask to report the example as an issue.

@anton-trunov
Copy link
Member Author

@novusnota And them we could make a Telegram bot that evaluates those Tact expressions and integrate it to https://t.me/tactlang :)

@anton-trunov anton-trunov merged commit dcf6c5e into main Jun 18, 2024
3 checks passed
@anton-trunov anton-trunov deleted the fix-struct-initializers branch June 18, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storage vars cannot be initialized by struct instances Constant structs are not supported
2 participants