public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: "Carlos Maniero" <carlos@maniero.me>
To: <~johnnyrichard/olang-devel@lists.sr.ht>
Subject: [RFC SPEC] Primitive data types and arrays
Date: Mon, 08 Apr 2024 00:29:11 -0300	[thread overview]
Message-ID: <D0EF88PEF0OL.2XEJ3V58Q6X3Q@maniero.me> (raw)

This thread tries to specify a basic datatypes of olang.

Primitive data types:
=====================

Primitive types are types that can be held on a general purpose register.

s8   : 8-bit  signed   integer type.
s16  : 16-bit signed   integer type.
s32  : 32-bit signed   integer type.
s64  : 64-bit signed   integer type.
u8   : 8-bit  unsigned integer type.
u16  : 16-bit unsigned integer type.
u32  : 32-bit unsigned integer type.
u64  : 64-bit unsigned integer type.
f32  : 32-bit floating point   type.
f64  : 64-bit floating point   type.

Translation to C:
-----------------

s8   : int8_t
s16  : int16_t
s32  : int32_t
s64  : int64_t
u8   : uint8_t
u16  : uint16_t
u32  : uint32_t
u64  : uint64_t
f32  : int32_t
f64  : int64_t

C also permits the use of type qualifiers, such as signed int or short int.
However, this specification recommends omitting the qualifier for simplicity.
In my opinion, this approach is more intuitive. While the meaning of long int
can be ambiguous, there’s no ambiguity with int32_t.

Example:
--------

const x: u32 = 1

Grammar:
--------

<primitive-type> ::= 's8'| 's16'| 's32'| 's64'| 'u8'|
                     'u16'| 'u32'| 'u64'| 'f32'| 'f64'


Arrays:
=======

An array is a fixed-size collection of similar data items stored in contiguous
memory locations. It can be used to store the collection of primitive data
types such as int, char, float, etc., and also derived and user-defined data
types, structures, etc.

Example:
--------

const x: u32[] = [1]
const y: u32[2] = [1, 2]

Grammar:
--------

<array-type> ::= <type> <ows> '[' <ows> <number>* <ows> ']'
<array-assign> ::= '['
                     <ows>
                     (<expression>
                       (<ows> ',' <ows> <expression>)*
                     )?
                     <ows>
                   ']'

Open question:
--------------

I have no idea how to initialize an array with a value. In C I know that this
is allowed:

int arr[20] = {0};

But I think this is ambiguous since if I remove the number 20 from the
statement above it will give me an one-sized array.

Translation to C:
-----------------

A olang array is just like a C array, no need to translation. Although it
differs from C by using square brakets other then curly brakets. That way we
could easily differ arrays from structs.

             reply	other threads:[~2024-04-08  3:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08  3:29 Carlos Maniero [this message]
2024-04-12  7:32 ` Johnny Richard
2024-04-13  2:51   ` Carlos Maniero
2024-04-13 23:31     ` Johnny Richard
2024-04-16  3:40       ` Carlos Maniero
2024-04-16 18:34         ` Johnny Richard
2024-04-17  1:30           ` ricardo_kagawa
2024-04-18 21:53             ` Carlos Maniero
2024-04-24 16:23               ` ricardo_kagawa
2024-04-20 11:45             ` Johnny Richard
2024-04-24 18:45               ` ricardo_kagawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D0EF88PEF0OL.2XEJ3V58Q6X3Q@maniero.me \
    --to=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox