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 kGOVA9vaBmeaHAAAe85BDQ:P1 (envelope-from ) for ; Wed, 09 Oct 2024 21:34:51 +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 kGOVA9vaBmeaHAAAe85BDQ (envelope-from ) for ; Wed, 09 Oct 2024 21:34:51 +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 F14F41F18C for ; Wed, 09 Oct 2024 21:34:50 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=lBquDqiwLoVxcDdJdCwLXDSkYxOLw2f/1/J+UR6nvgo=; 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=1728502490; v=1; b=M6fB9CEdTiXtPejWYRrSNF0N3lBGTa2MMvARjghmdXZsANzZ48jBmwEPz0r7zZQMvtVKAzrg QF1K9SXsaOjlf3da870G/e+rXOOscjxbmlubPtCmUmHhTJEfr1CItXpnZGIFD0u0mX7Y6CIKX88 wGaWxsqqCAS8zT0yC7Y22wH53p9DtTOtDbeaOWdirCiDT6kx4/uvyKrJcSEjPJUdtMvvo19mqnh 5wLb6yPqSpi8i6mjOSM4m8TuiDj2ALEdceRjiksfXCFM6FLbS1gG6sNaMqtGyIsJF+XZ6A8npRV yzhfSgAflfpU6rLzbDFpBshpdtGLRtRlOYJ+d1hrcB7DQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id CF401201FF for ; Wed, 09 Oct 2024 19:34:50 +0000 (UTC) Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by mail-a.sr.ht (Postfix) with ESMTPS id CA1A520134 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 09 Oct 2024 19:34: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=1728502489; 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=eHCdtzmcoTjWUGuYIfzVW3hBb+xE/dgCALQhlWaN70o=; b=m9IQOqW8VZ5V+BaLf+NDQLnkXGdMzbgtqJPeGo3yKMjt21Iy3WaIu6YM5lPhC/+3WtDV8v NRUG0bGanDdZZ4AbwkMPWrjsEIptQ3FUkItC8hN5KG4fXQxXogGe8G3SPVEGUkEReFEK62 dzOhuyJDnn/bxhSunkF2jR7f1xWnQcvduKU5sfK0cmaSPfEHNYuOdZnB5Y9jwTwOqAXLtM gUUmQ9oMtNvhi6eqOH++AQhuJSjuC2KVSAbBiHw4didd1bJgMtE/dUMURDWQzbkGjT/Qau TFilO/bLe3MfCfBySsXWv+twOtIF9u7V0eegcy3JbVeWC2Uy95ZvzdWroCvMFw== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 2/3] lexer: add tilde token support Date: Wed, 9 Oct 2024 23:18:28 +0200 Message-ID: <20241009213425.412949-3-johnny@johnnyrichard.com> In-Reply-To: <20241009213425.412949-1-johnny@johnnyrichard.com> References: <20241009213425.412949-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: F14F41F18C X-Migadu-Scanner: mx12.migadu.com X-TUID: 5WOBwFpqh3To The tilde token will be used for parsing bitwise-not unary operator. Signed-off-by: Johnny Richard --- src/lexer.c | 6 +++++ src/lexer.h | 1 + tests/olc/0033_unary_operator_bitwise_not.ol | 27 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/olc/0033_unary_operator_bitwise_not.ol diff --git a/src/lexer.c b/src/lexer.c index 5b4bbaa..9e012bd 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -258,6 +258,11 @@ lexer_next_token(lexer_t *lexer, token_t *token) lexer_skip_char(lexer); return; } + case '~': { + lexer_init_char_value_token(lexer, token, TOKEN_TILDE); + lexer_skip_char(lexer); + return; + } case '/': { lexer_init_char_value_token(lexer, token, TOKEN_SLASH); lexer_skip_char(lexer); @@ -303,6 +308,7 @@ static char *token_kind_str_table[] = { [TOKEN_DASH] = "-", [TOKEN_STAR] = "*", [TOKEN_SLASH] = "/", + [TOKEN_TILDE] = "~", [TOKEN_EQ] = "=", [TOKEN_CMP_EQ] = "==", [TOKEN_BANG] = "!", diff --git a/src/lexer.h b/src/lexer.h index 8beaea8..774f619 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -81,6 +81,7 @@ typedef enum token_kind TOKEN_DASH, TOKEN_SLASH, TOKEN_STAR, + TOKEN_TILDE, TOKEN_LF, TOKEN_OPAREN, TOKEN_CPAREN, diff --git a/tests/olc/0033_unary_operator_bitwise_not.ol b/tests/olc/0033_unary_operator_bitwise_not.ol new file mode 100644 index 0000000..1891549 --- /dev/null +++ b/tests/olc/0033_unary_operator_bitwise_not.ol @@ -0,0 +1,27 @@ +# 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 . + +fn main(): u32 { + var e: u32 = 4294967295 + return ~e +} + +# XTEST test_compile(exit_code=0) +# +# XTEST test_run_binary(exit_code=0) +# +# TEST test_contains_tokens WITH +# ./0033_unary_operator_bitwise_not.ol:18:10: <~> +# END -- 2.46.0