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 yASVIB9VEGdhfgAAe85BDQ:P1 (envelope-from ) for ; Thu, 17 Oct 2024 02:06:55 +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 yASVIB9VEGdhfgAAe85BDQ (envelope-from ) for ; Thu, 17 Oct 2024 02:06:55 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none 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 6E0DC61AF1 for ; Thu, 17 Oct 2024 02:06:55 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=8UkwT8jBYkLKOBz6emkp/DcQz/gd6J/fODh4d3ihkZ4=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1729123615; v=1; b=jEXBh6vSj1C0kpHm4aCzyT9dupdR1GtItfAbITY1kq7TQ5haM8n4Atj0s120Gxfn/BfpRTrn EQ4rpHoGW7Il1sSeoxAmQNlz/VT+UI1SvVB//4fy4b2NlrE3elScHT+6tuHYYznnbuYei1rsYER T2LiGaFR1vXHAzDrOD2OGRVTDDTZMajkGbEBxwWDIR7oA3bQas9Qbkq+vaGMzYV/IOkqp1hiArG BxT077yb1lpCQa31UJwLo4Efp2zuurn+O7/iRXoeShNop2tR/e1iJafoIstgg4A5SRav/eCxm49 yLO6s/eh1ffk2t8Nu/r7CcBI2zVl5h7o1lECNXiB1aVgQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 1E1AD202B6 for ; Thu, 17 Oct 2024 00:06:55 +0000 (UTC) Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by mail-a.sr.ht (Postfix) with ESMTPS id 7326620279 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 17 Oct 2024 00:06:49 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1729123609; 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=R6cQzwofo0RELq429TvNAwjg4XFjbYTsQlO7yRadVYg=; b=IKzchbTwdg0FYzT5RCA7G9/1xAKs902K5jp7xvlpuE+vCZcW86m3p9isH/vKWXgZ+Ly2vb 87oulsZbmAjFQmAREAbuvgJF4MAC9mXwmg1t/dhnqsy34GQTGqY2OStdLAIpctepOYcP/T pBRv4Rhid7HB1BGx1iWaynaQGbec2q9vapoJMnOsJC85y5fnM4BVzdmxPphK1P3uv0yuot FPTPPRJlmszsIZEgla28fR6OG6zwX2kNbRWTkm8nPHt2PRSEpWneaYccR0ly0gQDlJbl9c 4IZEqGZyd75BI/qvJDm13eZyZ8sy0NJqF9pP1V5CiYsFMjhdcBpPlWqxf5un3Q== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/3] lexer: spec: add extern keyword for function def Date: Thu, 17 Oct 2024 04:04:42 +0200 Message-ID: <20241017020603.551431-2-johnny@johnnyrichard.com> In-Reply-To: <20241017020603.551431-1-johnny@johnnyrichard.com> References: <20241017020603.551431-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: PROPOSED 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.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 6E0DC61AF1 X-Migadu-Scanner: mx12.migadu.com X-TUID: BbGvSwMvn3a+ Signed-off-by: Johnny Richard --- docs/info/olang.ebnf | 2 +- src/lexer.c | 5 ++++ src/lexer.h | 1 + tests/olc/0037_variable_overflow.ol | 39 +++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/olc/0037_variable_overflow.ol diff --git a/docs/info/olang.ebnf b/docs/info/olang.ebnf index 0bc7eb5..5bd2be6 100644 --- a/docs/info/olang.ebnf +++ b/docs/info/olang.ebnf @@ -11,7 +11,7 @@ ::= '=' (* Functions *) - ::= 'fn' '(' ( | ) ')' ':' + ::= ('extern' )? 'fn' '(' ( | ) ')' ':' ? ::= ::= ':' ( ',' )* ::= diff --git a/src/lexer.c b/src/lexer.c index 1a6c24b..ddfe42a 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -313,6 +313,7 @@ static char *token_kind_str_table[] = { [TOKEN_ELSE] = "else", [TOKEN_WHILE] = "while", [TOKEN_VAR] = "var", + [TOKEN_EXTERN] = "extern", [TOKEN_LF] = "line_feed", [TOKEN_OPAREN] = "(", [TOKEN_CPAREN] = ")", @@ -489,6 +490,10 @@ lexer_str_to_token_kind(string_view_t text) return TOKEN_VAR; } + if (string_view_eq_to_cstr(text, "extern")) { + return TOKEN_EXTERN; + } + if (string_view_eq_to_cstr(text, "return")) { return TOKEN_RETURN; } diff --git a/src/lexer.h b/src/lexer.h index 774f619..bba15fb 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -53,6 +53,7 @@ typedef enum token_kind TOKEN_ELSE, TOKEN_WHILE, TOKEN_VAR, + TOKEN_EXTERN, // Equality operators TOKEN_CMP_EQ, diff --git a/tests/olc/0037_variable_overflow.ol b/tests/olc/0037_variable_overflow.ol new file mode 100644 index 0000000..0e3c302 --- /dev/null +++ b/tests/olc/0037_variable_overflow.ol @@ -0,0 +1,39 @@ +# Copyright (C) 2024 olang mantainers +# +# 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 . + +extern fn putchar(c: u32): u32 + +fn main(): u32 { + return putchar(111) +} + +# XTEST test_compile(exit_code=0) +# +# XTEST test_run_binary(exit_code=0) +# +# XTEST test_ast WITH +# Translation_Unit +# |-Function_Definition +# | `-Param_Definition +# `-Function_Definition +# `-Block +# `-Return_Statement +# `-Function_Call +# `-Literal +# END +# +# TEST test_contains_tokens WITH +# ./0037_variable_overflow.ol:16:1: +# END -- 2.46.0