From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id +BFsB9j1ImcyqgAAe85BDQ:P1 (envelope-from ) for ; Thu, 31 Oct 2024 04:13:28 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id +BFsB9j1ImcyqgAAe85BDQ (envelope-from ) for ; Thu, 31 Oct 2024 04:13:28 +0100 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=SLzpXL1z; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=tvIWRgRk; 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=1730344407; 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=J9Rc+AM/okf5upN5NhSl0Dz/Su8yQAayBRtG7XVg0rU=; b=M1n0kIHgOaI83uH+SPlSw6lZWhS1KbR7zoLpENLoJ36fH9vRccfT9BaV+JOaSM6ERz47em vitKuOHsW2ot7X8qxJi8kepb0nvxHKZynVzX9pjopqazhBf5tV6kZ/vwezoyur/KpTVKCo EFAyKuWr258Mfn2xoakANv1jIkJUh2Juuzpv9YOq7XRL1Jfd3w85WEdN6vH2VhkEkOknle QqcEMo5+48orjJdpW+XtOaScDK6kH51XiD++gs50KyqdCuMaendLNJrbZ+MviIV+UbDHss iOl6VJYIKMAcebWWkSbOlxZMeCycmP+oR/ylAhcqftU32RkVghnUDLL5da4ttg== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1730344407; a=rsa-sha256; cv=pass; b=vf67t+VhIxG0RfWR9Ezxaz7fnDvidb79mCSyo7o/lUVZGk5ljHNHp+WV+x7/nOP2CUWyJR LRIeO1fjAbPro/SFxNVEme5B5bozJQrutT1X+KYQRlBl/pUiUfT64cYl+bLdbhH9M/6WAc MJhyEDgiA9ozOn4dbBxk7rFpRUph5v4fShhjht3m+QbXZWqkK7YA71y+MnAIUh2cktJVSy QzlcwjeEk/i7mQdHa6PqRcEebXaVXVF5qPAGqCvsT7Jh1beL6JSQXBahw5NYhdZFrnSyUM YMSYtHCeOyE+teUXTtL5aj0yD5GWQPkxOH02u8tEebM9PTCCY2sxdSlt0V/0UQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=SLzpXL1z; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=tvIWRgRk; 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 E2EBD7D8EB for ; Thu, 31 Oct 2024 04:13:27 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=eYhOfLwGVtq8wiEyYp2IsvIlsrb3lTWNuICR31BTi5E=; 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=1730344407; v=1; b=SLzpXL1zAuSkIJDdIctdfSVDlLVNHP+LnThc3EfrvpfeOjCy2zjeoMJtFmg2psW1eas372Gg RNDSQ6gyAooUJLHCs7v84r0+QA1iLNc4L2tvcj6Zw3ZJbsv6hbMI2ViWpZt58VTlOVvgdhGCNZZ kSo5Zhup/lhl2aRLUqlZ2jOBx7NHE/D54q7ZEGzLGumk1JhtxReuQ8a+soYTivl44OMtGRg0QMB ZFZ+mhBEHf1PDYN6ADNctxX51JENtQOWWKgR/7ThjR8yp7n2zVIwYYYF8XMQ2bjyTR8CPhW7a6p ERSV5sxtA5Pe2hOoXJCIGXMXwjDEahpG78cLFI9Qtoqpw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id C64F420396 for ; Thu, 31 Oct 2024 03:13:27 +0000 (UTC) Received: from bisque.elm.relay.mailchannels.net (bisque.elm.relay.mailchannels.net [23.83.212.18]) by mail-a.sr.ht (Postfix) with ESMTPS id C262820383 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 31 Oct 2024 03:13:26 +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 1FF538C1CDB for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 31 Oct 2024 03:13:25 +0000 (UTC) Received: from uk-fast-smtpout10.hostinger.io (100-103-134-71.trex-nlb.outbound.svc.cluster.local [100.103.134.71]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 602048C1C04 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 31 Oct 2024 03:13:24 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1730344404; a=rsa-sha256; cv=none; b=7I4K4s/R80DeSqs/FMEQDoERxpj+UFCNcoiF7HOFfKarQtEKAyaKFomnNMsNeVUkGvP4lb Cfar1mfi+0Hdw67oFbaM9kNTS+5Ph92LqhSOktTQVtGeuufEvAzYdDkQ66gT5oEg7wlK8K jWeDuVoVgtfhMS3QxvYoYd87S5gl+B7Hi3ZkAgSNxwi/DgIU+1FOrYCpjW8Yo+SBTACbWD O1SqqrXhnU+rlIQvu4JVxF/2CvADDNXNlC9rrzsHQBBu8dVLc+rNWu79PZx0V2IgyWI2MY 5x+3LISauzuUln8RbxBasdUdK4g/KfWoTKhBy+PJwE+Q2Mj641g/d5jrE89xHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1730344404; 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=J9Rc+AM/okf5upN5NhSl0Dz/Su8yQAayBRtG7XVg0rU=; b=OFhg1C7CR7c1xxQKD52SnXXd4z8MbNlKHs11JF8B+MpJmQE8EcdP8Vd3LhqKcG+E6Qfk06 bY68rcD/lTf2/OpI4KWBFBI65s2F6FBa8rEjFkNqkglRFkRTm1T9aD9V5iooIojoG/5hgH U/OXrVxfBEDEvaPVG1vRZgLs/p9nAqvOCefYYym9CuHlgqQEDovgITfrhoDyt6MuLdd0M4 55w+nd5P5ofBnInPoeQJKz2b89oWR25aKIKc6NhEgBCWY7A7pQfeBopKKlE91ivOqSUEpq ioS5w1yOHyE8zR7WD+zUb8XA5a0ClKaxDJAEYBA3D6RFMEkSKPkyQsgS8ZvZlA== ARC-Authentication-Results: i=1; rspamd-77cfccfb8-4kj4d; 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-Cure-Interest: 6754832e2ccbc41c_1730344405028_166253371 X-MC-Loop-Signature: 1730344405027:4186619848 X-MC-Ingress-Time: 1730344405027 Received: from uk-fast-smtpout10.hostinger.io (uk-fast-smtpout10.hostinger.io [145.14.155.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.103.134.71 (trex/7.0.2); Thu, 31 Oct 2024 03:13:25 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1730344402; 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=J9Rc+AM/okf5upN5NhSl0Dz/Su8yQAayBRtG7XVg0rU=; b=tvIWRgRk960Nq7rG7G5Pv6m++I0o5MFhMVTQpOKx56nmV2BgC/D2lc3K6YpErZOao5ME2/ 0rurzex1t4VsKj3t5dBgnmy/q3JNwb1clQ3CzJ2yacaxYEx3++WU93OrTcQK9DGg7+XOJe qK3GCpjvr8auKm3S9Vs0sGDgvACbSXUtvMFoZEPRlZFLOksp8755uC7ue2KkhlyxflKhym LYKR2RJWfcL8AS3MBELPLiMKEj5EVrSVzIktx4SGj3UwwnHcTauSpa4lSFmdP3bzx/HfMQ B24nNw6Ng7sdMGkW+sGYPcaEftpZWq3K2LlJ8pkW/XOPA98FxJ7s/fR+3H0hdA== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v2 5/6] type: refactor: rename type.id to type.name Message-ID: <20241031031302.136553-6-carlos@maniero.me> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241031031302.136553-1-carlos@maniero.me> References: <20241031031302.136553-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Thu, 31 Oct 2024 03:13:22 +0000 (UTC) X-CM-Envelope: MS4xfJgCUKWb9JZvrf57G09xEEWhEaug5pSPkUdan1HBqK9t9hqp5wssIs8d+cti0ja3Y6/Tq2LRGYFQrOygVJnlmQaKmIoZypXf1cNr88yWyfQleiojcigH loI3+6c3e9d0nvOpoJWjZ4K/RY4kIrSErPMdVDVFog5ZeuT9OEL83tQRfDTQd0lnbktyMiB1LBOBk7WWjAgF8hbTZhxNr7DTasfgG878z0PZQ7JjE7Q4/1mW X-CM-Analysis: v=2.4 cv=MYc+uI/f c=1 sm=1 tr=0 ts=6722f5d2 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=YQ6v6vjFj8O37F1Lw0sA: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-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.76 X-Spam-Score: -4.76 X-Migadu-Queue-Id: E2EBD7D8EB X-Migadu-Scanner: mx13.migadu.com X-TUID: 9lRrbmR4rmLx Now that there is a struct called ast_ident_t the type.id may be interpreted as an ast_id, to avoid confusion, it was renamed to name which also is more meaningful since the id is not actually the type id (as per TOKEN_ID) but the full type string representation. ie: "u8***". Signed-off-by: Carlos Maniero --- src/pretty_print_ast.c | 6 +++--- src/type.c | 8 ++++---- src/type.h | 25 ++++++++++++++----------- src/type_checker.c | 14 +++++++------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index 9501159..7fbed75 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -121,7 +121,7 @@ pretty_print_new_fn_param(ast_fn_param_t *param, arena_t *arena) sprintf(name, "Param_Definition ", SV_ARG(param->ident.name), - SV_ARG(param->type->id)); + SV_ARG(param->type->name)); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); return node; @@ -158,7 +158,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) "Function_Definition %s", SV_ARG(fn_def.id), - SV_ARG(fn_def.return_type->id), + SV_ARG(fn_def.return_type->name), fn_def._extern ? " " : ""); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); @@ -290,7 +290,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) sprintf(name, "Var_Definition ", SV_ARG(var.ident.name), - SV_ARG(var.type->id)); + SV_ARG(var.type->name)); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); diff --git a/src/type.c b/src/type.c index 4a8d6f4..b146fb7 100644 --- a/src/type.c +++ b/src/type.c @@ -18,24 +18,24 @@ #include "assert.h" type_t * -type_new_unknown(arena_t *arena, string_view_t id) +type_new_unknown(arena_t *arena, string_view_t name) { type_t *type = arena_alloc(arena, sizeof(type_t)); assert(type); type->kind = TYPE_UNKNOWN; - type->id = id; + type->name = name; return type; } type_t * -type_new_ptr(arena_t *arena, string_view_t id, type_t *ref_type) +type_new_ptr(arena_t *arena, string_view_t name, type_t *ref_type) { type_t *type = arena_alloc(arena, sizeof(type_t)); assert(type); type->kind = TYPE_PTR; - type->id = id; + type->name = name; type->as_ptr.type = ref_type; return type; } diff --git a/src/type.h b/src/type.h index d930a88..e5f2481 100644 --- a/src/type.h +++ b/src/type.h @@ -19,6 +19,16 @@ #include "arena.h" #include "string_view.h" +#define TYPE_BASE \ + { \ + type_kind_t kind; \ + string_view_t name; \ + } + +#define TYPE_HEAD \ + type_kind_t base_kind; \ + string_view_t name + typedef union type type_t; typedef enum @@ -38,32 +48,25 @@ typedef enum typedef struct type_primitive { - type_kind_t _type_kind; - string_view_t id; + TYPE_HEAD; type_primitive_kind_t kind; short size; } type_primitive_t; typedef struct type_unknown { - type_kind_t _type_kind; - string_view_t id; + TYPE_HEAD; } type_unknown_t; typedef struct type_ptr { - type_kind_t _type_kind; - string_view_t id; + TYPE_HEAD; type_t *type; } type_ptr_t; typedef union type { - struct - { - type_kind_t kind; - string_view_t id; - }; + struct TYPE_BASE; type_unknown_t as_unknown; type_primitive_t as_primitive; type_ptr_t as_ptr; diff --git a/src/type_checker.c b/src/type_checker.c index ad51002..34a8d05 100644 --- a/src/type_checker.c +++ b/src/type_checker.c @@ -43,29 +43,29 @@ checker_new(arena_t *arena) } static type_t -type_from_id(string_view_t id) +type_from_id(string_view_t name) { type_t type = { 0 }; - type.id = id; - if (string_view_eq_to_cstr(id, "u8")) { + type.name = name; + if (string_view_eq_to_cstr(name, "u8")) { type.kind = TYPE_PRIMITIVE; type.as_primitive.size = 1; type.as_primitive.kind = TYPE_U8; return type; } - if (string_view_eq_to_cstr(id, "u16")) { + if (string_view_eq_to_cstr(name, "u16")) { type.kind = TYPE_PRIMITIVE; type.as_primitive.size = 2; type.as_primitive.kind = TYPE_U16; return type; } - if (string_view_eq_to_cstr(id, "u32")) { + if (string_view_eq_to_cstr(name, "u32")) { type.kind = TYPE_PRIMITIVE; type.as_primitive.size = 4; type.as_primitive.kind = TYPE_U32; return type; } - if (string_view_eq_to_cstr(id, "u64")) { + if (string_view_eq_to_cstr(name, "u64")) { type.kind = TYPE_PRIMITIVE; type.as_primitive.size = 8; type.as_primitive.kind = TYPE_U64; @@ -84,7 +84,7 @@ type_resolve(type_t *type) { switch (type->kind) { case TYPE_UNKNOWN: - *type = type_from_id(type->as_unknown.id); + *type = type_from_id(type->as_unknown.name); break; case TYPE_PTR: type_resolve(type->as_ptr.type); -- 2.46.1