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

Underscore: _ variable in REPL #2755

Merged
merged 5 commits into from
Jul 9, 2024

Conversation

Vipul-Cariappa
Copy link
Contributor

@Vipul-Cariappa Vipul-Cariappa commented Jul 6, 2024

Demo:

>>> 5
5
>>> _
5
>>> _ ** _
3125
>>> 2.5
2.5
>>> _
2.5
>>> _ ** _
9.8821176880261863

This PR is built on top of #2752. Therefore #2752 should be merged first.

@Vipul-Cariappa
Copy link
Contributor Author

cc @Shaikh-Ubaid

@@ -2709,11 +2712,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}

void visit_Variable(const ASR::Variable_t &x) {
if ((compiler_options.interactive) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if ((compiler_options.interactive) &&
if (compiler_options.interactive &&

Similarly others.

@@ -2709,11 +2712,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}

void visit_Variable(const ASR::Variable_t &x) {
if ((compiler_options.interactive) &&
(std::strcmp(x.m_name, "_") == 0) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it so that at some place we compare with (std::strcmp(x.m_name, "_") == 0) and at some we use (std::strcmp(x.m_name, compiler_options.po.global_underscore.c_str()) == 0)? What is the significance of compiler_options.po.global_underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous code block's last expression's value is stored in compiler_options.po.global_underscore, which is ___main__global_stmts_<int>__.
While generating IR for compiler_options.po.global_underscore, we store its hash in global_underscore_hash, then whenever we need a reference to _ variable, we use global_underscore_hash. So _ gets replaced with ___main__global_stmts_<int>__.

@Shaikh-Ubaid
Copy link
Collaborator

Looks good overall. Lets merge #2752 and rebase and resolve conflicts in this PR. After that I will have a look again.

@Shaikh-Ubaid Shaikh-Ubaid merged commit 8f3393d into lcompilers:main Jul 9, 2024
15 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the underscore branch July 27, 2024 12:23
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.

2 participants