Annotations
Annotations provide metadata for classes, functions, and members, instructing the compiler to enforce specific rules or link to external code.
Annotations start with the @ symbol.
@override
Indicates that a function is intended to override a method from a base class.
class Animal {
func sound() { println("Some sound") }
}
class Cat extends Animal {
constructor() {
super()
}
@override
func sound() {
println("Meow")
}
}
Cat().sound()Using @override on a non-overriding function results in a compile-time error. This prevents silent bugs when a base class method is renamed or removed.
@no_override
Prevents a function from being overridden in subclasses. This is useful for securing core logic within a class hierarchy.
class Base {
@no_override
func finalMethod() {
println("This logic cannot be changed")
}
}
class Child extends Base {
constructor() { super() }
}
Child().finalMethod()@native
Marks a function as implemented in external native code (C/C++).
class Math {
@native("std_math_pow")
func pow(base: Float, exp: Float): Float
}
println(Math.pow(2.0, 3.0))Native functions do not have a body in AutoLang. The string parameter (e.g., "std_math_pow") is the linkage identifier used by the VM to find the C++ implementation.
@no_extends
Prevents a class from being inherited by any other class. This is essentially sealing the class, guaranteeing that its behavior cannot be modified via subclassing.
@no_extends
class CoreSystem {
func boot() {
println("Booting up...")
}
}
CoreSystem().boot()@no_constructor
Prevents the compiler from generating a default primary constructor and disallows instantiation of the class. This is often combined with @no_extends to create "Utility Classes" that only contain static functions.
@no_extends
@no_constructor
class Utils {
static func log(msg: String) {
println(msg)
}
}
Utils.log("Hello from Utility Class")@import
Imports a module or a standard library component into the current file scope.
@import("std/math")
println(Math.pow(5, 5))The import annotation must be declared at the top level of the file, outside of any class or function definitions.
