Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-11-19 04:54:17 -06:00
commit f086abcea6
789 files changed
+149185

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
#! @file fault.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains `fault`, which stops a program that has found a mistake of its own,
#! saying what, as an index past the end of a view stops it, as a contract that
#! fails does, `contracts`, which says whether they are checked, and the fault
#! the allocators of `core` stop with.
module core;
#! Stops the program at once, as a fault does: the report is "runtime error: "
#! and the text given, then the functions that were running, and the status is
#! 1, as every fault's.
#!
#! This is for a mistake the program cannot go on from, as a container asked
#! for an element past its end. It needs nothing of the system it runs on, so
#! every place a program runs gives it, and it never returns.
#! @param why What went wrong, as `Index 5 is out of bounds: the length is 3.`
@intrinsic
pub def fault(why: strview): void;
#! Whether the program's contracts are checked: where the program is checked,
#! as where it runs on the machine but for `run --fast`, and where it was built
#! with `--checks`, unless `--contracts on` or `--contracts off` says otherwise.
#! Left out, each `expects`, `asserts`, and `ensures` goes, conditions and all.
#!
#! The containers of `core` and std check what they are asked for with
#! contracts, as `expects(index < this._len)`, so a checked program stops where
#! one is asked for what it does not hold, as it stops at an index past the end
#! of a view, and one that is not checked trusts the program, as C does.
#!
#! It is known while compiling, so `if const contracts()` keeps work that only
#! contracts read out of a program that leaves them out.
#! @returns Whether they are.
@intrinsic
pub def contracts(): bool;
# Stops the program where an allocator gives no memory for what is asked of it,
# as `raw_allocate` stops it where the system gives none, which every program
# does, checked or not.
def exhausted(size: u64): void {
fault($"The allocator gave no memory for {size} bytes.");
}