From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6FHnAZ8d7mYGxQAA62LTzQ:P1 (envelope-from ) for ; Sat, 21 Sep 2024 03:13:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 6FHnAZ8d7mYGxQAA62LTzQ (envelope-from ) for ; Sat, 21 Sep 2024 03:13:03 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=JI8EuKGw; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=sIKjUk9+; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726881182; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=b7H9dMtGukMW2RlFm7LOldPpSoVbxzd8mYkQHzbyy64=; b=z3zzIpuOg0GyJLjFFj4l4rAfw1nfJGTbolyouTSVs8vFP9Zm7mbSjhtp8oAUf0FMh+IjZp j4dQmwpElIwFjnMZEHCTPmOphiD56X9emEu8t6nT+Huh2uJbalZ60LJ+HskJXY5e/kYPGe BemLXzSqPFhUEhMqlgtgJnpWw7BVzQr6SA6xQM3EB9ljeBkN/YLMkE7V2f+1rWpw2bKzmj oTpLZ20V/BHt2KuNd2toewZAXz2JR+74Tg1YhuBnofEE96IGUZZAjfripdgwnQEFWfIITZ 9W+HCBk+7UmyZtihW57PTCOCbIkH+CX/P83Mjd2MqNGoH3L+KWbmnmZ76Zm4eQ== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1726881182; a=rsa-sha256; cv=pass; b=kPzcNL1FLcDkTyLYOVCzz92QXdC8YElOrJ1TxeA9BYe7hKSGu8ELWd+2dpW/GyNVR5an7x ehZ0Bo5c0jpkFkoKx+suFHClOV2cW+jA+gleKrksW5dwnRU1c/qAYBjJoyAl9Yr/6Q1vuf K4DRMlsqVRR8Djzjtxky7AItZTX0Dk/ndMpBFb5GSREuvuA2lCm1HrfO/rSLjqqn+AQiUI MgaVHIcLb/ad3wfo+/BAlYZ76rz1UnZ91flm+XwhIISomFswgIJvQKbYQhsIBtiZMwz9kt CBqJa9u43u42Glsrg/preWzKhzd3qF4ILi0MfDUCkp7fprdpPfBp54HqTSespg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=JI8EuKGw; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=sIKjUk9+; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E39397A1BA for ; Sat, 21 Sep 2024 03:13:02 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=WjU4VB3cVRSrl4kOt98zeovbmtKiLk3fIv2Zh8MQA5w=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:In-Reply-To:References:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1726881182; v=1; b=JI8EuKGwHZWmR2ieFYgzHUcFbpH35iVStFB7q0kW0zZO4Q6xyJlIgiICy4IvAOqe3M2X0Ar6 ErjU10OKuo5tV6xhK6MnCmFcX7+FNXavBm3v8ZQrxhT0JNH1lygUnSu/TBpcVkfGckv5MB4Ewbp Az24Ith0l6CtvZJAvYRTbaf2fdzcRfe+QALJMm53zljj3IAIDNdE9TlLVQGsjQVrA7kvC8K4AQC H/NjC3M9ANhO2KGLvr8KJBY3CraKudmGBj8pF1+BrBzXX3beQ83v2a1iljMUOm6QmHqT5lK+7eU OaEy9R+N/YRTavq/YHOkgt68W48SHf8h3kM/m8GvfJkfQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 8E8742028A for ; Sat, 21 Sep 2024 01:13:02 +0000 (UTC) Received: from flamingo.ash.relay.mailchannels.net (flamingo.ash.relay.mailchannels.net [23.83.222.60]) by mail-a.sr.ht (Postfix) with ESMTPS id A13F520278 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 01:13:01 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id F167394A1E6 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 01:12:59 +0000 (UTC) Received: from nl-srv-smtpout1.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 63B3094A313 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 01:12:59 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1726881179; a=rsa-sha256; cv=none; b=OXpCnEd5ZtVV1mM0Z6nyUy3AZsAiDVVpAYLXILK/5v3BbX1mcrye6+NWZ3isHTaWkkgf78 bvEcpiTL19sgxlFAcycQJeK+PUxDvJeMdNmTfY+Y1sdlJqkBYPEq23Ux9WlIGgmTFjIgKl JxqoUQ44S3l1tAxf2IXLSDUuswwTziLSFjh+yUe3GVW+zrO+hte7i25vn0WxGqh3rPj+uB jBWdz/pbkbDL0zyGzpmu8kPyYEnCQGlpCZkDELYXfTKKat5IIoLW7hKLdJSpsngleq+ZMb 1+9mnkLskiXzcnfWBXUj98CzxvBMpfEFcEwoK2SRKJuNzWb9mv27Hcxd51tdig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1726881179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=b7H9dMtGukMW2RlFm7LOldPpSoVbxzd8mYkQHzbyy64=; b=oUfEx+kHAoKrIAKIwEsLzYB5wCslRMqC7gLWDS57jyxZj4TqLv/UUJoSyNiroeExtAr9O1 FIqInuI6/1ZoNM2nD7WrVBgydqS1anAnblOzgXwawYLy5ebkWFVEKNi3If66/Lx/4vVBhX RLruUtGxIuQFeZPHy+zxlR/+hqX275Ztdht941ZuHvg0nCuOScvr7gKP29qlO1SfoADfuZ rmlTzB2a/9Pknp0eM66ALM7KbXw4uEnkVOXYsASMZmCs8Q+vDBPVGfp+BHa5xWZrVWn6wx O+J0CTREF9SZtyOWnHcCtGdAawtIiV1MWU48lmiQTezdMRW3ts4JdluzM9+owA== ARC-Authentication-Results: i=1; rspamd-b5ccff48b-66kwb; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Well-Made-Bottle: 2c369ba774417120_1726881179868_2964524764 X-MC-Loop-Signature: 1726881179868:1703758240 X-MC-Ingress-Time: 1726881179868 Received: from nl-srv-smtpout1.hostinger.io (nl-srv-smtpout1.hostinger.io [145.14.150.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.125.154 (trex/7.0.2); Sat, 21 Sep 2024 01:12:59 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1726881177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7H9dMtGukMW2RlFm7LOldPpSoVbxzd8mYkQHzbyy64=; b=sIKjUk9+QRXexVHdqLL3COTTri579kVVXRRrW9viRtkOkrvToVVJn8Cp0COGY1Iujrqooj p9Zh1rsEDuIa4NfV9bJKJH+NAOCWDNyCvtmhpnCGGxKGwYiqVtFLMSb7P4vSYRiAw117A4 jaAu+4hOQGusFfNeZ/Fkea4TDQ4VuyuEOSsukK4ofOWC8QJxrwFs+oSRkM8jI2Eyisk+H1 PIUuwKJ+N4LiCysDj9c6mAFPDunzUPrW1RDEieRpnJekF4B/oQs3JTHBu6qVSxxCuWVEhO xUwuRSxHzo3RR4zLUDwIp0lP3exLg6pW+IOBTD6Zurm/cZfkoNaqFBOqJ1kT5A== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero , Johnny Richard Subject: [PATCH olang 2/5] scope: make scope a bi-directional tree Message-Id: <20240921011234.191248-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240921011234.191248-1-carlos@maniero.me> References: <20240921011234.191248-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Sat, 21 Sep 2024 01:12:57 +0000 (UTC) X-CM-Analysis: v=2.4 cv=c5X5Qg9l c=1 sm=1 tr=0 ts=66ee1d99 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=jziKOLAnAAAA:8 a=aBDPMG9rC79FbGWe7UAA:9 a=1ljl-wuu_96014yfT5Vk:22 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfCL9smplpQQjtILqSxfwZNYpmLI+OEZYBzPTPW8pNz5/EJP9IAw3USggXZ2TvGSw8rp8yrRdqpxD+Nrn3MhS/2d2leK2GPKCLtx54LxxnZJLh/zYsO2v 9t+o+oXg57M1TLfSfMBaWOtJOaC39bsQreXLUS+kXTXMXFeyRbpvXVBLSSmwzaxemub+aj0qhIfRRKkU+KwgmjQVo3k6JVZ6B6Icugw82spWsZkNqlnAcR4/ KGvcvJ5q0wE9GHDSVsfJ56cb1aNEGh4cSikpddg52MI= X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: UNKNOWN List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -5.13 X-Migadu-Queue-Id: E39397A1BA X-Spam-Score: -5.13 X-TUID: GFoyIfs66b55 In x86 architecture it is needed to reserve the stack space for local variables. The code generators needs to compute this value from diving into the tree from the function scope to the deepest level. So a bi-directional scope are required. Signed-off-by: Carlos Maniero Co-authored-by: Johnny Richard --- src/scope.c | 14 ++++++++++++++ src/scope.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/scope.c b/src/scope.c index 3271856..b23e865 100644 --- a/src/scope.c +++ b/src/scope.c @@ -33,6 +33,18 @@ scope_new(arena_t *arena) } scope->arena = arena; scope->symbols = map_new(arena); + + // FIXME: create a list_new function to avoid spreading this. + list_t *children = (list_t *)arena_alloc(arena, sizeof(list_t)); + + if (children == NULL) { + fprintf(stderr, "[FATAL] Out of memory: scope_new: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + list_init(children, arena); + + scope->children = children; return scope; } @@ -89,6 +101,8 @@ scope_push(scope_t *scope) scope_t *child = scope_new(scope->arena); child->parent = scope; + list_append(scope->children, child); + return child; } diff --git a/src/scope.h b/src/scope.h index ddb0cd0..7f7eaae 100644 --- a/src/scope.h +++ b/src/scope.h @@ -18,6 +18,7 @@ #define SCOPE_H #include "arena.h" +#include "list.h" #include "map.h" #include "string_view.h" @@ -29,6 +30,7 @@ typedef struct symbol typedef struct scope { struct scope *parent; + list_t *children; arena_t *arena; map_t *symbols; } scope_t; -- 2.34.1