From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6F+6FsEU72Z/+AAAe85BDQ:P1 (envelope-from ) for ; Sat, 21 Sep 2024 20:47:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 6F+6FsEU72Z/+AAAe85BDQ (envelope-from ) for ; Sat, 21 Sep 2024 20:47:29 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=fXRRloVC; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=OZmxJEBy; 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=quarantine) header.from=johnnyrichard.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726944449; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-unsubscribe:list-subscribe: list-post:dkim-signature; bh=eQoGyBuhrP7ZCkqpz5o04TdfvJznZddT+RSGg2umF5k=; b=2RdCPOb+YiGbYtmhTbS4wssAjoP1OV5+k6B7mOoAuCXlqtl9pl3kw9EYQAvGYpRPSuDbgS wSPz5pRHR+067xZOHWp3b5MRoSgYVDmgIivZLG/mZf3FinjFRxv+70vAxf4LUkDdNHyRLa sthUodl3SvHYvv77jPZNKj9f07hlPkC9m7fmCbWFR2oEDh5dFiLjmJFiGTD75swKEQxTH9 yBswaUq5lJ2omKrVUlZVn4Agd189b0gy4g8xR6EZjgCAb1kDvNGvShHzE5xhoP293DMO+X Da1QLG07i3IHLpguL3gAcIJgVZCB9nXcaqINbjYPkP6iiAakVFHfPMpPjaRA1g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=fXRRloVC; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=OZmxJEBy; 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=quarantine) header.from=johnnyrichard.com ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1726944449; a=rsa-sha256; cv=none; b=zi+4MQanuN0jO8MiEwWZkW57IjOxLJjdP60XcePXvEKH/w+n3P5MG8PNU8qESKdNdrM2F/ E10OC3eUmdI0H3JK7KtmQBncX3ehPp6/luhPHNe0vpn62js+gwxe5UhUruI/vaZZJh2fbH zpICUCrPi1rW2pzYfW3XhiWMe9bqllw3QJgIN6gAbM43anESwfEra12mjGiyOJUUYyMEEj hfZ/ZTzzVE3sypS4fDxucsvjjSdQL4pp5RMdtQ2SMBhYUWFKFNDhZwZnft/JDbmYxyi7ho LelOCf4VY0ZwyN1ynklWn0yYuyCtCFxS8j8hgQNMQe6pgBuD7YRdP9DhWCvCzQ== 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 2535D5CC8 for ; Sat, 21 Sep 2024 20:47:29 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=VvcTaSzqLjfQvCyu9Wufwjwy3ir0KybmxZeRWVHTe/g=; c=simple/simple; d=lists.sr.ht; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1726944448; v=1; b=fXRRloVC/H9breRO69uWSqZh3rwIOusuMsb2Z7KnkKufWR27l28t9XQ1W+1/z8NetQ/zRYmU UTed368bMBKpDpR9AQlQVhOI91/J+ZgmYstxyC1tV8yl+ZWzaXeWDevKtZOl0lZRTMbBNYr1gmO QLa0xPJPUAagt+cod8pSlfxsF+TzbsTP9gXAKCc1xFGWn60aqRBBq3VJnA40IOuqrv6tOldaJBI CrnhCFfKQoIJTYdqnfp5Plkj1AFbmasbG8X+zEm53/t2VkA3JK6mn37C/OiwSqgJAD+U+9r06zb g9EISN6jvq+72aA1OD2Ojt9PIDapI9pCFRXm/xLMCgi9A== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id E3FB52032E for ; Sat, 21 Sep 2024 18:47:28 +0000 (UTC) Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by mail-a.sr.ht (Postfix) with ESMTPS id 518E920320 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 21 Sep 2024 18:47:28 +0000 (UTC) Date: Sat, 21 Sep 2024 20:47:45 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1726944447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eQoGyBuhrP7ZCkqpz5o04TdfvJznZddT+RSGg2umF5k=; b=OZmxJEByzqXEXgayS27V9r0JKYzQ5tt1OmAQ4DtgKxKzJiiM0vGEn4DvnDi2PHYmphsTha L47xtiQ2DTPpEVHZ/oC6DMaZys6nkyaNcbtxZSjoAEXBQ+WjoHHt3vcLed+9ce9to3GCJY Vutgu1rR8FrGx710Xg6KA+SED4UDsstRQvMWHUEcAPiPgUnoW8cjUn8pcPadUzVrdMD1kU tqxaMVI/uegDeYBfiA4avhxipNfPJK1E7KoyuqC520vLerYqULoh6LTvNlJ4c/0X2R5MeL v6WMlWE7gBF1VxaP5XMnzi/jJZkcV05gZFDpCSjM2LnS1/E+rWaVXeXzWGRWoA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Johnny Richard To: Carlos Maniero Cc: ~johnnyrichard/olang-devel@lists.sr.ht Subject: Re: [PATCH olang 2/5] checker: scope: populate symbol's type Message-ID: References: <20240921082437.396691-1-carlos@maniero.me> <20240921082437.396691-3-carlos@maniero.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240921082437.396691-3-carlos@maniero.me> 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: -1.16 X-Spam-Score: -1.16 X-Migadu-Queue-Id: 2535D5CC8 X-Migadu-Scanner: mx10.migadu.com X-TUID: tlxgDnAzzQnK On Sat, Sep 21, 2024 at 08:24:56AM GMT, Carlos Maniero wrote: > Persisting the symbol type will be very convenient for codegen once this > information can be used to determine how many bytes that symbol > requires. I also agree. I would change a little bit here and make the checker calculate the size in bytes and add it to the symbol. > diff --git a/src/checker.c b/src/checker.c > index 3b713f7..f5068e0 100644 > --- a/src/checker.c > +++ b/src/checker.c > @@ -23,6 +23,9 @@ > static void > populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast); > > +static void > +populate_types(checker_t *checker, ast_node_t *ast); > + > checker_t * > checker_new(arena_t *arena) > { > @@ -44,6 +47,7 @@ checker_check(checker_t *checker, ast_node_t *ast) > assert(ast); > > scope_t *scope = scope_new(checker->arena); > + populate_types(checker, ast); > populate_scope(checker, scope, ast); We are traversing the tree twice to populate_scope. I think the populate scope can set the type on scope at this moment. > > // TODO: traverse the ast tree to verify semantics > @@ -107,7 +111,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); > + type_t type = ast->as_var_def.type; > + symbol_t *symbol = symbol_new(checker->arena, id, type); Let's include the size in bytes for the symbol. I believe this will enhance our symbol and make it easier to verify in the next steps > > scope_insert(scope, symbol); > ast->as_var_def.scope = scope; > @@ -124,3 +129,79 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast) > return; > } > } > + > +static void > +evaluate_type(type_t *type) > +{ > + if (string_view_eq_to_cstr(type->id, "u32")) { > + type->kind = TYPE_PRIMITIVE; > + type->as_primitive = TYPE_U32; > + return; > + } > + > + type->kind = TYPE_USER_DEFINED; > +} > + > +static void > +populate_types(checker_t *checker, ast_node_t *ast) > +{ If we set extra data to symbol's type we don't need to traverse the ast again here. Could you please enlighten the motivation behind setting extra data to types on AST nodes? > diff --git a/src/type.h b/src/type.h > new file mode 100644 > index 0000000..855cd83 > --- /dev/null > +++ b/src/type.h > @@ -0,0 +1,39 @@ > +/* > + * 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 > +typedef enum > +{ > + TYPE_PRIMITIVE, > + TYPE_USER_DEFINED > +} type_kind_t; I don't see other kinds in the future. What do you think about adding a boolean property named "is_primitive"?