Spec tweaks
This commit is contained in:
parent
cad6c06607
commit
8661ab6ace
1 changed files with 45 additions and 39 deletions
58
spec.txt
58
spec.txt
|
|
@ -19,16 +19,20 @@ Built-in types:
|
|||
N.B.: there is no dedicated 'char' type, strings operate on u8 (utf-8) or u32 (utf-32)
|
||||
|
||||
Pointer types:
|
||||
*T (pointer to const T)
|
||||
*mut T (pointer to mutable T)
|
||||
**T (pointer to const pointer to const T)
|
||||
*mut *T (pointer to mutable pointer to const T)
|
||||
**mut T (pointer to const pointer to mutable T)
|
||||
*mut *mut T (pointer to mutable pointer to mutable T)
|
||||
T* (pointer to const T)
|
||||
T mut* (pointer to mutable T)
|
||||
T** (pointer to const pointer to const T)
|
||||
T* mut* (pointer to mutable pointer to const T)
|
||||
T mut** (pointer to const pointer to mutable T)
|
||||
T mut* mut* (pointer to mutable pointer to mutable T)
|
||||
|
||||
Array types:
|
||||
T[N] array of N elements of type T (N must be a compile-time value)
|
||||
|
||||
Function types:
|
||||
(arg1, arg2, arg3) -> result
|
||||
(arg1, arg2) -> unit // no return value
|
||||
|
||||
======== LITERALS ========
|
||||
|
||||
Literals:
|
||||
|
|
@ -63,10 +67,10 @@ Variable declaration:
|
|||
|
||||
Array declaration:
|
||||
let arr: i32[4] = [12, 15, 65, 42]
|
||||
let arr: i32[] = [56, 23] // size inferred as 2
|
||||
let arr: i32[] = [56, 23] // size inferred as 2 - maybe forbid this?
|
||||
let arr = [2, 5, 6] // size and type inferred as i32[3]
|
||||
|
||||
Variables must always be initialized. (TODO: really? What about arrays?)
|
||||
Variables must always be initialized. (TODO: really? What about arrays? Maybe need special syntax for zero-initialization or mass-initialization)
|
||||
Const variables must be initialized with a const expression (any expression that doesn't include non-const values).
|
||||
|
||||
======== OPERATORS ========
|
||||
|
|
@ -118,13 +122,28 @@ 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?).
|
||||
|
||||
Address:
|
||||
&x // returns *T
|
||||
&x // returns *T, fails if x is a const variable
|
||||
&mut x // returns *mut T, fails if x is non-mut variable
|
||||
|
||||
Assignment:
|
||||
x = 15 // requires x to be a mut variable
|
||||
*p = 15 // p must be a pointer to mut
|
||||
|
||||
======== FLOW CONTROL ========
|
||||
|
||||
Flow control:
|
||||
if condition:
|
||||
statements
|
||||
else if condition:
|
||||
statements
|
||||
else:
|
||||
statements
|
||||
|
||||
while condition:
|
||||
statements
|
||||
|
||||
TODO: for loops? iterator/range interface?
|
||||
|
||||
======== STRUCTS ========
|
||||
|
||||
Struct types:
|
||||
|
|
@ -142,9 +161,7 @@ Struct field access:
|
|||
let p = &r
|
||||
let y = p.height // field access through pointer is the same
|
||||
|
||||
Function types:
|
||||
(T1, T2, T3) -> i32
|
||||
(T1, T2) -> unit // no return value
|
||||
======== FUNCTIONS ========
|
||||
|
||||
Function definition:
|
||||
func foo(x: i32, y: i32) -> i32:
|
||||
|
|
@ -153,18 +170,7 @@ Function definition:
|
|||
func bar(x: f32): // deduced return type unit
|
||||
print(x)
|
||||
|
||||
Flow control:
|
||||
if condition:
|
||||
statements
|
||||
else if condition:
|
||||
statements
|
||||
else:
|
||||
statements
|
||||
|
||||
while condition:
|
||||
statements
|
||||
|
||||
TODO: for loops? iterator/range interface?
|
||||
TODO: function overloading? Probably requires selecting a specific overload using `as` operator to save to a value (but not on call site)
|
||||
|
||||
======== TYPE OF TYPES ========
|
||||
|
||||
|
|
@ -182,14 +188,14 @@ E.g.
|
|||
======== CONST EXPRESSIONS ========
|
||||
|
||||
// TODO
|
||||
// Auto-upgrading values to compile-time when a function is executed from const-only values?
|
||||
// Auto-upgrading values to compile-time when a pure function is executed from const-only values?
|
||||
|
||||
======== METAPROGRAMMING ========
|
||||
|
||||
// TODO
|
||||
// Functions returning functions/structs
|
||||
// Syntactic sugar for common cases
|
||||
// Figure out: max(a,b) - how to deduce type parameters?
|
||||
// Figure out: max(a,b) - how to deduce type parameters? How does it play with overloading?
|
||||
// func max(t: type):
|
||||
// return func(x : t, y : t):
|
||||
// if x > y:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue