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 CHSOGEqDBGblVwAAe85BDQ:P1 (envelope-from ) for ; Wed, 27 Mar 2024 21:36:26 +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 CHSOGEqDBGblVwAAe85BDQ (envelope-from ) for ; Wed, 27 Mar 2024 21:36:26 +0100 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Ht6aIPun; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=opr8fBkJ; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1711571786; a=rsa-sha256; cv=none; b=KgckPMVqersBoE9p7A6zH9PRvh1HNXh/8Its3MkfL8Hzd3AEGnOv2dRaB4t9nRrjU5Erpc lmKTTNQTLycMakIGfszp7RjxphwPvfmLIzSHdalWqfUEQA9upjnhaslT1T7O7srZDvVWnw 9D3Bpyqpc9U445VGuWipSV1lzIH6QVKox9+xikNeen1+jdgF2nPqEE0SLFG5OmotVlgqeN K6Jf6oIHL73Y08Z5Qa1vUn1aZi/Z3az+or1CpCbZD27oWl4pSut0df+V1OwkMz96I7xtB1 jsTajk3lktJ4J5OWb3bsUUiQBFNZzlaj7FaFfWfq6UsaeB9QjNqLv+qXylPSxg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Ht6aIPun; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=opr8fBkJ; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1711571786; 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=iOVPUWCK7IpIHn0GjdHtvXJTV6xcbIIe9Mp2TDnIDYI=; b=BHOq8LNdOaNdxncathvffhoS5FPR9ATcWpgP2soqSKo7w0SIce4viQL6BcVov37MovpS3i wAPmLPxHq8dtCeyL3Ou3gs8rdq30DJy/ZxjPBmSmi4XwxTaTeyTZlvpTwjPnpWsxJEgVSB K0rSKdBvhuMLc7JF78Z52kgKAbvj3guMY5xxKye/wDiVd8/0qA35yF3P12gNYLfykdA0H4 vEQzEzMoFzlfIKvNQvhCyG8GTPlsXHIfp8G8DKKCbyzhAwzO4LURIMnc4oYrOE5H8dfeJo yyHXQJqe3s4gjUqsd8Q/eI1PhzPTOgpwPxgyebl5PjYQSsE0EyKGkw/Gh4F7/w== 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 EA0E834876 for ; Wed, 27 Mar 2024 21:36:25 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=mzyiTVNL9MP/Y5FGF4al/BxDr0pT5MXYXPqF8yQyShQ=; 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=1711571785; v=1; b=Ht6aIPun/HrqGHpuQXNdP8N1aIxoxIRlEMygsEe/Ai4+xWxvURw23pIv1irNao9dSQUnFlnc UAnFtvsIRh6FnF45pmCe4iaEvhOGinhvZHd0Cu2w4VmpjoYNyffBVavy++KDMKKany9n+E+M/3f epJwFKEOpG9pZ6vcbbXX/IqNGu21A9doO3mXWzeqb2U/ifG2Hfhn7Nf/O0Cz0VjBLtFLNRMOf4t VWN3XSIcPAFFRRa4I6KsPMuhYLQSN6mM2xNeSgECyB9BSu2eVWuerLD86zwYYdaJLK7O1LFKKZF NDJkqFaKcgldAfSOWFzj/n6Il/va8yIM3V5X9I0RHwC8g== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id C9D0920276 for ; Wed, 27 Mar 2024 20:36:25 +0000 (UTC) Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) by mail-a.sr.ht (Postfix) with ESMTPS id 3B07220236 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 27 Mar 2024 20:36:25 +0000 (UTC) Date: Wed, 27 Mar 2024 22:37:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1711571784; 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=iOVPUWCK7IpIHn0GjdHtvXJTV6xcbIIe9Mp2TDnIDYI=; b=opr8fBkJGf8l5bBUtpOFx32XA9H5dXDqcMHYlPKCfWQ1pPWVSQPE22b86fjJ0RQwNt49z9 mUSVJMzMaRziJFx7EjOiA62S/+2omU+31wrcQOMNzjTYQmGIjMhbltQSWL1TfNe3sgUWFO s6QT+AZsIwiVj++WFAmK1LQqMmJuibAw8vPojHBvkBZjLxgQ80DJLuAfAsZkkfgNB3ypks +NGx2HPVcaicoWa5TGmLho2m8AlUAV+s8Rz0y9Y+hW2PM6nSDo/H2ZxweXtYA9OqzwvBuU AQ2VAhVtxzTfWQTvSi+WQlQ5WA1qYbfy4oNB+tAngtZL32jn7kLxGiszEVJa+w== 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 v1 2/2] docs: spec: add variables and constants specification Message-ID: References: <20240327032128.406911-1-carlos@maniero.me> <20240327032128.406911-3-carlos@maniero.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240327032128.406911-3-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-Spam-Score: -10.10 X-Migadu-Queue-Id: EA0E834876 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -10.10 X-TUID: +vr7pb7G9KnF On Wed, Mar 27, 2024 at 12:21:28AM -0300, Carlos Maniero wrote: > This commit introduces the specification for variables and constants. A > valid program under this specification is as follows: > > var x: u32 = 1 Since this patch adds support to assignments, lets also add support to all assignment operators like "-=" "+=" "<<=" and so on. > const y: u32 = 2 This patch lacks support to the following valid assignment expression (which I think adds flexibility to the language): var x: u32 = a = b = c = 1 var y: u32 y = a = b = c = 1 > 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 *) > ::= ( )* > > - ::= > + ::= | | | nitpick: maybe _external-declaration_ sounds better since definitions are not statements? > + > +(* Variables *) > + ::= 'var' ':' ? > + ::= 'const' ':' We don't need to define twice the variable-definition for "var" and "const", let's combine both in a single rule. > + ::= > + ::= '=' > + ::= > > (* Functions *) > ::= 'fn' > @@ -38,11 +46,11 @@ language. > ::= '{' ( > )* ? '}' > ::= ';' | | > - ::= > + ::= | | | > ::= 'return' > > (* Expressions *) > - ::= > + ::= | > > (* Identifiers *) > ::= 'u32' > -- > 2.34.1 > I have done few adjustments according to my feedback (I also fix the unnecessary line breaks on function and block). Let me know what you think about it. ---->8---- Subject: [PATCH olang] fixup! docs: spec: add variables and constants specification diff --git a/docs/pages/language-specification.md b/docs/pages/language-specification.md index 708b679..2650dd9 100644 --- a/docs/pages/language-specification.md +++ b/docs/pages/language-specification.md @@ -22,35 +22,45 @@ language. ``` (* Entry Point *) - ::= ( )* + ::= ( ( | ))* - ::= | | | + ::= + | + | (* Variables *) - ::= 'var' ':' ? - ::= 'const' ':' - - ::= - ::= '=' - ::= + ::= ':' ( )? + ::= 'var' + | 'const' + ::= (* Functions *) - ::= 'fn' - ':' + ::= 'fn' ':' ::= ::= '(' ')' ::= ::= (* Statements *) - ::= '{' ( - )* ? '}' - ::= ';' | | - ::= | | | + ::= '{' ( )* ? '}' + ::= ';' | + ::= | | ::= 'return' (* Expressions *) - ::= | + ::= | | + ::= + ::= '=' + | '*=' + | '/=' + | '%=' + | '+=' + | '-=' + | '<<=' + | '>>=' + | '&=' + | '^=' + | '|=' (* Identifiers *) ::= 'u32'