public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>,
	Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang 4/5] codegen: reset variable offset on block leave
Date: Sat, 21 Sep 2024 01:13:15 +0000 (UTC)	[thread overview]
Message-ID: <20240921011234.191248-5-carlos@maniero.me> (raw)
In-Reply-To: <20240921011234.191248-1-carlos@maniero.me>

The block should reset the offset to avoid unnecessary stack consumption.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
Co-authored-by: Johnny Richard <johnny@johnnyrichard.com>
---
 src/codegen_linux_x86_64.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 4e0ea52..640c9fb 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -333,7 +333,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr
 static void
 codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
 {
-
+    size_t block_offset = codegen->base_offset;
     size_t nodes_len = list_size(block->nodes);
 
     for (size_t i = 0; i < nodes_len; ++i) {
@@ -414,6 +414,8 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
             }
         }
     }
+
+    codegen->base_offset = block_offset;
 }
 
 static void
-- 
2.34.1


  parent reply	other threads:[~2024-09-21  1:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-21  1:12 [PATCH olang 0/5] fix multiple variables Carlos Maniero
2024-09-21  1:12 ` [PATCH olang 1/5] map: add function to retrieve all key-value pairs Carlos Maniero
2024-09-21  1:12 ` [PATCH olang 2/5] scope: make scope a bi-directional tree Carlos Maniero
2024-09-21  1:13 ` [PATCH olang 3/5] ast: checker: add function scope Carlos Maniero
2024-09-21  1:13 ` Carlos Maniero [this message]
2024-09-21  1:13 ` [PATCH olang 5/5] codegen: preserve function's variable stack location Carlos Maniero
2024-09-21  1:13   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-21  1:25 ` [PATCH olang 0/5] fix multiple variables 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=20240921011234.191248-5-carlos@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