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 ms5.migadu.com with LMTPS id sGhWE9uC7mYQAQAAe85BDQ:P1 (envelope-from ) for ; Sat, 21 Sep 2024 10:24:59 +0200 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 sGhWE9uC7mYQAQAAe85BDQ (envelope-from ) for ; Sat, 21 Sep 2024 10:24:59 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=GGPHLueK; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=N+oSqEGK; dmarc=pass (policy=none) header.from=maniero.me; 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") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726907099; 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=2NJlK2Tm0WTUWQg0p3JXnLxtr1aqKBh0VbciTG23XkY=; b=WASiBUXNNkkjV9DyvsKbFY3+Z++pbMUSnnyILg0u+lZAbo0qt0Ho/gItdKASWBXcBhZPdm k4FG9lT9I+APH96btNkJUZzclJtZWdMuhPAf0eZqaHcFJ2AagdM6nUZJIv0BREdzxXz/z/ DMLJmkvA0Sv9JQpzfJ4M89jztl+Mo6NzX1fGkos0mVXlPZGhK9vEblHfBLhNDcqNbF6pV1 iq6PnbtiultC2rNsfZhe1GKwDyoiAv9Vi8QUGIrI8pJDPKK6hK/+WZAC+W4MYYJZxmfeC+ 7CipZOs7Dsj9KIZXIBFHjiHRAPkZaY6D38YK8ZD+5KSGuaYxs7bFIoWWJ+xDjw== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1726907099; a=rsa-sha256; cv=pass; b=Si3SiwED/CrHHUEs4jmHteCql86kSbW65kulIbtgmTMUSG67+Tl6ujw/dTO/IkiJYf8Nli OeicpFNhXwzeVOuystUBs+SmnPubhx1FouJ0SaYEhyj1zQyGFatAQgye46JoPqkjdMwZW1 1kduVkfcfh5rqQpFmf0m/b83SQL774Bg9pXaN6dd6sr16am0Hp5a8G9hsZmVu6F+Ps8+90 IKxdxcdrYEItd277dObAGGXFA9bokhTwJdVWtprE6xZ6sMPBPbioo0BmStVhmGVg6EdkSt skfaQbhUkYoYZC28O4TdhT5T/cm7zEVtNwAApRCiwpPRpyc37i6pICcSbQwVEA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=GGPHLueK; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=N+oSqEGK; dmarc=pass (policy=none) header.from=maniero.me; 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") 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 0B5F313C90 for ; Sat, 21 Sep 2024 10:24:59 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=SGAA0/1UGX4fsYdKhKjxnyPdQHm3l9IEQLdbycnCxu0=; 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=1726907098; v=1; b=GGPHLueKDQ3iPYCg0Sp4sw9VWfMiqp4XuDlv2tkcESP6zPMgc5VKD//OfUGcHRl/ZwwD37Uc qHLFNCpapar/1K+eNKUBfLlPnG/PQhPnTOK1UtolAO9N6KqnGlhXQ7VlHNEw66nNI/OAgdJ3d9N i2pPhmi2iex40BBO9QAVwXgzl/42wul+HyDdUQcpB5VxnhU6NAqALx+Aytt2lrZ04cJvUjYFb2u MjWe+CAe0ZiSFxQpzTLzhCNhLfhjDQ6mLTJRgv+svJufLp9RConUSa5mR8M+r8s//62Rbg6+xxz 7qgOrjEbPJ5h3iZDd4EN41ZcclIFqbkle+X/3huTNjFgg== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id DCBEC2026F for ; Sat, 21 Sep 2024 08:24:58 +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 CAC3D20249 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 08:24:57 +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 2CAECA4620 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 08:24:56 +0000 (UTC) Received: from uk-fast-smtpout10.hostinger.io (trex-13.trex.outbound.svc.cluster.local [100.99.103.168]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 6C841A3A9D for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 08:24:55 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1726907095; a=rsa-sha256; cv=none; b=xdqkRrMP9vNgCyiFUyBZ/EcT6d4ppYVnU6h0ONBd478KfCZlmI1B9W+4wIBUwuJI7wNfuN gT9GcPbbOsEv7zMqS1q/frd+2X2f1ctdnYojp1F6sc7WpfHswts6kG+iN0fTP/eNBK0wow 3OuByzfq/7ytrDXZYmhP74QqyUyIAQeIDlTF8hJnHc7Sv2YeXdwzXRnXKpsjlDAMIiXlFu oYVozsSv1kpiKq/ACbXCMPelV6/xhPG42v+NT10dXnm+qbNhROpPca6W3K/Rj4KQICfJxF Hjt+pnoJM4YOWwSHgttJoJR2Gv/FbI0CnTMlEGCj/hrs8O12ENcEP/CxxRVzIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1726907095; 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=2NJlK2Tm0WTUWQg0p3JXnLxtr1aqKBh0VbciTG23XkY=; b=kCCCKSiUYhV7fZVTG05FUMVKjeWzxFc75dMiJhwWarj8KVmkS1GJLrxeXrkcDGJa4cffV5 e7mW4A2GX70p0F0+bRuwPm4iKuakZ88r5Jg8uUoc2wPTRfRzwNWpGvYsWj41sLslVrHTGK fcppfyE6lTMZEAZvHJxQmAyuH4S+6Jebga1CjmXO5hgtTmfHaT08m0zcBcr+tfh446rNJB XA2julPxWTo1frNzN9dleUeI1HNGVlDh/YsqoIehKxo3DeR5Mg5kyTjUVOsTWhlnyk8CWc zgNiRfeimx8ncYGGTkHjOCQkcrzw5WJwn/R+IbNStZtdc3Q/ti4goMi1jku9nw== ARC-Authentication-Results: i=1; rspamd-5b46bcd97f-7bkdm; 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-Occur-Grain: 5b51bcaa1d3a1644_1726907096087_102384506 X-MC-Loop-Signature: 1726907096087:2087235264 X-MC-Ingress-Time: 1726907096086 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.99.103.168 (trex/7.0.2); Sat, 21 Sep 2024 08:24:56 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1726907093; 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=2NJlK2Tm0WTUWQg0p3JXnLxtr1aqKBh0VbciTG23XkY=; b=N+oSqEGKuQbhKAy7Kj+hM4R17yadYEIxf/+25ryDx0eGk1BAF9eP7fB938YtVoP818ZOyD bJoKj9c2OSCL8+SgqyiWravvsI6nM88MA/nP9pXptg5xIyInpQWzD+cksC9JzbRkJVonUE krChwgXKAffhsmPb0FiqaXwPeYwQsCU25sISElW3y2ZTE6LzZpHJoHFMOFfdyf4kfoWfHN T00JFGcts+oRkTy2M+rcdhsSj3tFnd8fapLg2T+i3X4Bg2gEfXCAPTEIIWjiQ0h/hMOtEg R7oZKrWDyF2mfWVmLnKOQdoelswp5/hBRRbHtwHdfrbRYqe62fKRIw9w3kDPNg== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang 1/5] parser: replace type enum to an struction string id representation Message-Id: <20240921082437.396691-2-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240921082437.396691-1-carlos@maniero.me> References: <20240921082437.396691-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Sat, 21 Sep 2024 08:24:53 +0000 (UTC) X-CM-Envelope: MS4xfCsR6kr8283COyExrhYz1Q4GRKh4Hpw3bzE3/unhrDkgJ8ifr4gs7EsLP7YpkOzB4IBpGwG5YAgCxC/LZl5zazQAGxBK21NJSZWznU7H0+0wSVhgvV5v TZFi7qB1dvDcJcfba1GBfJboSaQelsf8S+zrp9I8z/WB/1WcacJ9PW5X4RuCELRAxM8jcdCCyRnryoHTJZrR4EKlgDAdRN8aYVzWwGZHVulSYdP0NGozU8fD X-CM-Analysis: v=2.4 cv=TcnEtgQh c=1 sm=1 tr=0 ts=66ee82d5 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=a8uIOLOK57XD-VAA3AMA: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-Spam-Score: -0.16 X-Spam-Score: -0.16 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Queue-Id: 0B5F313C90 X-TUID: LKUBIGFFi/Pb Ensuring the type is correct is a semantics/checker role. Instead of trying to converting it to an enum on the parses step it just store the identifier of the given type. Signed-off-by: Carlos Maniero --- src/ast.h | 4 ++-- src/parser.c | 7 ++----- src/pretty_print_ast.c | 4 ++-- tests/integration/tests/0001_main_exit.ol | 2 +- tests/integration/tests/0020_if_statement.ol | 2 +- tests/integration/tests/0023_else_statement.ol | 2 +- tests/integration/tests/0024_var_definition.ol | 2 +- tests/unit/parser_test.c | 2 +- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/ast.h b/src/ast.h index a45a271..72fcc3e 100644 --- a/src/ast.h +++ b/src/ast.h @@ -40,9 +40,9 @@ typedef enum AST_NODE_UNKNOWN } ast_node_kind_t; -typedef enum +typedef struct type { - TYPE_U32 + string_view_t id; } type_t; typedef struct ast_block diff --git a/src/parser.c b/src/parser.c index d71500f..6076a64 100644 --- a/src/parser.c +++ b/src/parser.c @@ -317,12 +317,9 @@ parser_parse_type(parser_t *parser, type_t *type) return false; } - if (string_view_eq_to_cstr(token.value, "u32")) { - *type = TYPE_U32; - return true; - } + type->id = token.value; - return false; + return true; } static ast_node_t * diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c index d6eef67..8a02095 100644 --- a/src/pretty_print_ast.c +++ b/src/pretty_print_ast.c @@ -126,9 +126,9 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena) char name[256]; sprintf(name, - "Function_Definition ", + "Function_Definition ", SV_ARG(fn_def.identifier), - fn_def.return_type); + SV_ARG(fn_def.return_type.id)); node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1)); strcpy(node->name, name); diff --git a/tests/integration/tests/0001_main_exit.ol b/tests/integration/tests/0001_main_exit.ol index f446eb9..9068434 100644 --- a/tests/integration/tests/0001_main_exit.ol +++ b/tests/integration/tests/0001_main_exit.ol @@ -24,7 +24,7 @@ fn main(): u32 { # # TEST test_ast WITH # Translation_Unit -# `-Function_Definition +# `-Function_Definition # `-Block # `-Return_Statement # `-Literal diff --git a/tests/integration/tests/0020_if_statement.ol b/tests/integration/tests/0020_if_statement.ol index d48122f..460a05e 100644 --- a/tests/integration/tests/0020_if_statement.ol +++ b/tests/integration/tests/0020_if_statement.ol @@ -29,7 +29,7 @@ fn main(): u32 { # TEST test_ast WITH # Translation_Unit -# `-Function_Definition +# `-Function_Definition # `-Block # |-If_Statement # | |-Binary_Operation (==) diff --git a/tests/integration/tests/0023_else_statement.ol b/tests/integration/tests/0023_else_statement.ol index fafb22e..f3ddc64 100644 --- a/tests/integration/tests/0023_else_statement.ol +++ b/tests/integration/tests/0023_else_statement.ol @@ -31,7 +31,7 @@ fn main(): u32 { # TEST test_ast WITH # Translation_Unit -# `-Function_Definition +# `-Function_Definition # `-Block # `-If_Statement # |-Binary_Operation (!=) diff --git a/tests/integration/tests/0024_var_definition.ol b/tests/integration/tests/0024_var_definition.ol index 5c23449..ebbcda4 100644 --- a/tests/integration/tests/0024_var_definition.ol +++ b/tests/integration/tests/0024_var_definition.ol @@ -28,7 +28,7 @@ fn main(): u32 { # TEST test_ast WITH # Translation_Unit -# `-Function_Definition +# `-Function_Definition # `-Block # |-Var_Definition # | `-Literal diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c index 3cdac41..33657df 100644 --- a/tests/unit/parser_test.c +++ b/tests/unit/parser_test.c @@ -51,7 +51,7 @@ parse_program_test(const MunitParameter params[], void *user_data_or_fixture) ast_fn_definition_t fn = program.fn->as_fn_def; assert_memory_equal(fn.identifier.size, fn.identifier.chars, "main"); - assert_uint(fn.return_type, ==, TYPE_U32); + assert_memory_equal(fn.return_type.id.size, fn.return_type.id.chars, "u32"); ast_node_t *block = fn.block; assert_not_null(block); -- 2.34.1