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 6IyQO9WQA2Y/QQEAe85BDQ:P1 (envelope-from ) for ; Wed, 27 Mar 2024 04:21:58 +0100 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 6IyQO9WQA2Y/QQEAe85BDQ (envelope-from ) for ; Wed, 27 Mar 2024 04:21:58 +0100 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=iiGq4iRM; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=tPFbaeed; 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-Seal: i=2; s=key1; d=johnnyrichard.com; t=1711509717; a=rsa-sha256; cv=pass; b=HwuIxEGy+YyC3WHe35XE/EmDppDICv6vj2LmVCnzITtHf0bdxwPOor0fBJV/kKKWzx2h3k mIyZIE98TXIeb62y7wQU+B1MpNhe2AHaXHwlcZ3uEoFnUsYPzFJDySGbgpCXDfogjjVJt7 teo/jGsUZcIxlPp/X2VMX4/KNZcHfZaTdj65+M1kEaIDOdazilVJVXZFywjCKEdpFRF/Hi ymKbstsatCmKsuiD1whcu4uAH3py3pRgc67Xy3RSpS21XP/iqezkvYbXE+l5me9WJsuj/M RJr1hbkbJR+S2LZrGvTMDZzgBL4I9l9K4RUHJEpc/Nixdms6PsI4vMGpd8BUmA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=iiGq4iRM; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=tPFbaeed; 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=1711509717; 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=aeMhEjpHcFwgdQzjMc1uBMvSYr2I/1wnesWdpl6Fk+k=; b=te9h86tGZ2oCB2YKm/E6yW59nwWQxRNqBY2C2y9/rOLOzCQpmfk1VdjVCzZe5W+OncEfiF 7emFzU01twZF8xgPDf8lv7n8CHm8WYGF9Qsv4DizEgWE4hFMv6NFHtPT0ewnyXGDtPJxht EvCx3StFYnsdTXwUN/sELpuVh3evqtxcGrNg1MX0osAmWM5vN4n9uX7Y60wA6cFTKZSlih 4ogC7Ah8sZNbbHa8bIHY8pvckaanU6iWAQ8mb7f0N76OwyHw7Ra/GY28F4VMGGgJgWdPwO n9rUJ6cfsPCEM5v3TolR+Q7UAUEBqG4I+VhMA7CmxmJn87m4OXADPZFAhbHzBA== 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 C8DC532C49 for ; Wed, 27 Mar 2024 04:21:54 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=LyX9opDDkzkjtt9Vpg0rIwI1nzaQE0GaHPscm0D+TPM=; 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=1711509714; v=1; b=iiGq4iRMqscg7PN8Xvo4UdHcwMmx5AfTZb6XUmyCY21A40bU4iypbpaJdYCtWauz5cGChWAA nRUtGxOJ3SMCQhiuMKwlQsri/E3lDLdATaY0dlwZkPbOj8QA5NSlDYDo9Btz5I6hESfq+3T159q bNZnGBzCtbAuyTKdKhcKB8lhlvYhzm+0b/1+QUGnn8JPTAZWWWbcMHU8Szu+dYl0oWSTXb+KWab QjTOjBFHpc4huXU94Wuli5zc/q8wBku/EoIfh3Zyql+ILKtxy6eUTlfvWgzfF7H4P1ZAvyp6xQ8 8UO0WxExWnLMy985BB6unu3Xll1Rheiz4r0EAdovK5A6g== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 82F48201BF for ; Wed, 27 Mar 2024 03:21:54 +0000 (UTC) Received: from slateblue.cherry.relay.mailchannels.net (slateblue.cherry.relay.mailchannels.net [23.83.223.168]) by mail-a.sr.ht (Postfix) with ESMTPS id 84D8E2018A for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 27 Mar 2024 03:21:53 +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 8FCAB830DB for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 27 Mar 2024 03:21:51 +0000 (UTC) Received: from uk-fast-smtpout5.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id E34CE82B20 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 27 Mar 2024 03:21:50 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1711509711; a=rsa-sha256; cv=none; b=liOsnMv+gL6Gt4FCrql1Sz0Ed3n3Z3cm/ntVyjkhxw6e2+44v15KTuojlir7+ahkyvim36 78YzS4L/gl6zKAR4rAwkshX/aneV7imcDLr4Uqj1BuS2hIgpN0SpekN+whm0oSeUS02pZi bDgiY5ktvlDsaE+nDt/b1/Eam1n/BLc0XZ63cn2tQlG9NWr/fO5JyCDGNFLDormhZnp33C WNLi4AsaV8gVJbDrrtO38suaZWWu3ADyHAQh8/bFVQ389LMEjYcIAMxZV2KL+wfAd8kEBy +3bjIL8InfGTgXcDRBE0+F2hu/GvvneArhNSjXtIQH6PMQn6glCzor6q3NCMcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1711509711; 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=aeMhEjpHcFwgdQzjMc1uBMvSYr2I/1wnesWdpl6Fk+k=; b=BSpP1SVSvsJfh3JSFV4XninlHp4N8Z6rYuPyqFpLam53vVP2Nuaadew0Og9mEz8FZFhvmB JQKl67bWaxLn/kgASFqK7KJnvXeEm5FJ+7zNkdoEPAbp/1DjMafYeIG5gZM5ndjRDQN9lo 0lrCVpT2p0mS2gP8/u7UlmuI6gUofqzoFqGm37Gu4vFOQARRl0oXjymBBXEczGZKYurjWP 6iCa0Bv5qo+nrYgkY4C1G/cAg5V9rk9rw8ZxBaNbwWSSgzpL2ozC8I0zd0pSffT7F/NtN0 ULrVDluyMLAByEnVI5SGEkU1NjPr0JwBgl8O2ufd8Kjy1ST/O3S119FVAqIH8Q== ARC-Authentication-Results: i=1; rspamd-7f6944c677-6xfph; 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-Befitting-Drop: 4834f1f309240f1e_1711509711451_3753236058 X-MC-Loop-Signature: 1711509711451:1154494539 X-MC-Ingress-Time: 1711509711451 Received: from uk-fast-smtpout5.hostinger.io ([UNAVAILABLE]. [31.220.23.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.99.130.136 (trex/6.9.2); Wed, 27 Mar 2024 03:21:51 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1711509709; 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=aeMhEjpHcFwgdQzjMc1uBMvSYr2I/1wnesWdpl6Fk+k=; b=tPFbaeedhrrLY1Iwloez4rDM8s3ZqQtNnbeojWKxYXzmeocMpwRnC85bMDV9VhJj+QSuyE t2aHsmthfYStlrruDYAiPdlXLdrtc3+yg7/lDyjK1sMB0mcqbo0+Oj9+CIYXoJ/1LKCSuo nUzkB60pfGRGsIf1TmsBorR+AXjl99xQ9bIkOZb15ThEjTR2oyhwN8dA2U0KIo7MsJ6eMN r3k64w+oImzKTjfuUlFCrDYopitmAfNCBn8O3270b0vWwk4or5DzwJaSbceU+h7aHRDLtB VXYAXjQT/Zlz7V0qReOB0x5ibHXvTe/SRQBLb7CiUFZdpaNfHrlYFhiKEwr2kg== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 2/2] docs: spec: add variables and constants specification Date: Wed, 27 Mar 2024 00:21:28 -0300 Message-Id: <20240327032128.406911-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327032128.406911-1-carlos@maniero.me> References: <20240327032128.406911-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-Envelope: MS4xfKisRFlz0vjtbKhcWaZ84ogzsY2f1G82yqmw8PxSuDYgNdWoyhnXhrwiOU9DeFz0nwBHkHIzJFsPpb0mMk9GXwq2EexEuGe7lEKFhF0Z8V23/zjnlQIg 84FT9374xqoPk6aQsQ6mK0Lih0t6s6HgskfLieKeMQiwDeEdUsHMyY+gwyCtklTpRtD2jfSnK6swVpk/eSQ7/ll/OFWYtmFB+yFcpvxOp7930J2EvIN67REq X-CM-Analysis: v=2.4 cv=B6m/0vtM c=1 sm=1 tr=0 ts=660390cd a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=Jrym6FK-yHBCAelw_wwA:9 a=BXDaF_L80NY05PYiAFlV:22 X-AuthUser: carlos@maniero.me 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-Spam-Score: -10.10 X-Migadu-Queue-Id: C8DC532C49 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -10.10 X-TUID: byEKFnT2fmct This commit introduces the specification for variables and constants. A valid program under this specification is as follows: var x: u32 = 1 const y: u32 = 2 x = 2 fn main(): u32 { var x: u32 = 1; const y: u32 = 2 return x } Variables and Linkage: ---------------------- Variables can be defined globally or within a function. Variables defined globally are added to the *.data* section. On the other hand, variables defined within a function utilize the stack. Currently, the specification does not provide a keyword for external linkage yet, hence variables cannot be accessed outside their translation unit. Constants and Linkage: ---------------------- Constants behave similarly to variables. Constants defined at the file level are added to the *.rodata* section. Constants within functions are subject to semantic checks. Attempting to bypass these checks to reassign a global constant will result in a segmentation fault (SEGFAULT) and will be accepted at the function level. Example of bypassing semantic checks in C: int a = 1; const int b = 2; int *c = &a + 1; *c = 3; assert(b == 3); // its true Static variables in function level ---------------------------------- In C, static variables can be defined within the scope of a function. These variables are added to the `*.data*` segment and are only accessible within the function where they are defined. This is a unique behavior of C that some might find unusual. However, olang does not support this feature. In olang, if you need a variable that retains its value across function calls (like a static variable in C), you must define it at the file level. Signed-off-by: Carlos Maniero --- docs/pages/language-specification.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md index 4541ba8..708b679 100644 --- a/docs/pages/language-specification.md +++ b/docs/pages/language-specification.md @@ -24,7 +24,15 @@ language. (* Entry Point *) ::= ( )* - ::= + ::= | | | + +(* Variables *) + ::= 'var' ':' ? + ::= 'const' ':' + + ::= + ::= '=' + ::= (* Functions *) ::= 'fn' @@ -38,11 +46,11 @@ language. ::= '{' ( )* ? '}' ::= ';' | | - ::= + ::= | | | ::= 'return' (* Expressions *) - ::= + ::= | (* Identifiers *) ::= 'u32' -- 2.34.1