From: "Carlos Maniero" <carlos@maniero.me>
To: "Johnny Richard" <johnny@johnnyrichard.com>,
<~johnnyrichard/olang-devel@lists.sr.ht>
Subject: Re: [PATCH olang v1 2/2] codegen: x86_64: implement binary operations
Date: Thu, 02 May 2024 23:04:58 -0300 [thread overview]
Message-ID: <D0ZN3DOG7JK9.1C06QASWNCXQ3@maniero.me> (raw)
In-Reply-To: <20240427121832.203068-3-johnny@johnnyrichard.com>
That's a brilliant work man. I'm inspired in how simple the code is. I
even took a look at our previous work on pipa, and this patch is art
compared with pipa's implementation. Kudos!
There is just one issue with the current implementation:
> case AST_BINOP_DIVISION: {
> codegen_linux_x86_64_emit_expression(out, bin_op.rhs);
> fprintf(out, " push %%rax\n");
>
> codegen_linux_x86_64_emit_expression(out, bin_op.lhs);
> fprintf(out, " pop %%rcx\n");
> fprintf(out, " div %%rcx\n");
>
> return;
> }
You should always ensure *rdx* is zero right before calling the *div*
instruction otherwise the code bellow will return an unexpected value.
fn main(): u32 {
return 7 / 3 / 3
}
The same is valid for the reminder operation.
I also missed integration tests, the issue I described before could only
be catch over an integration test. I know we don't have the best ever
developer experience for integration tests, but following the
*test_cli_compile_minimal_program* test structure could save us a lot of
time in the future during refactors.
next prev parent reply other threads:[~2024-05-03 2:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-27 12:14 [PATCH olang v1 0/2] " Johnny Richard
2024-04-27 12:14 ` [PATCH olang v1 1/2] codegen: x86_64: extract function to emit expression Johnny Richard
2024-04-27 12:14 ` [PATCH olang v1 2/2] codegen: x86_64: implement binary operations Johnny Richard
2024-04-27 11:21 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-05-03 2:04 ` Carlos Maniero [this message]
2024-08-25 13:52 ` [PATCH olang v1 0/2] codegen: x86_64: implement binary operations Johnny Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D0ZN3DOG7JK9.1C06QASWNCXQ3@maniero.me \
--to=carlos@maniero.me \
--cc=johnny@johnnyrichard.com \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox