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

Lambdaexpr #123

Merged
merged 9 commits into from
Oct 21, 2024
Merged

Lambdaexpr #123

merged 9 commits into from
Oct 21, 2024

Conversation

apkrelling
Copy link
Contributor

@apkrelling apkrelling commented Oct 17, 2024

Pull Request description

This PR adds LambdaExpr class.
This PR is an attempt to solve #104 .

  • added new ASTKind's
  • created LambdaExpr classes
  • updated __init__.py to include the new imports and classes in the__all__ list
  • added the new class visit method in transpilers/python.py
  • added tests in tests/transpilers/test_python.py
  • added tests in tests/test_packages.py

How to test these changes

from astx.callables import Argument, Arguments, LambdaExpr
from astx.datatypes import LiteralInt32, Int32
from astx.operators import BinaryOp
from astx.variables import Variable

from astx.transpilers import python as astx2py

### Example with params
params = Arguments(Argument(name="x", type_=Int32))
body = BinaryOp(op_code="+", lhs=Variable(name="x"), rhs=LiteralInt32(1))
lambda_expr = LambdaExpr(params=params, body=body)

lambda_expr.get_struct()
lambda_expr.get_struct(simplified=True)
lambda_expr.__str__()

generator = astx2py.ASTxPythonTranspiler()
generated_code = generator.visit(lambda_expr)
print(generated_code) 

### Example w/o params
body = LiteralInt32(1)
lambda_expr = LambdaExpr(body=body)

lambda_expr.get_struct()
lambda_expr.get_struct(simplified=True)
lambda_expr.__str__()

generator = astx2py.ASTxPythonTranspiler()
generated_code = generator.visit(lambda_expr)
print(generated_code) 

Pull Request checklists

This PR is a:

  • bug-fix
  • new feature
  • maintenance

About this PR:

  • it includes tests.
  • the tests are executed on CI.
  • the tests generate log file(s) (path).
  • pre-commit hooks were executed locally.
  • this PR requires a project documentation update.

Author's checklist:

  • I have reviewed the changes and it contains no misspelling.
  • The code is well commented, especially in the parts that contain more
    complexity.
  • New and old tests passed locally.

Additional information

params = Arguments(Argument(name="x", type_=Int32))
body = BinaryOp(op_code="+", lhs=Variable(name="x"), rhs=LiteralInt32(1))

# Create the LambdaExpr
lambda_expr = LambdaExpr(params=params, body=body)
lambda_expr

lambdaexpr_ast_jupyterlab

lambdaexpr_ast

## Reviewer's Checklist

- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved .

@apkrelling apkrelling marked this pull request as draft October 17, 2024 14:37
@apkrelling
Copy link
Contributor Author

@xmnlab I would just like to check with you if the __str__() method is working the way it's intended to. As of now,

from astx.callables import Argument, Arguments, LambdaExpr
from astx.datatypes import LiteralInt32, Int32
from astx.operators import BinaryOp
from astx.variables import Variable

params = Arguments(Argument(name="x", type_=Int32))
body = BinaryOp(op_code="+", lhs=Variable(name="x"), rhs=LiteralInt32(1))
lambda_expr = LambdaExpr(params=params, body=body)
lambda_expr.__str__()

generates 'lambda x: BinaryOp[+](Variable[x],LiteralInt32(1))' as output. Is that the way it's supposed to be?

@apkrelling apkrelling marked this pull request as ready for review October 19, 2024 15:41
@xmnlab
Copy link
Contributor

xmnlab commented Oct 21, 2024

thanks for working on that @apkrelling !
looks good to me!

about __str__ I think it is ok for now, and we can revisit that in the future

I just added a small comment about a very small thing .. it is just a comment in the code that I think could be removed .. other than that, this PR looks good to be merged.

@xmnlab xmnlab merged commit 3ec145f into arxlang:main Oct 21, 2024
12 checks passed
Copy link

🎉 This PR is included in version 0.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants