// Variables immutables (par défaut)
let x: i32 = 42;
let name: str = "A.S.T.R.A.L";
// Variables mutables
mut counter: i32 = 0;
counter = counter + 1;
// Constantes
const PI: f64 = 3.14159265359;
fn add(a: i32, b: i32) -> i32 {
return a + b;
}
fn greet(name: str) -> void {
// Fonction sans retour
}
// Fonction avec attributs
@inline
fn fast_multiply(x: f64, y: f64) -> f64 {
return x * y;
}
fn fibonacci(n: i32) -> i32 {
if n <= 1 {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
fn factorial(n: i32) -> i32 {
if n <= 1 {
return 1;
}
return n * factorial(n - 1);
}
struct Point {
x: f64,
y: f64,
}
struct Vector3 {
x: f64,
y: f64,
z: f64,
}
struct Person {
name: str,
age: i32,
}
fn create_point() -> Point {
let p: Point = Point {
x: 10.0,
y: 20.0,
};
return p;
}
fn distance(v: Vector3) -> f64 {
return v.x * v.x + v.y * v.y + v.z * v.z;
}
fn max(a: i32, b: i32) -> i32 {
if a > b {
return a;
} else {
return b;
}
}
fn is_even(n: i32) -> bool {
if n % 2 == 0 {
return true;
}
return false;
}
fn sum_range(start: i32, end: i32) -> i32 {
mut sum: i32 = 0;
for i in start..end {
sum = sum + i;
}
return sum;
}
fn infinite_loop() -> void {
loop {
// Code répété indéfiniment
}
}
let a: i8 = 127;
let b: i16 = 32767;
let c: i32 = 2147483647;
let d: i64 = 9223372036854775807;
let e: i128 = 170141183460469231731687303715884105727;
let a: u8 = 255;
let b: u16 = 65535;
let c: u32 = 4294967295;
let d: u64 = 18446744073709551615;
let pi: f32 = 3.14159;
let e: f64 = 2.718281828459045;
let is_true: bool = true;
let is_false: bool = false;
let sum: i32 = 10 + 5; // Addition
let diff: i32 = 10 - 5; // Soustraction
let prod: i32 = 10 * 5; // Multiplication
let quot: i32 = 10 / 5; // Division
let rem: i32 = 10 % 3; // Modulo
let eq: bool = 5 == 5; // ĂgalitĂ©
let ne: bool = 5 != 3; // Différence
let lt: bool = 3 < 5; // Inférieur
let le: bool = 5 <= 5; // Inférieur ou égal
let gt: bool = 5 > 3; // Supérieur
let ge: bool = 5 >= 5; // Supérieur ou égal
let and_result: bool = true && false;
let or_result: bool = true || false;
let not_result: bool = !true;
mut x: i32 = 10;
x += 5; // x = x + 5
x -= 3; // x = x - 3
x *= 2; // x = x * 2
x /= 4; // x = x / 4
let numbers: [i32; 5] = [1, 2, 3, 4, 5];
let zeros: [f64; 10] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
fn get_element(arr: [i32; 5], index: i32) -> i32 {
return arr[index];
}
// Optimisation inline
@inline
fn fast_function() -> i32 {
return 42;
}
// Fonction pure (pas d'effets de bord)
@pure
fn calculate(x: f64) -> f64 {
return x * x;
}
// Fonction kernel (pour OS/embedded)
@kernel
fn interrupt_handler() -> void {
// Code d'interruption
}
// Pas de name mangling
@no_mangle
fn c_compatible_function() -> i32 {
return 0;
}
#![no_std]
#![no_main]
@entry_point
fn kernel_main() -> ! {
loop {}
}
fn print_value(value: &i32) -> void {
// Lecture seule
}
fn increment(value: &mut i32) -> void {
*value = *value + 1;
}
# Générer LLVM IRastralc program.astral --emit-llvm -o program.ll
# Générer assembleurastralc program.astral --emit-asm -o program.s
# Générer fichier objetastralc program.astral -o program.o
# Générer exécutableastralc program.astral -o program
# Pas d'optimisationastralc program.astral -O0
# Optimisation standardastralc program.astral -O2
# Optimisation agressiveastralc program.astral -O3
// â NE FONCTIONNE PAS
let distance: meter = 100.0;
let time: second = 10.0;
let speed: meter/second = distance / time;
// â NE FONCTIONNE PAS
let vector: vec3 = [1.0, 2.0, 3.0];
let matrix: Matrix<f64> = Matrix::new(3, 3);
let wave: WaveFunction = WaveFunction::new();
// â NE FONCTIONNE PAS
let planck: precise<128> = 6.62607015e-34;
// â NE FONCTIONNE PAS ENCORE
trait Simulate {
fn step(&mut self, dt: f64) -> void;
}
impl Simulate for Particle {
fn step(&mut self, dt: f64) -> void {
// ...
}
}
// â NE FONCTIONNE PAS ENCORE
match result {
Ok(value) => process(value),
Err(error) => handle_error(error),
}
// â NE FONCTIONNE PAS ENCORE
fn generic_function<T>(value: T) -> T {
return value;
}
// â NE FONCTIONNE PAS ENCORE
@simd
fn vectorized_add(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
return a + b;
}
@parallel
parallel for i in 0..1000 {
// Code parallĂšle
}
// â NE FONCTIONNE PAS ENCORE
@gpu
@workgroup(256)
fn gpu_kernel() -> void {
// Code GPU
}
fn fibonacci(n: i32) -> i32 {
if n <= 1 {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
fn main() -> i32 {
let result: i32 = fibonacci(10);
return result;
}
struct Point {
x: f64,
y: f64,
}
fn distance(p1: Point, p2: Point) -> f64 {
let dx: f64 = p2.x - p1.x;
let dy: f64 = p2.y - p1.y;
return dx * dx + dy * dy;
}
fn main() -> i32 {
let p1: Point = Point { x: 0.0, y: 0.0 };
let p2: Point = Point { x: 3.0, y: 4.0 };
let dist: f64 = distance(p1, p2);
return 0;
}
fn sum_to_n(n: i32) -> i32 {
mut sum: i32 = 0;
mut i: i32 = 1;
for i in 1..n {
sum = sum + i;
}
return sum;
}
fn main() -> i32 {
let total: i32 = sum_to_n(100);
return total;
}
@inline
@pure
fn square(x: f64) -> f64 {
return x * x;
}
@inline
fn cube(x: f64) -> f64 {
return x * x * x;
}
fn main() -> i32 {
let x: f64 = 5.0;
let sq: f64 = square(x);
let cb: f64 = cube(x);
return 0;
}
Découvrez comment installer astralc sur votre distribution Linux en consultant la documentation officielle.
astralc examples/hello.astral -o hello
astralc examples/fib.astral -O3 -o fib
astralc examples/test.astral --emit-llvm
astralc examples/test.astral --emit-asm
C'est un prototype fonctionnel qui démontre le concept et peut compiler des programmes réels, mais ce n'est pas encore un langage de production. C'est une base solide pour continuer le développement !