From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.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 ENwOCvho72a1lQAAe85BDQ:P1 (envelope-from ) for ; Sun, 22 Sep 2024 02:46:48 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id ENwOCvho72a1lQAAe85BDQ (envelope-from ) for ; Sun, 22 Sep 2024 02:46:48 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=UXshspdo; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=ChFNH9ws; 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=1726966008; 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=znPX1Ag2K/dUbnooC8VzDUL85QW+tvhKtbXDv6G+sKU=; b=gyKnDECw2U+NkX43B1MX8h8pCoxoIkA+c0B5fn8rJf4ZooIz8C8pjZ4/uFLvVbtJeHNJGB oa9++vgIkiSMJxz5wW8bQRDY4ffCjqciTN23ohgXOMWH++lRZVbGwEEOzveJokpu0Bg0Zv bb2SJvpIfilLM3gD5elDXKC0BSWLJ6fNhkmM8ngF+rUD9jhhzFFUGe8obWtSs/ptI0jIBZ ODX7ug64rv7QPNbA7lvL6KV8Mzk967a0u3LgpwJwE/HRdcd8dkB6t9A/ZZYBsoPI5cuh6j iVQ61U6JfgepFDYfC6reqAPHWfg2oXLQb0A6jhuZRRxWFIpYVxz2qxFUjLzriQ== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1726966008; a=rsa-sha256; cv=pass; b=VGQJ7Tfj/JITSJiAU5F+8h3tMhhh/UHAEiggzXyMX2u8MpvCYiZcpUsmTn1V9q09880koo vmddgzD3p549WUnD5fxZmLp3EXjZ/OQYxXq/dqJfxiKFHKEKOoohRVvL+EWzCYBrHVRYd2 JKAvHUgQr1E8Ozaodmk7YvDHQC6parqRUqSvi5GC5tKNBWeCuLq1i0x5DP+WDgz+c1pws8 awkbQjwk+QwYYKudTQmahzpF6dwdMyItxIdB6d5fEpdhOV2brBQwi1scomwhTXw7wRfUmV yyHFdAUKdXS4YWkm0ZZ5a+NCB+q4yscmVBQH+n7vu7P4Xq6KrRHMtY0cQ6Te0w== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=UXshspdo; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=ChFNH9ws; 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 12C336088B for ; Sun, 22 Sep 2024 02:46:47 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=86I0230YtTYoEK+WtvAz/wWmzRWCH1U5FKaRDvYDCBk=; 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=1726966006; v=1; b=UXshspdohFywr1f+hwGP2hzJq1OoEbN9QDiLHPMSLdR087PtnSU59+JAqEyiNGGHwbSS3cwo jyNxmzC2IRTXteC/Pc4ofJ9JSFd0g8gvP+/Y3HPWVjgZAZV2M2eE90H3h/QfOdKFLQPPiNl5W1W vbgK5sLvHO87vpkp0rIY0jSiYY2Ul+4DpmJwsva28/nxdUycSQhh46fpRIKX53K4ZxBMkTkYPQZ 6ADGyo1cbKiLFr3e0Z6EHJez9D6+Iy7ryMk41NrH8N703HDKxsFcbuCaP/BExjtK/DNs5J//sBW 4IV/lpafmJBJK3hkX4PuGaHygH+Wx8j58CpE9cle8U4Gw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 9D2AF20305 for ; Sun, 22 Sep 2024 00:46:46 +0000 (UTC) Received: from sienna.cherry.relay.mailchannels.net (sienna.cherry.relay.mailchannels.net [23.83.223.165]) by mail-a.sr.ht (Postfix) with ESMTPS id 75359202CC for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 22 Sep 2024 00:46:42 +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 1384C1A266D for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 22 Sep 2024 00:46:41 +0000 (UTC) Received: from fr-int-smtpout5.hostinger.io (trex-6.trex.outbound.svc.cluster.local [100.99.101.224]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 72F221A2FB2 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 22 Sep 2024 00:46:40 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1726966000; a=rsa-sha256; cv=none; b=k58erVtOTz0PiOiN6kLMoNoT4OLXL55hscgDxeJs9G8KguY+U7UNbPzYJK1odl7+hBPgBa 3cHBwEVehNJVJQgwbEZTP9Tj+pN79yRJGwMug3dYEQ0BvdE2Z4nE4QC5nq6OC7+Xl6p+QS jGupPK0bfeg1nElSReExVi0XtG41x9dgyNGivtEZf7WvCoRAtHMB0/R4ReYXBYaTZZpU11 AH3/ntVEN1D2DuQRpUvHozQRTRfPIIONA96+bkyi/exiKS6it/CoAKhNrz7aI2bK/eAsaM i1wqQ2ARptnYhJvmZRpl/Eox6pYKGXKY7AHflp4TXKxejjVeiQrREDopaJ+4eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1726966000; 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=znPX1Ag2K/dUbnooC8VzDUL85QW+tvhKtbXDv6G+sKU=; b=UursDCSO3kObryRUdr5r/NOu9qCnpbowKDH54QtEdRSoUE5BjenKjjVmlrb48hDn12X8p9 cLYAzF3sa3ljleBvVSGVVPoziUO31nevM5kV6nyouQ+KoaYfhaU3aRMR0UZlcJxJgoHYQ+ qCTPT9bo4AhIy9Kaauq6EXm7hiX5JoxQoPFdV3zgxwyDSrsn8kGj03YSQ2ZS2j+43tk1ZB rP7uWDxwRR2qbMjbj5L6VoruJY2EZfPbR69K9qW0UpfLLlvwSZkMSc7ztN/LoyRH/Xq70r E38d5MWxwrHBTazX8cVnC5YIS/dZaSnG7aT6f65omSttO3qX15EaEnQBDA5PxQ== ARC-Authentication-Results: i=1; rspamd-5b46bcd97f-s2rjn; 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-Cold-Scare: 2c7e2e4a01b0f3e0_1726966000972_1662534426 X-MC-Loop-Signature: 1726966000972:2925510224 X-MC-Ingress-Time: 1726966000972 Received: from fr-int-smtpout5.hostinger.io (fr-int-smtpout5.hostinger.io [89.116.146.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.99.101.224 (trex/7.0.2); Sun, 22 Sep 2024 00:46:40 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1726965998; 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=znPX1Ag2K/dUbnooC8VzDUL85QW+tvhKtbXDv6G+sKU=; b=ChFNH9wsXxz/oWg10SAKRNtlGe2C/ohm3wqG1nolM0un2jawoRwEe6N4uSDHSyfDwDJPCR h0G4hSu8Es8OFtqvcYu3vJFY1wLk+K7DOnxHzb4WS1yzi2ShfrZwBWxTClkh7ofrCfT2bg u6dlAKEze8fKYk1++/naTtObZp3iWMH9DWrqZBofzcTI5hm1IDEEIO0bYwgbK+FvcJaGRP 8wdf60fTOuv2i5DMtnWc7Vlsh0m1kyu8BDDRwx4eihQaaREANKFiiHKUyhfezHtFwJ1Svv eZGwdQx31eUlmrR/3H6CpnL5a5UHlhU7x91s3Ysu4aXjFO6NfdPaV6vsXStHug== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v2 2/4] checker: scope: populate symbol's type Message-Id: <20240922004619.518310-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240922004619.518310-1-carlos@maniero.me> References: <20240922004619.518310-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Sun, 22 Sep 2024 00:46:38 +0000 (UTC) X-CM-Analysis: v=2.4 cv=SpTC6+O0 c=1 sm=1 tr=0 ts=66ef68ee a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=mDV3o1hIAAAA:8 a=RnZcVRIpV9TlLSNgdNoA:9 a=1ZBrrQ3mb_2f3s7f-pIo:22 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfOX+Zwyhtc8PPMhLltfH0RoHdwHmLWtQ01wJtEt4M5ZjdSl7kAFswFA4jteySk0qpuFujmk9RiAxDKqYQleDJtLc8RFo4iDpeW1D6AkhWzKq5LmYG8D2 g1sILmdzV53ya+gOlmKYQElIKzknB2D8kmLF7oaQXHsFRTg3BCIfgkY2ctez6UPijkigVK4aYsaG6yWBgJepEfFfbgE78iciOlddgFk7Qh2yELzAscR01Rmx 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.80 X-Migadu-Queue-Id: 12C336088B X-Spam-Score: -5.80 X-TUID: ZZT0znxxgxGc Persisting the symbol type will be very convenient for codegen once it can be used to determine which register it will use to operate this type. Signed-off-by: Carlos Maniero --- src/ast.h | 1 + src/checker.c | 3 ++- src/scope.c | 3 ++- src/scope.h | 4 +++- src/type.c | 33 +++++++++++++++++++++++++++++++++ src/type.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/type.c create mode 100644 src/type.h diff --git a/src/ast.h b/src/ast.h index ff26ed8..7cb2ceb 100644 --- a/src/ast.h +++ b/src/ast.h @@ -23,6 +23,7 @@ #include "list.h" #include "scope.h" #include "string_view.h" +#include "type.h" typedef struct ast_node ast_node_t; diff --git a/src/checker.c b/src/checker.c index 3b713f7..6ffdc72 100644 --- a/src/checker.c +++ b/src/checker.c @@ -107,7 +107,8 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) case AST_NODE_VAR_DEF: { string_view_t id = ast->as_var_def.identifier; - symbol_t *symbol = symbol_new(checker->arena, id); + + symbol_t *symbol = symbol_new(checker->arena, id, type_from_id(ast->as_var_def.type)); scope_insert(scope, symbol); ast->as_var_def.scope = scope; diff --git a/src/scope.c b/src/scope.c index b23e865..81f610a 100644 --- a/src/scope.c +++ b/src/scope.c @@ -49,7 +49,7 @@ scope_new(arena_t *arena) } symbol_t * -symbol_new(arena_t *arena, string_view_t id) +symbol_new(arena_t *arena, string_view_t id, type_t type) { assert(arena); symbol_t *symbol = (symbol_t *)arena_alloc(arena, sizeof(symbol_t)); @@ -58,6 +58,7 @@ symbol_new(arena_t *arena, string_view_t id) exit(EXIT_FAILURE); } symbol->id = id; + symbol->type = type; return symbol; } diff --git a/src/scope.h b/src/scope.h index 7f7eaae..92a5a4f 100644 --- a/src/scope.h +++ b/src/scope.h @@ -21,10 +21,12 @@ #include "list.h" #include "map.h" #include "string_view.h" +#include "type.h" typedef struct symbol { string_view_t id; + type_t type; } symbol_t; typedef struct scope @@ -39,7 +41,7 @@ scope_t * scope_new(arena_t *arena); symbol_t * -symbol_new(arena_t *arena, string_view_t id); +symbol_new(arena_t *arena, string_view_t id, type_t type); symbol_t * scope_lookup(scope_t *scope, string_view_t id); diff --git a/src/type.c b/src/type.c new file mode 100644 index 0000000..cbdfbde --- /dev/null +++ b/src/type.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 olang maintainers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "type.h" +#include "assert.h" + +type_t +type_from_id(string_view_t id) +{ + type_t type = { 0 }; + if (string_view_eq_to_cstr(id, "u32")) { + type.kind = TYPE_PRIMITIVE; + type.as_primitive.size = 4; + type.as_primitive.kind = TYPE_U32; + return type; + } + + // FIXME: handle user defined types + assert(0 && "unknown type"); +} diff --git a/src/type.h b/src/type.h new file mode 100644 index 0000000..b431171 --- /dev/null +++ b/src/type.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2024 olang maintainers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef TYPE_H +#define TYPE_H +#include "string_view.h" +typedef enum +{ + TYPE_PRIMITIVE +} type_kind_t; + +typedef enum +{ + TYPE_U32 +} type_primitive_kind_t; + +typedef struct type_primitive +{ + short size; + type_primitive_kind_t kind; +} type_primitive_t; + +typedef struct type +{ + string_view_t id; + type_kind_t kind; + union + { + type_primitive_t as_primitive; + }; +} type_t; + +type_t +type_from_id(string_view_t id); +#endif -- 2.34.1