Skip to content

Commit

Permalink
[Codegen] remove trailing zeros after numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
isuckatcs committed Jul 3, 2024
1 parent 9aa3b81 commit 6135606
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void Codegen::generateBuiltinPrintBody() {
auto *printf = llvm::Function::Create(
functionType, llvm::Function::ExternalLinkage, "printf", *module);

auto *formatStr = builder.CreateGlobalStringPtr("%f\n");
auto *formatStr = builder.CreateGlobalStringPtr("%.15g\n");
llvm::Value *param;
for (auto &&fn : resolvedSourceFile) {
if (fn->identifier != "print")
Expand Down
2 changes: 1 addition & 1 deletion test/codegen/cond_binop_side_effect.al
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: compiler %s -llvm-dump 2>&1 | filecheck %s
// RUN: compiler %s -o cond_binop_side_effect && ./cond_binop_side_effect | grep -Plzx '1.000000\n2.000000\n3.000000\n4.000000\n5.000000\n7.000000\n10.000000\n13.000000\n14.000000\n15.000000\n16.000000\n'
// RUN: compiler %s -o cond_binop_side_effect && ./cond_binop_side_effect | grep -Plzx '1\n2\n3\n4\n5\n7\n10\n13\n14\n15\n16\n'
fn true(x: number): number {
print(x);
return 1.0;
Expand Down
2 changes: 1 addition & 1 deletion test/codegen/expressions.al
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: compiler %s -o expressions && ./expressions | grep -Plzx '1.000000\n-1.000000\n-9.000000\n'
// RUN: compiler %s -o expressions && ./expressions | grep -Plzx '1\n-1\n-9\n'
fn foo(x: number): number {
if x < (0.0 - 5.0) {
return (0.0 - 1.0);
Expand Down
2 changes: 1 addition & 1 deletion test/codegen/multiple_return_if.al
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: compiler %s -llvm-dump 2>&1 | filecheck %s
// RUN: compiler %s -o multiple_return_if && ./multiple_return_if | grep -Plz '2.000000\n10.000000\n5.200000\n'
// RUN: compiler %s -o multiple_return_if && ./multiple_return_if | grep -Plzx '2\n10\n5.2\n'
fn foo(x: number): number {
if x == 1.0 {
return 2.0;
Expand Down
2 changes: 1 addition & 1 deletion test/codegen/multiple_return_while.al
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: compiler %s -llvm-dump 2>&1 | filecheck %s
// RUN: compiler %s -o multiple_return_while && ./multiple_return_while | grep -Plz '0.000000\n5.000000\n3.000000\n'
// RUN: compiler %s -o multiple_return_while && ./multiple_return_while | grep -Plzx '0\n5\n3\n'
fn foo(x: number): number {
var n: number = x;
while n > 10.0 {
Expand Down
8 changes: 8 additions & 0 deletions test/codegen/print.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: compiler %s -o print && ./print | grep -Plzx '0\n1\n1.2345\n1.0002345\n12345.6789\n'
fn main(): void {
print(0.0);
print(01.0);
print(1.234500000);
print(1.000234500000);
print(12345.6789);
}
2 changes: 1 addition & 1 deletion test/codegen/while_empty_exit_ret.al
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: compiler %s -llvm-dump 2>&1 | filecheck %s
// RUN: compiler %s -o while_empty_exit_ret && ./while_empty_exit_ret | grep -Plzx '2.000000\n'
// RUN: compiler %s -o while_empty_exit_ret && ./while_empty_exit_ret | grep -Plzx '2\n'
fn foo(x: number): void {
var i: number = x;

Expand Down

0 comments on commit 6135606

Please sign in to comment.