Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-foundation

Source of release 0.6.1

0.6.1 / src / ak / support.lucb

#==============================================================================================
#
#   support - ClassInfo, Traits, containers and Function<> shapes
#
#   DESCRIPTION:
#       Hand-written generic shapes the generated declarations use (DESIGN.md §2.3, §2.6, §2.7):
#       ClassInfo, AK's Traits as an interface, the containers (inline capacity dropped), Checked<T>
#       and Function<>. Part of the skeleton generator's output (Ladybird 47c82b38d0).
#
#==============================================================================================

## The error code of AK::Error (DESIGN.md §2.10): `ErrorOr<T>` is `T!` and fails with it.
pub let ak_error: ErrorCode = ErrorCode.package(1)

## The error code of AK::Error::from_errno; the errno is kept in a per-thread slot (DESIGN.md §2.10).
pub let ak_errno_error: ErrorCode = ErrorCode.package(2)

## Class information of one class of a polymorphic hierarchy: name, pre-order class-id range,
## size and vtable (DESIGN.md §2.3).
pub struct ClassInfo:
    pub let name: str
    pub let first_id: u16
    pub let last_id: u16
    pub let size: usize
    pub let vtable: const void*
    ## The engine's MixinOffsets of this class (DESIGN.md §2.5), or none.
    pub let mixins: const void*? = none

## AK::Traits<K> (AK/Traits.h): AK's hash and equality for a key type, as an interface a one-byte
## traits struct implements (DESIGN.md §2.6).
pub interface Traits[K]:
    func hash_of(key: const K*) -> u32

    func equals(a: const K*, b: const K*) -> bool

## AK::Traits<T*>: pointers hash by address with AK's ptr_hash.
pub struct PtrTraits[T]: Traits[T*]:
    var empty_: u8

    func hash_of(key: const (T*)*) -> u32: return ptr_hash_void(*key)

    func equals(a: const (T*)*, b: const (T*)*) -> bool: return *a == *b

## AK::Traits<T> for key types the generator could not give their own traits struct.
pub struct DefaultTraits[T]: Traits[T]:
    var empty_: u8

    func hash_of(key: const T*) -> u32: trap("unported: AK::Traits<T>::hash")

    func equals(a: const T*, b: const T*) -> bool: trap("unported: AK::Traits<T>::equals")

## AK::Vector<T, N> (AK/Vector.h): size, capacity and the outline buffer; inline capacity dropped.
## A zero Vector is empty. `m_atomic` (set by vector_create_atomic) keeps the buffer in atomic
## storage, never scanned for pointers (DESIGN.md §3.3 rule 5).
pub struct Vector[T]: IndexedContainer[T]:
    pub var m_size: usize
    pub var m_capacity: usize
    pub var m_outline_buffer: T*?
    pub var m_atomic: bool

    func size() -> usize: return self.m_size

    func at(index: usize) -> T*: return vector_at((Vector[T]*)&self, index)

## AK::HashTable<T>::Bucket and OrderedBucket (AK/HashTable.h): the ordered-iteration links, the
## state (BucketState, or the probe length + 1), the stored hash and the value. Every bucket has
## the links; an unordered table leaves them none. The hash is always stored and checked first,
## which the donor does for types whose equality may be slow; for the others the check is
## redundant (equal values have equal hashes), so lookups behave identically.
pub struct HashTableBucket[T]:
    pub var previous: HashTableBucket[T]*?
    pub var next: HashTableBucket[T]*?
    pub var state: u8
    pub var hash: u32
    pub var storage: T

## AK::HashTable<T, TT> (AK/HashTable.h): closed hashing with Robin Hood probing over
## `m_mask + 1` buckets. `m_head`/`m_tail` are the OrderedCollectionData of an ordered table
## (`m_ordered`, set by the OrderedHashTable functions). A zero HashTable is empty.
pub struct HashTable[T, TT: Traits[T]]:
    pub var m_buckets: HashTableBucket[T]*?
    pub var m_head: HashTableBucket[T]*?
    pub var m_tail: HashTableBucket[T]*?
    pub var m_size: usize
    pub var m_mask: usize
    pub var m_ordered: bool

## AK::OrderedHashTable<T, TT> (AK/HashTable.h, IsOrdered = true): a HashTable that iterates in
## insertion order.
pub struct OrderedHashTable[T, TT: Traits[T]]:
    pub var m_table: HashTable[T, TT]

## AK::HashMap<K, V>::Entry (AK/HashMap.h).
pub struct HashMapEntry[K, V]:
    pub var key: K
    pub var value: V

## AK::HashMap<K, V>::EntryTraits (AK/HashMap.h).
pub struct HashMapEntryTraits[K, V, KT: Traits[K]]: Traits[HashMapEntry[K, V]]:
    var empty_: u8

    func hash_of(key: const HashMapEntry[K, V]*) -> u32: return hash_map_entry_traits_hash[K, V, KT](key)

    func equals(a: const HashMapEntry[K, V]*, b: const HashMapEntry[K, V]*) -> bool: return hash_map_entry_traits_equals[K, V, KT](a, b)

## AK::HashMap<K, V, KT> (AK/HashMap.h).
pub struct HashMap[K, V, KT: Traits[K]]:
    pub var m_table: HashTable[HashMapEntry[K, V], HashMapEntryTraits[K, V, KT]]

## AK::OrderedHashMap<K, V, KT> (AK/HashMap.h, IsOrdered = true).
pub struct OrderedHashMap[K, V, KT: Traits[K]]:
    pub var m_table: OrderedHashTable[HashMapEntry[K, V], HashMapEntryTraits[K, V, KT]]

## AK::Checked<T> (AK/Checked.h).
pub struct Checked[T]:
    pub var m_value: T
    pub var m_overflow: bool

## AK::Function<R()>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function0[R]:
    pub var call: (func(void*?) -> R)?
    pub var context: void*?

## AK::Function<R(A1)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function1[A1, R]:
    pub var call: (func(void*?, A1) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function2[A1, A2, R]:
    pub var call: (func(void*?, A1, A2) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function3[A1, A2, A3, R]:
    pub var call: (func(void*?, A1, A2, A3) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3, A4)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function4[A1, A2, A3, A4, R]:
    pub var call: (func(void*?, A1, A2, A3, A4) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3, A4, A5)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function5[A1, A2, A3, A4, A5, R]:
    pub var call: (func(void*?, A1, A2, A3, A4, A5) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3, A4, A5, A6)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function6[A1, A2, A3, A4, A5, A6, R]:
    pub var call: (func(void*?, A1, A2, A3, A4, A5, A6) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3, A4, A5, A6, A7)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function7[A1, A2, A3, A4, A5, A6, A7, R]:
    pub var call: (func(void*?, A1, A2, A3, A4, A5, A6, A7) -> R)?
    pub var context: void*?

## AK::Function<R(A1, A2, A3, A4, A5, A6, A7, A8)>: a function pointer beside its capture context (DESIGN.md §2.7).
pub struct Function8[A1, A2, A3, A4, A5, A6, A7, A8, R]:
    pub var call: (func(void*?, A1, A2, A3, A4, A5, A6, A7, A8) -> R)?
    pub var context: void*?