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

Fix separator inside print #2820

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 1 addition & 11 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8432,14 +8432,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
args.push_back(nullptr); // reserve space for fmt_str
std::vector<std::string> fmt;
llvm::Value *sep = nullptr;
llvm::Value *sep_no_space = nullptr;
llvm::Value *end = nullptr;
bool global_sep_space = false;
if (x.m_separator) {
this->visit_expr_wrapper(x.m_separator, true);
sep = tmp;
} else {
global_sep_space = true;
sep = builder->CreateGlobalStringPtr(" ");
}
if (x.m_end) {
Expand All @@ -8451,14 +8448,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])))) {
args.push_back(sep);
} else {
sep_no_space = sep_no_space != nullptr ? sep_no_space : builder->CreateGlobalStringPtr("");
args.push_back(sep_no_space);
}
args.push_back(sep);
}
compute_fmt_specifier_and_arg(fmt, args, x.m_values[i], x.base.base.loc);
}
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": "cffcdb43864ef4e234dec5a10923f9077b7c6d1f4d9c37df1882f375",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Hello
This isLPython
Hello
This is LPython
1 2 3 ... 3 4 5
The first element is: 1
The middle element is: 3
3.14000000000000012e+00 * 2 = 6.28000000000000025e+00
Total: 9.41999999999999993e+00
(1, 2, 3) is a tuple, but 1 is a number.
123
1 is smaller than 2 is smaller than 3
1 # 2 # 3 # 4 # 5 #

List 0 : [1, 2]
Expand Down
Loading