Update spec

This commit is contained in:
Nikita Lisitsa 2026-03-12 20:17:17 +03:00
parent c7e0232b15
commit 76f80f8135

View file

@ -11,8 +11,7 @@ Built-in types:
i16 i16
i32 i32
i64 i64
f8 (maybe? cpu-emulated at best) f16
f16 (maybe? cpu-emulated at best)
f32 f32
f64 f64
@ -32,6 +31,7 @@ Array types:
Function types: Function types:
(arg1, arg2, arg3) -> result (arg1, arg2, arg3) -> result
(arg1, arg2) -> unit // no return value (arg1, arg2) -> unit // no return value
arg -> result // simplified syntax for single-argument case
======== LITERALS ======== ======== LITERALS ========
@ -45,16 +45,15 @@ Literals:
123l -> i64 123l -> i64
123ul -> u64 123ul -> u64
3.14h -> f16 3.14h -> f16
3.14f -> f32 3.14 -> f32
3.14 -> f64 3.14l -> f64
'a' -> u8 'a' -> u8 (ascii only?)
'猫'u -> u32 '猫'u -> u32
TODO: string literals? fixed-size arrays? built-in spans? TODO: string literals? fixed-size arrays? built-in spans? Probably built-in spans (potentially defines in prelude.psl)
"hello, world" -> utf-8 string "hello, world" -> utf-8 string
"здарова, братки"u -> utf-32 string "здарова, братки"u -> utf-32 string
======== VARIABLES ======== ======== VARIABLES ========
Variable declaration: Variable declaration:
@ -67,10 +66,13 @@ Variable declaration:
Array declaration: Array declaration:
let arr: i32[4] = [12, 15, 65, 42] let arr: i32[4] = [12, 15, 65, 42]
let arr: i32[] = [56, 23] // size inferred as 2 - maybe forbid this?
let arr = [2, 5, 6] // size and type inferred as i32[3] let arr = [2, 5, 6] // size and type inferred as i32[3]
let arr: i32[0] = [] // need special empty array literal, type cannot be inferred
Variables must always be initialized. (TODO: really? What about arrays? Maybe need special syntax for zero-initialization or mass-initialization) Null pointer literal:
let p: u32* = null // special like empty array literal, type cannot be inferred
Variables must always be initialized. (TODO: really? What about arrays? Maybe need special syntax for zero-initialization or mass-initialization. Alternative: default to zero-initialization)
Const variables must be initialized with a const expression (any expression that doesn't include non-const values). Const variables must be initialized with a const expression (any expression that doesn't include non-const values).
======== OPERATORS ======== ======== OPERATORS ========
@ -79,13 +81,15 @@ Logical (only bool type):
!x !x
x & y x & y
x | y x | y
x && y // short-circuit
x || y // short-circuit
x ^ y x ^ y
Equality (all built-in types, only same type): Equality (all built-in types, all struct types, only same type):
x == y x == y
x != y x != y
Comparison (all built-in types, only same type): Comparison (all built-in types, all struct types, only same type):
x < y x < y
x > y x > y
x <= y x <= y
@ -95,6 +99,8 @@ Bitwise (integer types, only same type):
!x !x
x & y x & y
x | y x | y
x && y // short-circuit
x || y // short-circuit
x ^ y x ^ y
Bitwise shift (any pair of integer types): Bitwise shift (any pair of integer types):
@ -119,7 +125,7 @@ Casting:
x as u32 // always explicit, no implicit casts allowed x as u32 // always explicit, no implicit casts allowed
Any integer/floating-point types can be cast to each other. Any integer/floating-point types can be cast to each other.
Any pointer types can be cast to each other (TODO: alignment? UB or safe fallback?). Any pointer types can be cast to each other (TODO: alignment? UB or safe fallback? Probably UB.)
Address: Address:
&x // returns *T, fails if x is a const variable &x // returns *T, fails if x is a const variable