From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id MAuBJd0/GmfIEAEAe85BDQ:P1 (envelope-from ) for ; Thu, 24 Oct 2024 14:38:53 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id MAuBJd0/GmfIEAEAe85BDQ (envelope-from ) for ; Thu, 24 Oct 2024 14:38:53 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=YNQziui2; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=wLpPi0yD; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1729773533; 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=F3NIcYFl7XU1BUegyuyQiDe1UZ2l3YWLPJOU4YsQgNo=; b=4gZl6q8a946IezhcrVcga+55W02zc4yz6MengXpuROPPr7xCa9k/VHccTMRXrmOmmHy2Gp 2+d0dAw3TolQ1HwBr4AenddkKaRdFfVWS4aO3Qf00cV5wNgREX9CIM0QW3fStUJXCr6txK n6iczb4Bpc6Aci50YMPWRMnS8Rw+K9/H5XHuraB0Ewart7TbiqTd+q19NqYa0mSq9L8+5M ejLuADUHUX3NVW35rbuUMOrt9MIyWy4e2o/yUVsa+J2mp4cjSeGEHx6jXhVxo8WCRCl6B8 uEbz+HbD6BJvX4lM45roLrN2N8nia/APE7IeyjfaIyWfWNYKgFVfuqK9smKMfg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=YNQziui2; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=wLpPi0yD; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1729773533; a=rsa-sha256; cv=pass; b=yrTsu5Lev/WI3MMbHujikMfX/dwu1af0bZ6bZ3Tb5+w70EAphfMtRYOOOLpmkLBvNwJq2w E9luXiDNUhb3r8Dag9fBCqYKNHrANwZzYErjwH6foNVOyGHaYhXNvXmxzGrSRQQUVf9Es+ 5/AYZgKTOTu3G6rO3UY/+t1cXlJN5fdvTkHWtsqknaJEHNJg7TsKwbChdMqM7fNTB1aMik SuLC5+pyQM+w9YbIL16NnkNOyKvqNiPUHZIKuoUqiJLEsFyxqafOIHdF0gWYZP1k2/Av7/ fsas5awPZxh1RqX0CZWeCwMUMprCYtfuZXtAaiGsaRzd0p3iwScQP3QAGl86vA== 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 5F52B78F92 for ; Thu, 24 Oct 2024 14:38:53 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=Aj13CwX4ZKgI4YBmCKDnOcGqLguADoyj0fIvd2njKd0=; 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=1729773533; v=1; b=YNQziui2+lMFmE64klCM/N76wgfi4qENlolgp0fDui2vsZbhh4JtqH4LE/nasELI/30w0pYO /tuvD+GGxBlD5CAZUAxfD18hcaDd6XcJ1vGAbde5LDhsV6GqwqkbbT6a1m4T7SMuFP1T7+Kwpom UEzzvRrnBaPR3etDT0DCiCxd/Dgp/THpWcrnhu1YDAOZUBNimclC6PbZNDPPT8m4o59Bw92aHbw jihVORfrhXPZzexiZhvHzmnNQRZXvWyvcaCMYelrMQMEDLi16PuTTuZnnfPpL8PPYw7xAWtLq8v 6UOTlGVF3h1Uj/tDmo7I/2cT/SaJqV33IW0qTaUhob9dA== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 2C4A420350 for ; Thu, 24 Oct 2024 12:38:53 +0000 (UTC) Received: from poodle.tulip.relay.mailchannels.net (poodle.tulip.relay.mailchannels.net [23.83.218.249]) by mail-a.sr.ht (Postfix) with ESMTPS id 98DEA20347 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:51 +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 1BADE1C5543 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:50 +0000 (UTC) Received: from nl-srv-smtpout1.hostinger.io (100-99-177-130.trex-nlb.outbound.svc.cluster.local [100.99.177.130]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 5229F1C56B1 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:47 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1729773527; a=rsa-sha256; cv=none; b=1MUvjOJJCyCx/JTRB6Lb3J/tnoIN3q8j1o5rflKkLAhaJtJdoZzEautCg9UtmwJng6j4F5 /vaUpFhnABBzmhAIwUIToCpUjYZfeuEtzPc4HEwMhIYChNe28WCv7CoDY9hMFThDpZ5qzB t4VMAS+iDOUsFyuFrs3LjkdWJWhS7VBiljVzUn8cjg98hAxINmEj8hosG4AGC8HUGvncZO tW96qBAg1D8Y2vneCfC/u+RdfsKV2MzWazlffDA4pxSosw/ImdnIkTZ8qvQcBmOrfyhcNz j9pTxZfLstLKxB0yvJKB9Xbl9VjMvlQ5Swc6mD5DPDDvvs2OKgB5rwUehk9h/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1729773527; 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=F3NIcYFl7XU1BUegyuyQiDe1UZ2l3YWLPJOU4YsQgNo=; b=4RxRceGOTVz03FNpbh3ayqYXrUw2fyuwxa0BCiD1LS7y/WJcvpY0qOZ88keHoxy4V9S19q z6Zuxj0QSJoQ+a0waNUURdBJUHrsRCkkLl3GK/ZYQSMs8KJdFQg3hSRxwcLZKpbvCBnvNb NWPRKfXflLTl1OdP8cVmUC/fCm5/Q9eIswWFcgsYw2aHmgwy20lP5DUBnw5ON8RecKYzl+ oZMZW3FUf05oBlIQRMeR0CI4FqRJbR0a8Opum6t+OMwC/ulsb29iEkAa7TyzCkKy3nnKvw 4ZrxBryYTlJ9uzwtYm5vCzdwYr8AbwUdM4b9DCGfDXULBTGe+vSneSrt0kwFWg== ARC-Authentication-Results: i=1; rspamd-7767f6b98-frtv4; 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-Name-Invention: 5520785f6410f1e4_1729773530008_614335042 X-MC-Loop-Signature: 1729773530008:1246171819 X-MC-Ingress-Time: 1729773530008 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.99.177.130 (trex/7.0.2); Thu, 24 Oct 2024 12:38:50 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1729773525; 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=F3NIcYFl7XU1BUegyuyQiDe1UZ2l3YWLPJOU4YsQgNo=; b=wLpPi0yD2Pq0/cfjhXaqwicW1WrGouEQO3h+B4DPAynOqdZ9uhXERyznyetp3xRkv6BpL0 PIRnCqLCT/RfbcUKIv13f6RbYKDYP3UPR8pH5SG2asA5g1iJ59zo8XJyMLTK2xUAaMFnaY h38VCkcBXusyangqg5M7gZ9wAOsgLIoO8rQHw1y904hiPT3KzhgP1I8zp4WBFZT6ZNKXeF yn4J7qy3jGx+M07WfnhPzYkcNx8JvD5wohz7RWQxAl+tzb2/ALEKKIReZXMtfm21QcNqXS CyfQMtTwOkwoQ1tKcOL2yldXwzOT4jGmZmyfqFrIrojfk9vintOknRIJkTQIHA== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 4/6] semantics: refactor: use the ast_id_t into the fn_def.params Message-ID: <20241024123825.120390-5-carlos@maniero.me> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241024123825.120390-1-carlos@maniero.me> References: <20241024123825.120390-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Thu, 24 Oct 2024 12:38:45 +0000 (UTC) X-CM-Envelope: MS4xfG+07qwbeCmKQ5Th+Mz08CLXAkhAkQvo4cQtY8LRRteycgz4tEW1lCtV7ahqunMJ7Ry/M4D77oYf9zVhsxuOqKbSJKh02hhdaosqtbTm5osUj8ZFkA5p IJWR0YwcgtGpPo0HpadTAl+xO5Jkf5wuVrxnWPzQT/F0CpGEF2x6ggd8Qdoo02B3SOzksHHLc3N4N1J8XvpdNAF3I3jcKficarMEdxbSfWARUsvN9tF2nGhk X-CM-Analysis: v=2.4 cv=VemlP0p9 c=1 sm=1 tr=0 ts=671a3fd5 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=auKJ7hgzAjVp0e9oPzEA:9 a=BXDaF_L80NY05PYiAFlV:22 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-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -1.54 X-Spam-Score: -1.54 X-Migadu-Queue-Id: 5F52B78F92 X-TUID: OXnSvU7OGxki With this refactor the codegen no longer perform symbol_lookups by receiving the symbols fully resolved at the semantics level. Signed-off-by: Carlos Maniero --- src/ast.c | 2 +- src/ast.h | 2 +- src/codegen_x86_64.c | 9 ++++----- src/pretty_print_ast.c | 2 +- src/type_checker.c | 4 +--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ast.c b/src/ast.c index e0722d8..6d83bd3 100644 --- a/src/ast.c +++ b/src/ast.c @@ -253,7 +253,7 @@ ast_new_fn_param(arena_t *arena, string_view_t id, type_t *type) (ast_fn_param_t *)arena_alloc(arena, sizeof(ast_fn_param_t)); assert(fn_param); - fn_param->id = id; + fn_param->id.name = id; fn_param->type = type; return fn_param; diff --git a/src/ast.h b/src/ast.h index 048d725..8cf072a 100644 --- a/src/ast.h +++ b/src/ast.h @@ -83,7 +83,7 @@ typedef struct ast_translation_unit typedef struct ast_fn_param { - string_view_t id; + ast_id_t id; type_t *type; } ast_fn_param_t; diff --git a/src/codegen_x86_64.c b/src/codegen_x86_64.c index 936a77b..57c201b 100644 --- a/src/codegen_x86_64.c +++ b/src/codegen_x86_64.c @@ -894,19 +894,18 @@ codegen_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_param_t *param = item->value; - symbol_t *symbol = scope_lookup(fn_def->scope, param->id); - assert(symbol); - // FIXME: add offset according to the param size codegen->base_offset += 8; size_t offset = codegen->base_offset; - codegen_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset); + codegen_x86_64_put_stack_offset( + codegen, param->id.symbol, codegen->base_offset); fprintf(codegen->out, " mov %s, -%ld(%%rbp)\n", // FIXME: Type may not be an as_primitive - get_reg_for(x86_call_args[i], symbol->type->as_primitive.size), + get_reg_for(x86_call_args[i], + param->id.symbol->type->as_primitive.size), offset); ++i; diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index f65c253..6ae8358 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -120,7 +120,7 @@ pretty_print_new_fn_param(ast_fn_param_t *param, arena_t *arena) char name[256]; sprintf(name, "Param_Definition ", - SV_ARG(param->id), + SV_ARG(param->id.name), SV_ARG(param->type->id)); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); diff --git a/src/type_checker.c b/src/type_checker.c index 9481539..5864f79 100644 --- a/src/type_checker.c +++ b/src/type_checker.c @@ -162,9 +162,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) ast_fn_param_t *param = (ast_fn_param_t *)item->value; type_resolve(param->type); - symbol_t *symbol = - symbol_new(checker->arena, param->id, param->type); - scope_insert(fn_def->scope, symbol); + register_id(checker, scope, ¶m->id, param->type); item = list_next(item); } -- 2.46.1