From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.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 UIb1BuI/GmdClgAA62LTzQ:P1 (envelope-from ) for ; Thu, 24 Oct 2024 14:38:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id UIb1BuI/GmdClgAA62LTzQ (envelope-from ) for ; Thu, 24 Oct 2024 14:38:58 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Q584g9XI; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=ZAgxyrng; 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=1729773537; 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=HSinQVldVwh8+ryFlJVxQwH90Sbfc8LheOZiXsU9wcQ=; b=16x3w4FyKjgMsCT0yukoYR4oEXqP8aZKmM6rc/trZiBqrlBJCTJ05egurq6AW1xiySb8AY 8ZGdzCuicgJ/RYHvGYH7Qn6ZY9EaQJZ0KtGuuKhKIK3R3zGCE8AFGJ/13R3YPEpM4GsIlM Mh/B6NfdQ+CB+qU4u0+3GDv/I7rkrGNCQ0S5nCzOZ14me5XP3udBSSt0XjUBntZkMp0G/P beqBREid0J4TjmPPWVakbj1UyqyOBwhmmMDGdIUImwTTTIJGKdcyvVahDUferiRZzOpEig PrMWIo1eCmqqodiQpJij5beOSnQA/xyxG9jbZasaWFKS0JMVH3sgjIWeUmsV+w== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1729773537; a=rsa-sha256; cv=pass; b=J1XJ2YB0fit7hNXavb4i0IfEN77TlM/Zp+sm0CAUVrqA3aeQqp3l9+hwPnD6p5Awqho+jT X1XrNukySVNeuE1n18G4y0Vbi1ZVSPZLE5vbar30I6VesN71ReaPUnlYqYDF3AW/ke1n5t langzMiNRnIaSY6DwbiPpP+R5arpM7fPT6kFcB5BQl9ygWGcmFp4fNMJfMIEM1bz3egK1G MPY9b3Z0Mf3wBCgMmuvjXq/YMGjk+5N45uCUPVQy84u6iAOWmeyhceGV9UmqEkUnJFbgu7 7zLj2kBFKUM+jtYyGrMLhIoKq0gefMn75jvzOLVq9OS9W2g3fY7L6s9gsqmN2A== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Q584g9XI; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=ZAgxyrng; 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 CA9B3876FB for ; Thu, 24 Oct 2024 14:38:54 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=0WvyLJmBSByJO6nDlNHMNC9lCA8hAH/f1B+rL7zw7rQ=; 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=1729773534; v=1; b=Q584g9XI467QwRLgkyRkgKEHHmak53ByE3GrZIEFO6Y7TK98RHtywxtEdn5N6PmYP1fk0QVp CV23xQ3RiU7gmT1t0WzmYJNZ30c7FPHPg91AlJyjBdHrsJSrMUksLhd/fDCa6g0b7p6XRp3Vm9T JjnMOQEz29OyFePaG8nD5ZAmbLo6+jIiKp8A79NKZJGy6B5F/sTZfRoByohiYgFGpyQ64bROdG/ ebCylykhEF7Ba5backW0srWShJNhKjViP90q3O0ooGUF5oH7prJBtbaHY0OxlC4AFgEzYSVWGMk 74onina8AiCuqS3QUPA2xL4hruIupzgJBWmqbBB2GtQvw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 6740320352 for ; Thu, 24 Oct 2024 12:38:54 +0000 (UTC) Received: from crab.ash.relay.mailchannels.net (crab.ash.relay.mailchannels.net [23.83.222.42]) by mail-a.sr.ht (Postfix) with ESMTPS id 6396220347 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:53 +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 B99BD783497 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:51 +0000 (UTC) Received: from nl-srv-smtpout1.hostinger.io (trex-0.trex.outbound.svc.cluster.local [100.99.209.54]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 3023F783486 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 24 Oct 2024 12:38:51 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1729773531; a=rsa-sha256; cv=none; b=RzLV6b3nJpY3z2XRpnYoV54iHvaPiODHU7LBLDwcZIGakW3XmCO9tz5lqzLGIffVm2X58N VOflnXts4ANZJtE78kAc9JrAu/qhrUoAtUpgr+piWIXSsAnfAQPcSs21KiiGEWWb0N8zA9 QbW+wSxfpQ7q5ID/i0IVgxlpXmB/6edNRJHcWWfKxO/+lvtzNpV0ZYHsXV7HdNiDsYx8if PF0bkBhKRJdgw6V8jvkcRt4shyZ47p3/N30lrY7VV6+7o6Fscau139XAtaXidDQ7j0W7ZN k6X5XN/39g4gBRTuDVR+ro/k7ZMnMu4y77Ph7sGW7oUqIpQ9heJWIp3sEMa9rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1729773531; 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=HSinQVldVwh8+ryFlJVxQwH90Sbfc8LheOZiXsU9wcQ=; b=BgNUk2fOnBoj5xAxKZuzZcm1Pyu3IV3L0FeYttCFjIbI9LejpHPEokW8OHn9iiOMrZQWPh x+5bFsuige9EBPxC2DNK2Nhi40955w4r2syBkDVSm49GGHiHzi0by6YRgAozVT2ynOJnDK LpKUyaH3kIefpgX+klsybAClg4QGMSmjtBu8ezOHg6alOX6/lMi8yFUQGz9eMBG/pL6GhM 92bWhyswWcVxPRTUmxuRIKzwaF3Tgt+uoxFNZe2U/a+nGQdLKxzyNXFzAomGHHCBFpmRnO cNoeHLTlMkpf7i6ELHTKsbMIce7nj7nRZRiJ7H8NlwVCozOfvxFQhb1ai+D4MQ== ARC-Authentication-Results: i=1; rspamd-7767f6b98-gn4hd; 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-Squirrel-Versed: 7ca66dbd0fcb29a5_1729773531661_3722989203 X-MC-Loop-Signature: 1729773531661:2793892781 X-MC-Ingress-Time: 1729773531661 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.209.54 (trex/7.0.2); Thu, 24 Oct 2024 12:38:51 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1729773529; 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=HSinQVldVwh8+ryFlJVxQwH90Sbfc8LheOZiXsU9wcQ=; b=ZAgxyrngx0WEUEOfplx+cIUY+OnJp2gq1tserzQrFG9HJQm1Oj1W4a1/pcQDD+2SaXOT2D PzrGwAbKew7hYboU3zNesRSrtqAG6tbRhHAsG2lub1f65PSg7uGRbUxEe0P95im7kalLwa DTU4tbWtsL+HqQCqfVoxujpOYgVIv+qUzjACzQUc9qPfgV0g866vp6sSu4ifa202F1RFGL by+thojqviYxvGqHcP5xKdEMtGubMh6x6ifhivtB3qlRXdJLCtW/NAFxDi6Lr5L+TxALoA 1QqCur9+I74GwDHEcZ8hdU5EVLYfTqL5PiIkOz4bn/KaREyllApkZztDcO4foQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 5/6] type: refactor: rename type.id to type.name Message-ID: <20241024123825.120390-6-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:48 +0000 (UTC) X-CM-Envelope: MS4xfPVEUQgeEsHUsaZqgMkyjh120WJr7HbhzQOEh9Q6rifwnCp79XVIolBLhI62P6A0H5QlK4yoqGLg6McoYdJfbO6/6S+XDDtDdYnP2hNBt0MIh1KtTUah HeeV3qXxdGRF3vmcE4QAFvJEq7pakINIGi6OJSoSsqsQnmbfbYpF6IMw0x8VNMmuCejlr+AcP5mQtE+kAsZIayQqJgjy5kSE2AEN8qq7s4mLjOuicMLaym0P X-CM-Analysis: v=2.4 cv=VemlP0p9 c=1 sm=1 tr=0 ts=671a3fd9 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.80 X-Spam-Score: -4.80 X-Migadu-Queue-Id: CA9B3876FB X-Migadu-Scanner: mx13.migadu.com X-TUID: ZjetfeJ5SnBR Now that there is a struct called ast_id_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 6ae8358..b9359ae 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->id.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.id.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 5864f79..f3911d8 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