public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [RFC SPEC] Primitive data types and arrays
@ 2024-04-08  3:29 Carlos Maniero
  2024-04-12  7:32 ` Johnny Richard
  0 siblings, 1 reply; 11+ messages in thread
From: Carlos Maniero @ 2024-04-08  3:29 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-24 18:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08  3:29 [RFC SPEC] Primitive data types and arrays Carlos Maniero
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

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