You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RawPtr<T> // ham pointer — sadece @ManualMemory
(T1, T2) -> R // function pointer
Result<T, E> // yerleşik generic enum
type NodeId = u32; // type alias
2.6 Tip Uyumu Kuralları
// Integer literal → Float'a atanabilir
Float pi = 3; // ✅ (3 → 3.0)
Float f = 42; // ✅
// Integer literal → herhangi bir sized integer'a atanabilir
u8 byte = 255; // ✅
i32 val = -1; // ✅
// Sized integer → Integer (genel tip) atanabilir
Integer n = some_u32; // ✅
// Implicit widening YOK — aynı boyut grubu dışında cast zorunlu
u32 word = some_u64; // ❌ HATA — as kullan
u32 casted = some_u64 as u32; // ✅
// HashMap / TreeMap → Map (interface) atanabilir
Map<String, Integer> m = HashMap(); // ✅
2.7 toString()
Tüm class'lar otomatik olarak toString() : String metoduna sahiptir (Object'ten gelir).
Override etmek için class içinde aynı imzalı metodu tanımla:
public class Task {
public toString() : String {
return "[${this.status}] ${this.title}";
}
}
3. Tip Bildirimi Kuralları
Arimo'da iki farklı bağlama göre iki sözdizimi kullanılır:
3.1 Bildirim bağlamı — : Type (kolon, tip sağda)
Field, parametre ve dönüş tipi bildirimlerinde tip her zaman sağda gelir:
// Field
private readonly radius : Float;
private color : String;
// Parametre
public constructor(id: String, radius: Float) { ... }
// Dönüş tipi
public getRadius() : Float { ... }
public area() : Float { ... }
3.2 Local değişken — Type name (tip solda)
Method gövdesi içindeki yerel değişkenlerde tip solda gelir:
String name = "Arimo"; // null olamaz — garanti
String? name = null; // nullable — açıkça işaretlenmeli
// Smart cast — if bloğu içinde derleyici null olmadığını bilir
String? title = task.getTitle();
if (title != null) {
IO.print(title); // burada String, String? değil
}
// Null-safe erişim — field ve method call
String? name = user?.getName(); // method çağrısı
Integer? len = name?.length(); // zincir
String? found = user?.findTask("id"); // argümanlı method çağrısı
String? address = user?.address; // field erişimi
5. Literal'lar
// Sayılar
Integer x = 42;
Float f = 3.14;
u32 h = 0xDEADBEEF; // hex literal
u8 b = 0b10101010; // binary literal
// String interpolation — + operatörü string birleştirme için değil
IO.print("Merhaba ${name}!");
IO.print("Sonuç: ${a + b} birim");
IO.print("Oran: %${rate}");
// Boolean
Boolean t = true;
Boolean f = false;
6. Erişim Belirteçleri
public // her yerden
private // sadece bu class
protected // bu class + alt sınıflar
internal // sadece aynı module
Class içinde her field ve metodda zorunlu
Interface içinde yazılmaz — zaten public
7. Modifier'lar
private readonly id : String; // bir kez atanır
public static MAX : Integer = 50; // class seviyesi
public static readonly VERSION : String = "1.4.0";
8. Class
public class Circle extends Shape implements Drawable, Movable {
private readonly id : String;
private readonly radius : Float;
private color : String;
public constructor(id: String, radius: Float, color: String) {
this.id = id;
this.radius = radius;
this.color = color;
}
public static create(radius: Float, color: String) : Circle {
return Circle(Time.generateId(), radius, color);
}
public getRadius() : Float { return this.radius; }
public getColor() : String { return this.color; }
public setColor(color: String) : Void {
this.color = color;
}
}
new yok — Circle(...) veya Circle.create(...)
override keyword — opsiyonel, metodu üst sınıf metodunu override ediyor olarak işaretler (kaydedilir, şu an enforce edilmiyor)
constructor açık anahtar kelime
super(...) — üst sınıf constructor'ını çağırır
Field'lara varsayılan değer verilebilir: private color : String = "red";
9. Abstract Class
public abstract class Shape implements Drawable {
private readonly color : String;
protected constructor(color: String) {
this.color = color;
}
public getColor() : String { return this.color; }
public abstract draw() : Void;
public abstract area() : Float;
}
10. Interface
interface Drawable {
draw() : Void;
area() : Float;
}
// Default method — implementing class override etmek zorunda değil
interface Updatable {
update(dt: Float) : Void;
default updateFixed() : Void {
Float dt = 0.016;
IO.print("fixed update");
}
}
public yazılmaz — her method zaten public
default keyword ile gövdeli method tanımlanabilir
Bir class birden fazla interface implement edebilir
11. Struct (Value Type)
public struct Vec3 {
x : Float;
y : Float;
z : Float;
@ForceInline
public operator +(other: Vec3) : Vec3 {
return Vec3(this.x + other.x, this.y + other.y, this.z + other.z);
}
public operator ==(other: Vec3) : Boolean {
return this.x == other.x && this.y == other.y && this.z == other.z;
}
public dot(other: Vec3) : Float {
return this.x * other.x + this.y * other.y + this.z * other.z;
}
}
// Kullanım — auto-constructor (field sırası)
Vec3 pos = Vec3(0.0, 1.0, 0.0);
Vec3 vel = Vec3(1.0, 0.0, 0.0);
Vec3 sum = pos + vel; // operator overloading
Stack-allocated, copy semantics, extends yok
Auto-constructor field sırasından üretilir
implements InterfaceName ile interface implement edebilir
BorrowChecker: struct copy type, move takibi yok
12. Enum
// Saf variant'lar
public enum Priority {
Low, Medium, High, Critical;
public isUrgent() : Boolean {
return this == Priority.High || this == Priority.Critical;
}
public label() : String {
switch (this) {
case Priority.Low: return "Low";
case Priority.Medium: return "Medium";
case Priority.High: return "High";
case Priority.Critical: return "Critical";
}
}
}
// Veri taşıyan variant'lar
public enum Shape {
Circle(Float),
Rectangle(Float, Float),
Point;
}
// Pattern matching
match shape {
Shape.Circle(r) => IO.print("circle r=${r}"),
Shape.Rectangle(w, h) => IO.print("rect ${w}x${h}"),
Shape.Point => IO.print("point"),
_ => IO.print("other"),
}
13. Exception
public class TaskNotFoundException extends Exception {
private readonly taskId : String;
public constructor(taskId: String) {
super("Task not found: ${taskId}");
this.taskId = taskId;
}
public getTaskId() : String { return this.taskId; }
}
14. Union (Systems)
// CPU register overlapping — OS / embedded için
public union Register {
full : u32;
bytes : Array<u8, 4>;
}
Field'lar aynı bellek adresini paylaşır
@ManualMemory context'inde kullanım önerilir
15. Generics
// Parametreli class
public class Pair<First, Second> {
private readonly first : First;
private readonly second : Second;
public static of(first: First, second: Second) : Pair<First, Second> {
return Pair(first, second);
}
public getFirst() : First { return this.first; }
public getSecond() : Second { return this.second; }
}
// Bound — T, Drawable interface'ini implement etmeli
public class Renderer<T: Drawable> {
public render(item: T) : Void {
item.draw();
}
}
// Çoklu bound
public class Sorter<T: Comparable + Printable> { ... }
16. Type Alias
type NodeId = u32;
type ByteFlag = u8;
type Callback = (String) -> Void;
17. Result<T, E>
// Yerleşik generic enum
Result<String, Integer> r = Result.Ok("success");
Result<String, String> e = Result.Err("not found");
if (r.isOk()) {
IO.print("ok");
}
18. Koleksiyonlar
// List — üç oluşturma yolu
List<Task> tasks = List(); // boş
List<String> names = List.of("Alice", "Bob"); // başlangıç değerleriyle
List<Task> empty = List.empty(); // boş (alternatif)
tasks.append(task);
tasks.length();
tasks.isEmpty();
tasks.filter((task) -> task.isDone());
tasks.sortedBy((a, b) -> a.getTitle().compareTo(b.getTitle()));
tasks.take(5);
tasks.takeLast(5);
tasks.reduce(0, (sum, item) -> sum + item.getCount());
// HashMap — sırasız
Map<String, Integer> scores = HashMap();
Map<String, Integer> preset = HashMap.of("alice", 100, "bob", 90); // veya
Map<String, Integer> alt = HashMap.create(); // alternatif factory
scores.set("alice", 100);
Integer? val = scores.get("alice"); // nullable döndürür!
Integer v = scores.getOrDefault("bob", 0); // null-safe
scores.containsKey("alice");
scores.remove("alice");
scores.keys();
scores.values();
scores.entries();
scores.length();
// TreeMap — key'e göre sıralı
Map<String, Integer> sorted = TreeMap();
Map<String, Integer> sortedAlt = TreeMap.create();
// Array — compile-time boyut, stack
Array<Float, 4> vec = Array.zeroed();
vec[0] = 1.0; // index ile yaz
Float f = vec[0]; // index ile oku
vec.get(0); // alternatif getter
vec.set(0, 1.0); // alternatif setter
Integer len = vec.length();
Slice<Float> view = vec.asSlice(); // Slice'a dönüştür
Slice<Float> view2 = vec.slice(); // alternatif
// Slice — non-owning view
Slice<Float> s = Slice.of(rawPtr, count); // pointer'dan oluştur
s.length();
Float elem = s[0]; // index ile oku
s.get(0); // alternatif
s.set(0, 1.0); // alternatif setter
// Pair — iki yol
Pair<String, Integer> pair = Pair.of("score", 100); // factory
Pair<String, Integer> pair2 = Pair("score", 100); // direkt constructor
pair.getFirst();
pair.getSecond();
19. Kontrol Akışı
if / else
if (total > 10) {
IO.print("Large");
} else if (total > 5) {
IO.print("Medium");
} else {
IO.print("Small");
}
Ternary
String label = isUrgent ? "urgent" : "normal";
switch
// break yok — her case direkt döner
switch (priority) {
case Priority.Low: return "Low";
case Priority.High: return "High";
case Priority.Critical: return "Critical";
}
match (pattern matching — expression)
match bir expression'dır, statement değil. Değer döndürür veya statement olarak kullanılır.
// Statement olarak
match shape {
Shape.Circle(r) => IO.print("r=${r}"),
Shape.Rectangle(w, h) => IO.print("${w}x${h}"),
_ => IO.print("other"),
}
// Expression olarak — atama veya return
String desc = match shape {
Shape.Circle(r) => "circle",
Shape.Rectangle(w, h) => "rect",
_ => "other",
};
while
while (count > 0) {
count--;
}
for-each
for (Task task : this.tasks) {
IO.print(task.getTitle());
}
klasik for
for (Integer i = 0; i < 10; i++) {
IO.print("${i}. adım");
}
break / continue
for (Integer i = 0; i < 10; i++) {
if (i == 5) { break; } // döngüden çık
if (i == 3) { continue; } // sonraki iterasyona geç
IO.print("${i}");
}
public class ApiService {
public async fetchUser(id: String) : String {
String result = await ApiService.getData(id);
return result;
}
public static async getData(id: String) : String {
return "data";
}
}
async — method modifier
await — expression prefix, inner type'ı döndürür
CodeGen: state machine transform (Faza 4'te implement edilecek)
29. Entry Point
public class Application {
public static readonly NAME : String = "Arimo";
public static readonly VERSION : String = "1.4.0";
public static main() : Void {
IO.print("${Application.NAME} v${Application.VERSION}");
}
}
Parse edilip AST'de saklanıyor; CodeGen state machine henüz yok
@Pure enforcement
Kaydedilir; mutasyon kontrolü CodeGen'de
ARC / GC
CodeGen'de henüz implement edilmedi
About
Stage 0 bootstrap compiler for the Arimo programming language, written in Rust. Features a custom lexer, parser, typechecker, borrow checker, and native code generation.