Skip to main content

Introduction

Overview

Swirl is a statically-typed, LLVM-based systems programming language.

Kickstart

The main function is the entry-point of a Swirl program.

fn main(): i32 {  // the return type can be omitted as the type inference system can infer it
return 0;
}

Variable Declarations

Variables can either be declared with let or var, the former doesn't allow reassignment and enforces in-place initialization, the latter does allow it.

let constant = 43;
let anothere_const: i8; // error: initialization required

var my_var = 39;
my_var = 49; // can be reassigned

Initialization Semantics: when a variable declaration is left uninitialized, it is automatically zero-initialized. If you do not want that to happen, initialize it with the undefined keyword.

var uninitialized: i16 = undefined;

Conditions

if a == b || c == d && e != f {
...
}

elif a == c {
...
}

else {
...
}

While Loop

while e != f {
if e == g {
break;
} else {
continue;
}
}

Operators

OperatorUsageAssociativityPrecedence (Descending order)
.Member accessLeftA
[]IndexingLeftB
&xAddress takingLeftC
+xUnary plusLeftC
-xUnary minusLeftC
*xDereferenceLeftC
!xLogical notLeftC
~xBitwise NOTLeftC
asCastLeftD
**ExponentiationRightE
*MultiplicationLeftF
/DivisionLeftF
%ModulusLeftF
+AdditionLeftG
-SubtractionLeftG
<<Bitwise left shiftLeftH
>>Bitwise right shiftLeftH
>Greater thanLeftI
>=Greater than or equalLeftI
<Less thanLeftI
<=Less than or equalLeftI
==EqualityLeftJ
!=InequalityLeftJ
&Bitwise ANDLeftK
^Bitwise XORLeftL
|Bitwise ORLeftM
&&Logical ANDLeftN
||Logical ORLeftO
=AssignmentRightP
+=Add assignmentRightP
-=Subtract assignmentRightP
*=Multiply assignmentRightP
/=Divide assignmentRightP
%=Modulus assignmentRightP
**=Exponentiation assignmentRightP
|=Bitwise OR assignmentRightP
&=Bitwise AND assignmentRightP
^=Bitwise XOR assignmentRightP
<<=Left shift assignmentRightP
>>=Right shift assignmentRightP

Stay informed