#! @file target.sakura #! @author John Christman (sorakatadzuma@gmail.com) #! @copyright Malunal Studios, LLC. #! @license MIT #! #! Contains the intrinsics naming the platform the program was checked for, as #! text, and the version of the compiler checking it. #! #! Code only for some platforms goes in `when os == linux { ... }`, or in a file #! declared `module path when os == linux;`, since both leave out what other #! platforms have. Code only for some compilers goes in #! `when compiler >= 1.2.0 { ... }` the same way. These give the same facts #! where code wants them as values. module core; #! The operating system the program was checked for. #! @returns `linux`, `macos`, `windows`, `freebsd`, or `unknown`. @intrinsic pub def os(): strview; #! The processor the program was checked for. #! @returns `x86_64`, `aarch64`, or `unknown`. @intrinsic pub def arch(): strview; #! How the program runs. #! @returns `vm` when run by `sakura run`, or `native` as an executable. @intrinsic pub def backend(): strview; #! A version of the compiler, as `compiler` gives it: three numbers, compared #! in order, so `1.10.0` comes after `1.9.0`. One is written to compare with as #! `version { 1, 2 }`, the parts left out 0. pub struct version : equatable, ordered { pub val major: u32; #! Changes where what a program means changes. pub val minor: u32; #! Changes where the language gains what it lacked. pub val patch: u32; #! Changes where only mistakes are fixed. } #! Whether two versions are the same. #! @param this The version. #! @param other The other. #! @returns Whether they are. pub def version::equals(&this, other: &version): bool { return this.compare(other) == 0; } #! How a version stands to another, part by part. #! @param this The version. #! @param other The other. #! @returns Negative where it comes first, 0 where they are the same, and #! positive where it comes after. pub def version::compare(&this, other: &version): i64 { return this.major as i64 - other.major as i64 if this.major != other.major; return this.minor as i64 - other.minor as i64 if this.minor != other.minor; return this.patch as i64 - other.patch as i64; } #! The version as it is written, as `1.2.0`. pub val version::text: string { get => $"{this.major}.{this.minor}.{this.patch}"; } #! The version of the compiler checking the program: the one reading it, not #! the one it was written for, so a library read by an older compiler can #! choose what that compiler understands. #! #! It is known while checking, so `if const compiler() >= (version { 1, 2 })` #! checks only the branch it takes. `when compiler >= 1.2` chooses declarations #! by it the same way. #! @returns The version, which the compiler fills in, so this costs nothing #! where the program runs. @intrinsic pub def compiler(): version;