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

Add space between multiple strings while printing #2670

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7981,9 +7981,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
for (size_t i=0; i<x.n_values; i++) {
if (i != 0) {
fmt.push_back("%s");
if (global_sep_space &&
!(ASRUtils::is_character(*ASRUtils::expr_type(x.m_values[i]))
&& ASRUtils::is_character(*ASRUtils::expr_type(x.m_values[i - 1])))) {
if (global_sep_space) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The way to fix this such that we print spaces when two consecutive arguments are strings in LPython and not print spaces for the same in LFortran, is to support this in AST->ASR Translation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You will need to figure out how to update the middle-ends of both lfortran and lpython such that both of them work as expected when two consecutive arguments are strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Shaikh-Ubaid thanks for this! I will try to create a solution that works for both. 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

See if your solution works for both lpython and lfortran (test it locally on your system or send a PR to lfortran so it gets tested at the CI). If no run reference tests change for lfortran, then it works.

You can also test your current approach with lfortran. If it works currently, then I think its good.

args.push_back(sep);
} else {
sep_no_space = sep_no_space != nullptr ? sep_no_space : builder->CreateGlobalStringPtr("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "runtime-test_list_item_mixed_print-a3fd49f.stdout",
"stdout_hash": "9d9a68fea29f11320efb0764ce38ed3d4090f64457b0f1eb10251a2b",
"stdout_hash": "382a58aa2b426d46c2f22f343df9d99eb41653855b679300aade5102",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hello
This isLPython
Hello
This is LPython
1 2 3 ... 3 4 5
The first element is: 1
The middle element is: 3
Expand Down
Loading