99 lines
4.3 KiB
Plaintext
99 lines
4.3 KiB
Plaintext
#! @file builtin.sakura
|
|
#! @author John Christman (sorakatadzuma@gmail.com)
|
|
#! @copyright Malunal Studios, LLC.
|
|
#! @license MIT
|
|
#!
|
|
#! Contains the types the syntax makes, which the compiler holds itself rather
|
|
#! than finding them in a library: `string`, which interpolation makes, the
|
|
#! views `span`, `slice`, and `strview`, which `a[:]` and literals make, `range`,
|
|
#! which `a..b` makes, and `maybe`, `result`, and `nothing`, which `else`, `for`,
|
|
#! and `?` read. They are found where `i64` is, from every file.
|
|
#!
|
|
#! Their declarations are text read as the first file of `core`'s root, before
|
|
#! `core`'s own, so what the compiler relies on of them is written here, beside
|
|
#! the code relying on it: `string`'s fields in their order, `maybe`'s `none`
|
|
#! first, `span`'s two words, and `range`'s three fields. They name `core`'s
|
|
#! traits and `allocator`, so they are read only with `core`. Their methods are
|
|
#! `core`'s, declared through them as `u8`'s are.
|
|
|
|
module sakura::analyzer;
|
|
|
|
|
|
#! The path the text is read as, which notes and traces into it name.
|
|
pub const builtin_path: strview = "<built-in>";
|
|
|
|
#! The declarations of the types the syntax makes, as `core`'s root.
|
|
pub const builtin_text: strview = """
|
|
#! The types the syntax makes, which the compiler holds. Their methods are
|
|
#! `core`'s.
|
|
module core;
|
|
|
|
#! What a `maybe` holds where its value is missing, which `nothing {}` makes
|
|
#! the empty one of any `maybe`. It is apart from `void`, the value of what
|
|
#! gives nothing.
|
|
pub struct nothing {}
|
|
|
|
#! A value that may be missing: either a `T`, as `some`, or `nothing`, as
|
|
#! `none`, which comes first, so a `maybe` left without a value holds nothing.
|
|
#! A value converts to a `maybe` of its type wherever one is wanted.
|
|
#! @tparam T The type of the value it may hold.
|
|
pub union maybe<T> {
|
|
pub var none: nothing; #! Holds nothing: the value is missing.
|
|
pub var some: T; #! Holds the value.
|
|
}
|
|
|
|
#! The outcome of something that may fail: either the value it gave, as
|
|
#! `value`, or the error that stopped it, as `error`, which must be handled
|
|
#! where it is made.
|
|
#! @tparam T The type of the value it gives where it succeeds.
|
|
#! @tparam E The type of the error it gives where it fails.
|
|
@nodiscard
|
|
pub union result<T, E> {
|
|
pub var value: T; #! The value, where it succeeded.
|
|
pub var error: E; #! The error, where it failed.
|
|
}
|
|
|
|
#! A view over a run of elements that something else holds: where they begin,
|
|
#! and how many there are. It owns nothing, and writes nothing.
|
|
#! @tparam T The type of the elements it views.
|
|
pub struct span<T> : hashable, equatable, indexable<u64, T>, spannable<T>, iterable<T> {
|
|
var _dat: *T;
|
|
var _len: u64;
|
|
}
|
|
|
|
#! A writable view over a run of elements that something else holds, which
|
|
#! converts to a `span<T>` wherever a reader is wanted.
|
|
#! @tparam T The type of the elements it views.
|
|
pub struct slice<T> : hashable, equatable, indexable<u64, T>, assignable<u64, T>, spannable<T>, sliceable<T>, iterable<T> {
|
|
var _dat: *mut T;
|
|
var _len: u64;
|
|
}
|
|
|
|
#! Text that is only read, as a literal is: a view of bytes.
|
|
pub type strview = span<u8>;
|
|
|
|
#! Text that owns the memory its bytes are written in, which interpolation
|
|
#! makes. Its memory is its allocator's, or `raw_allocate`'s where it has
|
|
#! none, and goes back where its scope ends.
|
|
pub struct string
|
|
: owning, hashable, indexable<u64, u8>, assignable<u64, u8>, spannable<u8>, sliceable<u8>, iterable<u8>,
|
|
extendable<strview>, equatable, ordered, copyable, moveable
|
|
{
|
|
var _alc: maybe<&mut allocator>;
|
|
var _dat: *mut u8;
|
|
var _len: u64;
|
|
var _cap: u64;
|
|
}
|
|
|
|
#! The integers from `start` up to, but not including, `end`, as `a..b`
|
|
#! makes, or through `end`, as `a..=b` makes, or the members of an enum
|
|
#! between them, in the order of their values. The compiler makes one from
|
|
#! its fields in the order they are declared.
|
|
#! @tparam T The type of the integers, or the enum.
|
|
pub struct range<T> : sized_iterator<T>, backward_iterator<T> where T: ordinal {
|
|
pub var start: T; #! The first value it gives, while it gives any.
|
|
pub var end: T; #! Where it ends: just past its last, or its last where it was made by `..=`.
|
|
var _last: bool; #! Whether `end` is still to be given, as `a..=b` gives it.
|
|
}
|
|
""";
|