Files
sakurac/compiler/conventions.sakura
T
2026-11-19 04:54:17 -06:00

32 lines
1.2 KiB
Plaintext

#! @file conventions.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains what the machine and the native backend both know of how calls
#! cross to C: how many words of a frame a value passed to a function of the
#! program takes, and which aggregates Microsoft's ABI passes by value. The
#! machine calls C through code of its own on Windows, and the native backend
#! writes the code of each call, so both cross by these rules.
module sakura::compiler;
#! How many words of a frame a value of a layout takes as an argument of a
#! function of the program: the address of one held in memory, or its words.
#! @param shape The layout.
#! @returns How many.
pub def argument_words(shape: &layout): u64 {
return in_memory(shape) ? 1 : word_count(shape) as u64;
}
#! Whether Microsoft's ABI passes an aggregate of a size by value, as an integer
#! of as many bytes, which it does for one of 1, 2, 4, or 8 bytes. It passes any
#! other by the address of a copy, and returns it through memory whose address
#! the caller passes.
#! @param size The aggregate's bytes.
#! @returns Whether it does.
pub def micro_by_value(size: u64): bool {
return size == 1 || size == 2 || size == 4 || size == 8;
}