Files
sakurac/core/site.sakura
T

57 lines
2.5 KiB
Plaintext
Raw Normal View History

2026-10-26 10:14:11 -05:00
#! @file site.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains `site`, where a call is written, and the intrinsics the compiler
#! fills in where a call is written: `call_site`, which gives that site, and
#! `source_of` and `values_of`, which give an expression's text and its
#! operands' values, as checks report them.
module core;
#! Where a call is written, which the compiler fills in at each call site.
#!
#! A `site` is made only by `call_site`, which gives the site of the call it is
#! written in, so a function is told where it was called from by taking one and
#! being passed `call_site()`.
pub struct site {
pub val path: strview; #! The file the call is written in.
pub val line: u32; #! Its one-based line.
pub val column: u32; #! Its one-based column.
pub val signature: strview; #! The function the call is written in, as it is declared.
}
#! Gives where this call is written.
#! @returns The path, line, and column of the call, and the signature of the
#! function holding it. The compiler fills each in while compiling, so
#! this costs nothing where the program runs.
@intrinsic
pub def call_site(): site;
#! Gives the text of an expression as it is written.
#!
#! The expression is not evaluated: only the source it was written as is taken,
#! so `source_of(count != 0)` is the text `count != 0` and nothing runs. The
#! text is written into the program, so this costs nothing where it runs.
#! @tparam T The type of the expression, which is never evaluated.
#! @param value The expression to take the text of.
#! @returns Its text, exactly as it is written.
@intrinsic
pub def source_of<T>(value: T): strview;
#! Gives the values the operands of an expression held.
#!
#! Unlike `source_of`, this evaluates the expression's operands, so it costs
#! what they cost and what printing them costs. A comparison gives both of its
#! operands, as `count = 0`, leaving out any that is written as a literal. An
#! expression that is neither a comparison nor a value of its own gives no text,
#! since the operands of `&&` and `||` are not both evaluated.
#! @tparam T The type of the expression.
#! @param value The expression to take the values of.
#! @returns What its operands held, or empty text. The text is built where the
#! call is written, so it is a `string` that gives its memory back
#! there.
@intrinsic
pub def values_of<T>(value: T): string;