/**
A compile-and-run sketch of `sparkles:ui` authoring, built **top-down** from
**expressions**: children are D lazy variadic arguments,
Node column(ref Ui ui, NamedOnly _ = NamedOnly.init, int gap = 0, …,
NamedOnly _children = NamedOnly.init, scope ChildFn[] children...)
so `ui.column(gap: 1, children: a, b, c)` reads like the inside-out form, but
the compiler wraps each of `a`, `b`, `c` in a delegate literal. `column` opens
its element (appended, pushed on the open stack, its env pushed), calls each
child delegate in order, then closes: the fit size is computed from the
children right there (Clay's `CloseElement`) and the env pops.
A child's identity is its parent's id mixed with its *argument position*: a
ternary with `Node.none` keeps every later sibling's position, so an `if`
never shifts identity. `mapKeyed` splices a keyed run of rows into the one
argument position it occupies; each row's id mixes in its key.
The `scope` lazy variadic must not allocate a closure in the caller. Stock
DMD 2.115 / LDC 1.43 do allocate one ("allocates closure … with the GC"), so
`@nogc` views need the frontend fix for it (dlang/dmd#22885; see README.md).
Nothing here lays out or paints. Every name is a proposal.
*/
module (module) lazystackA compile-and-run sketch of sparkles:ui authoring, built top-down from
expressions*: children are D lazy variadic arguments,
Node column(ref Ui ui, NamedOnly = NamedOnly.init, int gap = 0, …,
NamedOnly children = NamedOnly.init, scope ChildFn[] children...)
so ui.column(gap: 1, children: a, b, c) reads like the inside-out form, but
the compiler wraps each of a, b, c in a delegate literal. column opens
its element (appended, pushed on the open stack, its env pushed), calls each
child delegate in order, then closes: the fit size is computed from the
children right there (Clay's CloseElement) and the env pops.
A child's identity is its parent's id mixed with its argument position: a
ternary with Node.none keeps every later sibling's position, so an if
never shifts identity. mapKeyed splices a keyed run of rows into the one
argument position it occupies; each row's id mixes in its key.
The scope lazy variadic must not allocate a closure in the caller. Stock
DMD 2.115 / LDC 1.43 do allocate one ("allocates closure … with the GC"), so
@nogc views need the frontend fix for it (dlang/dmd#22885; see README.md).
Nothing here lays out or paints. Every name is a proposal.
lazystack;
import (package) corecore.(module) core.interpolationThis module provides definitions to support D's
interpolated expression sequence literal, sometimes
called string interpolation.
string str;
int num;
// the compiler uses this module to implement the
// i"..." literal used here.
auto a = i"$(str) has $(num) items.";
The variable a is a sequence of expressions:
a[0] == InterpolationHeader()
a[$-1] == InterpolationFooter()
First and last, you see the header and footer, to
clearly indicate where interpolation begins and ends.
Note that there may be nested interpolated sequences too,
each with their own header and footer. Think of them
as a set of balanced parenthesis around the contents.
Inside, you will find three general categories of
content: InterpolatedLiteral!"string" for string
expressions, InterpolatedExpression!"code" for code
expressions, and then the values themselves as their
own type.
In the example:
auto a = i"$(str) has $(num) items.";
We will find:
a[0] == InterpolationHeader()
a[1] == InterpolatedExpression!"str"
a[2] == str
a[3] == InterpolatedLiteral!" has ";
a[4] == InterpolatedExpression!"num";
a[5] == num
a[6] == InterpolatedLiteral!" items.";
a[7] == InterpolationFooter()
a.length == 8;
You can see the correspondence with the original
input: when you write $(expression), the string of the
expression is passed as InterpolatedExpression!ThatString,
(excluding any parenthesis around the expression),
and everything else is passed as InterpolatedLiteral!str,
in the same sequence as they appeared in the source.
After an InterpolatedExpression!..., you will find the
actual value(s) in the tuple. (If the expression expanded
to multiple values - for example, if it was itself a tuple,
there will be multiple values for a single expression.)
Library functions should NOT attempt to mixin the code
from an InterpolatedExpression themselves. Doing so
will fail, since it is coming from a different scope anyway.
The string is provided to you only for informational purposes
and as a sentinel to separate things the user wrote.
Your code should be able to handle an empty code string
in InterpolatedExpression or even an entirely missing
InterpolatedExpression, in case an implementation decides to
not emit these.
The toString members on these return null, except for
the InterpolatedLiteral, which returns the literal string.
This is to ease processing by generic functions like
std.stdio.write or std.conv.text, making them effectively
transparently skipped.
To extract the string from an InterpolatedLiteral, you can
use an is expression or the .toString method.
To extract the string from a InterpolatedExpression, you can
use an is expression or the .expression member.
None of these structures have runtime state.
interpolation : (struct) core.interpolation.InterpolationFooterditto
InterpolationFooter, (struct) core.interpolation.InterpolationHeaderSentinel values to indicate the beginning and end of an
interpolated expression sequence.
Note that these can nest, so while processing a sequence,
it may be helpful to keep a nesting count if that knowledge
is important to your application.
InterpolationHeader;
import (package) corecore.(module) core.lifetimelifetime : (alias template) lazystack.emplace = core.lifetime.emplace(T)(T* chunk)Given a pointer chunk to uninitialized memory (but already typed
as T), constructs an object of non-class type T at that
address. If T is a class, initializes the class reference to null.
emplace;
import (package) stdstd.(package) std.experimentalexperimental.(package) std.experimental.allocatorallocator.(package) std.experimental.allocator.building_blocksbuilding_blocks.(module) std.experimental.allocator.building_blocks.regionSource
std/experimental/allocator/building_blocks/region.d
region : (alias struct) lazystack.InSituRegion = std.experimental.allocator.building_blocks.region.InSituRegion(ulong size, ulong minAlign = platformAlignment)InSituRegion is a convenient region that carries its storage within itself
(in the form of a statically-sized array).
The first template argument is the size of the region and the second is the
needed alignment. Depending on the alignment requested and platform details,
the actual available storage may be smaller than the compile-time parameter. To
make sure that at least n bytes are available in the region, use
``InSituRegion!(n + a - 1, a).
Given that the most frequent use of InSituRegion is as a stack allocator, it
allocates starting at the end on systems where stack grows downwards, such that
hot memory is used first.
InSituRegion;
import (package) stdstd.(module) std.traitsTemplates which extract information about types and symbols at compile time.
Category Templates Symbol Name traits fullyQualifiedName mangledName moduleName packageName Function traits isFunction arity functionAttributes hasFunctionAttributes functionLinkage FunctionTypeOf isSafe isUnsafe isFinal ParameterDefaults ParameterIdentifierTuple ParameterStorageClassTuple Parameters ReturnType SetFunctionAttributes variadicFunctionStyle Aggregate Type traits BaseClassesTuple BaseTypeTuple classInstanceAlignment EnumMembers FieldNameTuple Fields hasAliasing hasElaborateAssign hasElaborateCopyConstructor hasElaborateDestructor hasElaborateMove hasIndirections hasMember hasStaticMember hasNested hasUnsharedAliasing InterfacesTuple isInnerClass isNested MemberFunctionsTuple RepresentationTypeTuple TemplateArgsOf TemplateOf TransitiveBaseTypeTuple Type Conversion CommonType AllImplicitConversionTargets ImplicitConversionTargets CopyTypeQualifiers CopyConstness isAssignable isCovariantWith isImplicitlyConvertible isQualifierConvertible Type Constructors InoutOf ConstOf SharedOf SharedInoutOf SharedConstOf SharedConstInoutOf ImmutableOf QualifierOf Categories of types allSameType ifTestable isType isAggregateType isArray isAssociativeArray isAutodecodableString isBasicType isBoolean isBuiltinType isCopyable isDynamicArray isEqualityComparable isFloatingPoint isIntegral isNarrowString isConvertibleToString isNumeric isOrderingComparable isPointer isScalarType isSigned isSIMDVector isSomeChar isSomeString isStaticArray isUnsigned Type behaviours isAbstractClass isAbstractFunction isCallable isDelegate isExpressions isFinalClass isFinalFunction isFunctionPointer isInstanceOf isIterable isMutable isSomeFunction isTypeTuple General Types ForeachType KeyType Largest mostNegative OriginalType PointerTarget Signed Unconst Unshared Unqual Unsigned ValueType Promoted Misc lvalueOf rvalueOf Select select User-Defined Attributes hasUDA getUDAs getSymbolsByUDA
Source
std/traits.d
traits : (enum) std.traits.FunctionAttributeReturns the FunctionAttribute mask for function func.
FunctionAttribute, (alias template) lazystack.functionAttributes = std.traits.functionAttributes(alias func) if (isCallable!func)Returns the FunctionAttribute mask for function func.
functionAttributes, (alias template) lazystack.Parameters = std.traits.Parameters(alias func) if (isCallable!func)Get, as a tuple, the types of the parameters to a function, a pointer
to function, a delegate, a struct with an opCall, a pointer to a
struct with an opCall, or a class with an opCall.
Parameters, (alias template) lazystack.ReturnType = std.traits.ReturnType(alias func) if (isCallable!func)Get the type of the return value from a function,
a pointer to function, a delegate, a struct
with an opCall, a pointer to a struct with an opCall,
or a class with an opCall. Please note that ref
is not part of a type, but the attribute of the function
(see template functionAttributes).
To reduce template instantiations, consider instead using
typeof(() { return func(args); } ()) if the argument types are known or
static if (is(typeof(func) Ret == return)) if only that basic test is needed.
ReturnType;
import (package) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.bufferA @nogc container with Small Buffer Optimization (SBO).
Provides an append-only buffer that stores small amounts of data inline
(avoiding heap allocation) and automatically switches to heap storage
when capacity is exceeded.
Primary use case: appending elements in a temporary scope where GC
allocation is not desired.
buffer : (alias struct) lazystack.BoundedSink = sparkles.base.buffer.BoundedSink(T)A bounded output range over storage someone else owns.
Handed out by tryWrite and valid only inside it, so a partially written
destination is never observable: either the whole write fits, or nothing is
kept. Overflow is recorded rather than thrown, which is what lets the entire
sparkles.base.text.writers family compose inside one attempt.
BoundedSink, (alias template) lazystack.HeapBuffer = sparkles.base.buffer.HeapBuffer(T, Storage extra = Storage.none) if (!(extra & ~Storage.unique))A buffer with no inline array: the elements always live on the heap.
For a sequence whose typical size makes an inline array dead weight — the struct
costs one slice regardless of how much it holds. Size it up front with reserve;
there is no N to raise.
HeapBuffer, (alias template) lazystack.InlineBuffer = sparkles.base.buffer.InlineBuffer(T, ulong N, Storage extra = Storage.none) if (!(extra & ~Storage.unique))A buffer that never allocates: the elements live in the inline T[N] and
nowhere else.
The policy with a guarantee no other has. Because there is no union, a slice of
the storage is provably a reference to the enclosing frame, so -dip1000
rejects returning one from a @safe function — the property CString is built
on. It also has no destructor, so it is plain data: copyable, comparable, and
usable as a field in an aggregate that must stay POD.
It is deliberately not an output range: put promises to accept what it is
given, and this cannot. Write into it with tryWrite.
Pass Storage.unique as extra for the move-only form, which is what prevents
an accidental copy of a large one.
InlineBuffer, (enum) sparkles.base.buffer.StorageWhat storage a buffer may use, and whether it may be copied.
The bits are capabilities, so the combination is the policy: inline alone
never allocates, heap alone carries no inline array, and both together is the
small-buffer optimization. ``Storage.none is the empty set — the neutral
default for an alias's extra parameter — but a buffer with neither storage bit
has nowhere to put anything and fails Buffer's constraint.
Storage, (alias template) lazystack.UniqueBuffer = sparkles.base.buffer.UniqueBuffer(T, ulong N = max(size_t(1), (T[]).sizeof / T.sizeof))Small-buffer optimization with a sole owner: inline while the elements fit, heap
when they do not, and copying is disabled.
Disabling copies is what removes the reference count from the grow path — there
is no second owner to consult. Hand a finished one to the shared world with
toShared, which consumes it and transfers any heap block without reallocating.
UniqueBuffer;
import (package) sparklessparkles.(package) sparkles.basebase.(package) sparkles.base.poolpool.(module) sparkles.base.pool.text_poolVariable-length text behind generational ids.
TextPool generalises DqlEngine.intern (sparkles.dql.engine): text is
appended to one inline byte arena and addressed by a TextSpan. The
difference is that callers never hold the span. They hold an id — a Handle
into a pool of spans — so the arena can reset when it empties and compact
when it fragments without invalidating anything a caller kept.
The price is that text is read only inside a borrow (withText). While any
borrow is open the pool does not move bytes, so the slice a callback receives
stays valid for exactly as long as the callback runs.
See docs/specs/base/pool.md §5 (POOL12–POOL18, POOL22).
text_pool : (alias struct) lazystack.TextPool = sparkles.base.pool.text_pool.TextPool(Tag, ulong slots, ulong bytes, ulong maxText = bytes, Reuse reuse = Reuse.lifo) if (slots > 0 && (bytes > 0) && (bytes < (uint).max) && (maxText > 0) && (maxText <= bytes))A fixed-capacity store of up to slots texts sharing bytes bytes.
TextPool;
import (package) sparklessparkles.(package) sparkles.basebase.(package) sparkles.base.texttext.(module) sparkles.base.text.enumsEnum ↔ text/value conversion.
Format-agnostic primitives for an enum's two serialized forms:
enumMemberName — a value's member name, recased per a
CaseStyle.
enumMemberNameOr — the same, for an enum whose members are not
distinctly valued, and for a value that may not be a declared member at
all.
enumCommonPrefix — the prefix every member name shares, so a
C-derived enum can be rendered without it.
enumFromValue — a membership-checked underlying value back to
the enum.
Enums that come from C are why the last three exist. A .h translated by
ImportC routinely declares several members with the same value — an extension
enumerator promoted to core keeps its old spelling as an alias — and every
member repeats the type's name as a prefix, because C has no enum scope. The
final switch in enumMemberName rejects the first outright (duplicate
case labels), and nothing here would strip the second.
The module is unopinionated — it applies no per-member name override (that is a
policy concern for a layer such as @WireName in sparkles:wired). The inverse
name direction is readEnumString (sparkles.base.text.readers); the
output-range writers are writeEnumMemberName / writeEnumValue
(sparkles.base.text.writers).
enums : (alias template) lazystack.enumMemberName = sparkles.base.text.enums.enumMemberName(CaseStyle style = CaseStyle.original, E)(in E value) if (is(E == enum))The name of the declared member equal to value, recased per style as a
compile-time string literal (so the call allocates nothing).
value must be a declared member of E. The generated final switch rejects a
duplicate-valued enum at compile time (duplicate case labels) and asserts on a
value that is not a declared member.
enumMemberName;
import (package) sparklessparkles.(package) sparkles.basebase.(package) sparkles.base.texttext.(module) sparkles.base.text.writers@nogc-compatible text writing utilities for output ranges.
Provides functions for writing integers, floats, escaped characters/strings,
and ANSI escape sequences to output ranges without GC allocation.
writers : (alias template) lazystack.writeText = sparkles.base.text.writers.writeText(Writer, Args...)(ref Writer w, InterpolationHeader, Args args, InterpolationFooter)Writes an interpolated sequence to an output range, verbatim.
SharedBuffer!(char, 128) buf;
buf.writeText(i"pid $(pid) exited with $(status)");
Plain, not styled. Literals are copied through and interpolated values go
via writeValue; nothing is parsed. That is the difference from
sparkles.base.styled_template.writeStyled, which reads {red …} as markup —
and the reason to reach for this one whenever the text is not a style template.
Interpolating a value that may contain a brace (a file path, a user's input)
through the styled writer silently eats it as a style block; here a brace is a
brace.
The @nogc half of the pair. std.conv.text already renders an
interpolated sequence to a string, so use that where a GC allocation is fine;
this is for the paths where it is not, and it inherits Writer's attributes the
way every template in this module does.
writeText;
version (BenchBench)
import (module) benchtextThe benchmark's frame text store, used by all three builders under
version (Bench): a bump arena with TextPool's intern/withText/release
surface. TextPool cannot be sized for a 100 000-row frame on a test worker's
512 KiB stack: its compact keeps a uint[slots] on the stack (2 MiB at 2^19
slots), and the frame is reserved on every intern that may compact.
benchtext : (alias template) lazystack.FrameBuf = benchtext.FrameBuf(T)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf;
else
private alias FrameBuf(T) = HeapBuffer!(T, Storage.unique);
// ── forced named arguments (docs/guidelines/idioms/forced-named-arguments) ──
/// The sentinel in front of every attribute list, and again in front of
/// `children`: a positional argument after the last named attribute would
/// otherwise fill `children` silently. With it, `children:` is required.
private struct (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly {}
// ── nodes, context, text, messages ─────────────────────────────────────────
/// A handle to a node this frame built. Children return it so a parent can
/// tell a child built *in* its slot from one built earlier (see `evalChild`).
struct (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node
{
uint (field) uint lazystack.Node.indexindex = uint.(constant) uint uint.max = 4294967295umax;
/// An empty child: its argument position still counts, so the siblings
/// after it keep their identity whether or not it is shown.
enum (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node (constant) lazystack.Node lazystack.Node.none = Node(4294967294u)An empty child: its argument position still counts, so the siblings
after it keep their identity whether or not it is shown.
none = (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node(uint.(constant) uint uint.max = 4294967295umax - 1);
bool bool lazystack.Node.isNone() const pure nothrow @nogc @safeisNone() const @safe pure nothrow @nogc => (field) uint lazystack.Node.indexindex == (constant) lazystack.Node lazystack.Node.none = Node(4294967294u)An empty child: its argument position still counts, so the siblings
after it keep their identity whether or not it is shown.
none.(field) uint lazystack.Node.indexindex;
}
/// What a child slot holds: a lazy, non-capturing-by-GC subtree builder.
/// `scope` at every use site is what keeps it off the GC (with the patch).
alias (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn = Node delegate() @safe pure nothrow @nogc;
enum (enum) lazystack.SlotSlot : ubyte { (enum value) lazystack.Slot.code = cast(ubyte)0ucode, (enum value) lazystack.Slot.heading = 1heading, (enum value) lazystack.Slot.dim = 2dim }
enum (enum) lazystack.DensityDensity : ubyte { (enum value) lazystack.Density.comfortable = cast(ubyte)0ucomfortable, (enum value) lazystack.Density.compact = 1compact }
enum (enum) lazystack.LayoutLayout : ubyte { (enum value) lazystack.Layout.wide = cast(ubyte)0uwide, (enum value) lazystack.Layout.touch = 1touch }
/// Context pushed by an element on open and popped on close. A child is
/// evaluated after its parent opens, so it reads the context directly.
struct (struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env
{
(enum) lazystack.LayoutLayout (field) lazystack.Layout lazystack.Env.layoutlayout;
(enum) lazystack.DensityDensity (field) lazystack.Density lazystack.Env.densitydensity;
bool (field) bool lazystack.Env.disableddisabled;
/// An override replacing `density` for a subtree.
(struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride lazystack.EnvOverride lazystack.Env.withDensity(lazystack.Density d) const pure nothrow @nogc @safeAn override replacing density for a subtree.
withDensity((enum) lazystack.DensityDensity (parameter) lazystack.Density dd) const @safe pure nothrow @nogc
=> (struct) lazystack.EnvOverrideditto
EnvOverride(active: true, env: (struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env(layout: (field) lazystack.Layout lazystack.Env.layoutlayout, density: (parameter) lazystack.Density dd, disabled: (field) bool lazystack.Env.disableddisabled));
}
/// ditto
struct (struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride
{
bool (field) bool lazystack.EnvOverride.activeactive;
(struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env (field) lazystack.Env lazystack.EnvOverride.envenv;
}
// Capacities: the demo's frame is tiny; the benchmark builds 100 000-row frames
// into a heap-owned `Ui`.
version (BenchBench)
{
private enum (constant) int lazystack.argBytes = 8388608argBytes = 8 << 20, (constant) int lazystack.maxDepth = 64maxDepth = 64;
}
else
{
private enum textSlots = 512, textBytes = 4096, argBytes = 4096, maxDepth = 64;
}
private struct (struct) lazystack.FrameTextFrameText {}
version (BenchBench)
{
import (module) benchtextThe benchmark's frame text store, used by all three builders under
version (Bench): a bump arena with TextPool's intern/withText/release
surface. TextPool cannot be sized for a 100 000-row frame on a test worker's
512 KiB stack: its compact keeps a uint[slots] on the stack (2 MiB at 2^19
slots), and the frame is reserved on every intern that may compact.
benchtext : (struct) benchtext.BumpTextPoolBumpTextPool;
// `TextPool` keeps a `uint[slots]` on the stack in `compact`: see `benchtext.d`.
private alias (alias) lazystack.FrameTextPool = benchtext.BumpTextPoolFrameTextPool = (struct) benchtext.BumpTextPoolBumpTextPool;
}
else
private alias FrameTextPool = TextPool!(FrameText, textSlots, textBytes);
alias (alias) lazystack.TextId = benchtext.BumpTextPool.IdTextId = (alias) lazystack.FrameTextPool = benchtext.BumpTextPoolFrameTextPool.(struct) benchtext.BumpTextPool.IdId;
/// An erased message: an index into the frame's message table.
struct (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef
{
uint (field) uint lazystack.MsgRef.indexindex = uint.(constant) uint uint.max = 4294967295umax;
bool bool lazystack.MsgRef.isSet() const pure nothrow @nogc @safeisSet() const @safe pure nothrow @nogc => (field) uint lazystack.MsgRef.indexindex != uint.(constant) uint uint.max = 4294967295umax;
}
private ulong ulong lazystack.fnv(scope const(char)[] s, ulong h = 14695981039346656037LU) pure nothrow @nogc @safefnv(scope const(char)[] (parameter) const(char)[] ss, ulong (parameter) ulong hh = 0xcbf29ce484222325) @safe pure nothrow @nogc
{
foreach ((parameter) const(char) cc; (parameter) const(char)[] ss)
{
(parameter) ulong hh ^= (local variable) const(char) cc;
(parameter) ulong hh *= 0x100000001b3;
}
return (parameter) ulong hh;
}
private ulong ulong lazystack.mix(ulong a, ulong b) pure nothrow @nogc @safemix(ulong (parameter) ulong aa, ulong (parameter) ulong bb) @safe pure nothrow @nogc
{
ulong (local variable) ulong hh = (parameter) ulong aa ^ ((parameter) ulong bb + 0x9e3779b97f4a7c15 + ((parameter) ulong aa << 6) + ((parameter) ulong aa >> 2));
(local variable) ulong hh ^= (local variable) ulong hh >> 31;
(local variable) ulong hh *= 0xbf58476d1ce4e5b9;
return (local variable) ulong hh ^ ((local variable) ulong hh >> 29);
}
/// A type's identity for the message check.
enum ulong (constant) ulong lazystack.typeKey(T) = fnv(T.mangleof)A type's identity for the message check.
typeKey(T) = fnv(T.mangleof);
private enum uint (constant) uint lazystack.none = 4294967295unone = uint.(constant) uint uint.max = 4294967295umax;
enum (enum) lazystack.KindKind : ubyte
{
(enum value) lazystack.Kind.column = cast(ubyte)0ucolumn, (enum value) lazystack.Kind.row = 1row, (enum value) lazystack.Kind.label = 2label, (enum value) lazystack.Kind.toggle = 3toggle, (enum value) lazystack.Kind.numberField = 4numberField, (enum value) lazystack.Kind.keyValue = 5keyValue, (enum value) lazystack.Kind.mapMsg = 6mapMsg, (enum value) lazystack.Kind.memo = 7memo
}
private alias (alias) lazystack.ApplyThunk = void function(scope const(void)* from, scope void* to) @systemApplyThunk = void function(scope const(void)* (parameter) const(void)* fromfrom, scope void* (parameter) void* toto) @system;
private struct (struct) lazystack.MapRecMapRec
{
ulong (field) ulong lazystack.MapRec.fromfrom, (field) ulong lazystack.MapRec.toto;
(alias) lazystack.ApplyThunk = void function(scope const(void)* from, scope void* to) @systemApplyThunk (field) void function(scope const(void)* from, scope void* to) @system lazystack.MapRec.applyapply;
(alias) object.string = stringstring (field) string lazystack.MapRec.fromNamefromName, (field) string lazystack.MapRec.toNametoName;
}
/// One element, written once when it opens (its size and children once more
/// when it closes). Children are listed, not linked: a closing element copies
/// its children's indices from the children stack into the `kids` table, as
/// Clay does, so no earlier record is ever updated.
struct (struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec
{
(enum) lazystack.KindKind (field) lazystack.Kind lazystack.NodeRec.kindkind;
uint (field) uint lazystack.NodeRec.parentparent = (constant) uint lazystack.none = 4294967295unone;
uint (field) uint lazystack.NodeRec.kidStartkidStart, (field) uint lazystack.NodeRec.childCountchildCount; // `kids[kidStart .. kidStart + childCount]`
// identity: id = mix(parent id, argument position [, key])
uint (field) uint lazystack.NodeRec.positionposition;
bool (field) bool lazystack.NodeRec.keyedkeyed;
ulong (field) ulong lazystack.NodeRec.keykey;
ulong (field) ulong lazystack.NodeRec.idid;
// content
(alias) lazystack.TextId = benchtext.BumpTextPool.IdTextId (field) benchtext.BumpTextPool.Id lazystack.NodeRec.texttext, (field) benchtext.BumpTextPool.Id lazystack.NodeRec.text2text2;
(struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef (field) lazystack.MsgRef lazystack.NodeRec.msgmsg;
(enum) lazystack.SlotSlot (field) lazystack.Slot lazystack.NodeRec.slotslot;
int (field) int lazystack.NodeRec.gapgap, (field) int lazystack.NodeRec.valuevalue;
bool (field) bool lazystack.NodeRec.onon;
(struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env (field) lazystack.Env lazystack.NodeRec.envenv; // the env this element's children see
(struct) lazystack.MapRecMapRec (field) lazystack.MapRec lazystack.NodeRec.mapmap; // `mapMsg`
ulong (field) ulong lazystack.NodeRec.memoKeymemoKey; // `memo`: hash of the arguments and the env
// intrinsic (fit) size, computed at close
uint (field) uint lazystack.NodeRec.ww, (field) uint lazystack.NodeRec.hh;
// position, from `place`
int (field) int lazystack.NodeRec.xx, (field) int lazystack.NodeRec.yy;
}
private struct (struct) lazystack.MsgRecMsgRec
{
ulong (field) ulong lazystack.MsgRec.typeKeytypeKey;
const(void)[] (field) const(void)[] lazystack.MsgRec.valuevalue;
(alias) lazystack.ApplyThunk = void function(scope const(void)* from, scope void* to) @systemApplyThunk (field) void function(scope const(void)* from, scope void* to) @system lazystack.MsgRec.payloadpayload;
ulong (field) ulong lazystack.MsgRec.payloadKeypayloadKey;
}
/// What a debug build reports instead of guessing.
enum (enum) lazystack.DiagKindWhat a debug build reports instead of guessing.
DiagKind : ubyte
{
/// A node opened while the slot it sits in already held one: something
/// was built *outside* a children slot (`auto x = ui.label(…)` in a view
/// body) and took the slot meant for this node.
(enum value) lazystack.DiagKind.slotAlreadyTaken = cast(ubyte)0uA node opened while the slot it sits in already held one: something
was built outside a children slot (auto x = ui.label(…) in a view
body) and took the slot meant for this node.
slotAlreadyTaken,
/// A child slot returned a node built before the slot was evaluated: the
/// node was built eagerly, under whatever was open then, not here.
(enum value) lazystack.DiagKind.childBuiltOutsideSlot = 1A child slot returned a node built before the slot was evaluated: the
node was built eagerly, under whatever was open then, not here.
childBuiltOutsideSlot,
/// `ui.on` sent a message of another type than the innermost `mapMsg`
/// (or the app) expects.
(enum value) lazystack.DiagKind.messageTypeMismatch = 2ui.on sent a message of another type than the innermost mapMsg
(or the app) expects.
messageTypeMismatch,
/// A `mapMsg` lifts into another type than its own scope expects.
(enum value) lazystack.DiagKind.mapMsgTargetMismatch = 3A mapMsg lifts into another type than its own scope expects.
mapMsgTargetMismatch,
}
private struct (struct) lazystack.DiagDiag
{
(enum) lazystack.DiagKindWhat a debug build reports instead of guessing.
DiagKind (field) lazystack.DiagKind lazystack.Diag.kindkind;
uint (field) uint lazystack.Diag.nodenode; // the node it is about
uint (field) uint lazystack.Diag.otherother = (constant) uint lazystack.none = 4294967295unone; // `slotAlreadyTaken`: the node that took the slot
(alias) object.string = stringstring (field) string lazystack.Diag.gotgot, (field) string lazystack.Diag.expectedexpected;
uint (field) uint lazystack.Diag.positionposition; // `childBuiltOutsideSlot`: the argument position
}
/// An open element: where its children start on the children stack, and its
/// id, kept here so a child's id never reads its parent's record.
private struct (struct) lazystack.OpenRecAn open element: where its children start on the children stack, and its
id, kept here so a child's id never reads its parent's record.
OpenRec
{
uint (field) uint lazystack.OpenRec.nodenode;
uint (field) uint lazystack.OpenRec.pendingBasependingBase;
ulong (field) ulong lazystack.OpenRec.idid;
}
/// A closed element waiting for its parent to close: its index and fit size,
/// kept together so the parent's fit reads one contiguous run.
private struct (struct) lazystack.PendingA closed element waiting for its parent to close: its index and fit size,
kept together so the parent's fit reads one contiguous run.
Pending
{
uint (field) uint lazystack.Pending.nodenode;
uint (field) uint lazystack.Pending.ww, (field) uint lazystack.Pending.hh;
}
/**
The frame's builder, on its owner's stack (or heap-owned for big frames) and
passed `ref`. Storage as in the inside-out sketch: append-only `HeapBuffer`s
for nodes and messages, a `TextPool` for text, an `InlineBuffer` scratch for
`ui.text`, and an `InSituRegion` for constant messages' bytes.
*/
struct (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui
{
private (alias) benchtext.FrameBuf!(lazystack.NodeRec) = sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf!(struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes;
private (alias) benchtext.FrameBuf!(lazystack.MsgRec) = sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf!(struct) lazystack.MsgRecMsgRec (field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.msgsmsgs;
private (alias) benchtext.FrameBuf!(lazystack.Diag) = sparkles.base.buffer.Buffer!(Diag, 0LU, cast(Storage)cast(ubyte)6u)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf!(struct) lazystack.DiagDiag (field) sparkles.base.buffer.Buffer!(Diag, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.diagsdiags;
private (alias) lazystack.FrameTextPool = benchtext.BumpTextPoolFrameTextPool (field) benchtext.BumpTextPool lazystack.Ui.textstexts;
private (alias) sparkles.base.buffer.InlineBuffer!(char, 1024LU, Storage.none) = sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline)A buffer that never allocates: the elements live in the inline T[N] and
nowhere else.
The policy with a guarantee no other has. Because there is no union, a slice of
the storage is provably a reference to the enclosing frame, so -dip1000
rejects returning one from a @safe function — the property CString is built
on. It also has no destructor, so it is plain data: copyable, comparable, and
usable as a field in an aggregate that must stay POD.
It is deliberately not an output range: put promises to accept what it is
given, and this cannot. Write into it with tryWrite.
Pass Storage.unique as extra for the move-only form, which is what prevents
an accidental copy of a large one.
InlineBuffer!(char, 1024) (field) sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline) lazystack.Ui.scratchscratch;
private (constant) int lazystack.argBytes = 8388608InSituRegion!(constant) int lazystack.argBytes = 8388608argBytes (field) std.experimental.allocator.building_blocks.region.InSituRegion!(8388608LU, 16LU) lazystack.Ui.argArenaargArena;
private (struct) lazystack.OpenRecAn open element: where its children start on the children stack, and its
id, kept here so a child's id never reads its parent's record.
OpenRec[(constant) int lazystack.maxDepth = 64maxDepth] (field) lazystack.OpenRec[64] lazystack.Ui.stackstack; // the open elements, innermost last
private uint (field) uint lazystack.Ui.depthdepth;
private (alias) benchtext.FrameBuf!(lazystack.Pending) = sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf!(struct) lazystack.PendingA closed element waiting for its parent to close: its index and fit size,
kept together so the parent's fit reads one contiguous run.
Pending (field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending; // closed children of the open elements, in order
private (alias) benchtext.FrameBuf!uint = sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u)The frame tables' buffer in the benchmark. By default the sparkles:base
HeapBuffer!(T, Storage.unique) the prototypes use; under version (RawBuf) a
bare malloc'd array. The mutable Buffer.opIndex/opSlice call
ensureUniqueStorage (not inlined, computing roundedCapacity) on every
access even for Storage.unique, and the top-down builders index their node
table far more than the inside-out one does; RawBuf takes that cost out of
all three, leaving the builders' own work.
FrameBuf!uint (field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids; // every element's children, contiguous per parent
private (struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv;
private ulong (field) ulong lazystack.Ui.msgKeymsgKey; // the message type the innermost `mapMsg` expects
private (alias) object.string = stringstring (field) string lazystack.Ui.msgNamemsgName;
private ulong (field) ulong lazystack.Ui.appMsgKeyappMsgKey;
private (alias) object.string = stringstring (field) string lazystack.Ui.appMsgNameappMsgName;
// what the slot being evaluated gives the node that opens in it
private uint (field) uint lazystack.Ui.nextPosnextPos;
private bool (field) bool lazystack.Ui.nextKeyednextKeyed;
private ulong (field) ulong lazystack.Ui.nextKeynextKey;
private bool (field) bool lazystack.Ui.armedarmed; // debug: the slot is still free
private uint (field) uint lazystack.Ui.slotOwnerslotOwner = (constant) uint lazystack.none = 4294967295unone; // debug: the node that took it
@disable this(this);
/// Structural context, as resolved by the elements open around the caller.
(struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env lazystack.Env lazystack.Ui.env() const pure nothrow @nogc @safeStructural context, as resolved by the elements open around the caller.
env() const @safe pure nothrow @nogc => (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv;
/// The app's message type (`runApp!(view, update, Msg)` in the real host).
void void expectMsg(Msg)()The app's message type (runApp!(view, update, Msg) in the real host).
expectMsg(Msg)()
{
appMsgKey = (template instance) typeKey!MsgtypeKey!Msg;
appMsgName = Msg.stringof;
}
/// Formats an IES into the frame's scratch (UI-Q2.1).
const(char)[] const(char)[] text(Args...)(InterpolationHeader header, Args args, InterpolationFooter footer) returnFormats an IES into the frame's scratch (UI-Q2.1).
text(Args...)((unresolved type) InterpolationHeaderInterpolationHeader (parameter) InterpolationHeader headerheader, Args (parameter) Args argsargs,
(unresolved type) InterpolationFooterInterpolationFooter (parameter) InterpolationFooter footerfooter) return
{
const _error_ startstart = scratch.scratch.lengthlength;
const _error_ fitsfits = scratch.tryWrite((scope ref BoundedSink!char (parameter) BoundedSink!char ww) {
w.w.writeTextwriteText(header, args, footer);
});
assert(fits, "the frame's text scratch is full");
return scratch[start .. scratch.length];
}
// ── the frame ──────────────────────────────────────────────────────────
/// Builds the root view under `env`: the view is a lazy child, so `env`
/// and the app's message type are in place before it runs.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.Ui.frame(lazystack.Env env, lazystack.Node delegate() pure nothrow @nogc @safe[] root...) pure nothrow @nogc @safeBuilds the root view under env: the view is a lazy child, so env
and the app's message type are in place before it runs.
frame((struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env (parameter) lazystack.Env envenv, scope (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn[] (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] rootroot...) @safe pure nothrow @nogc
{
assert((parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] rootroot.(field) ulong lazystack.Node delegate() pure nothrow @nogc @safe[].lengthlength == 1, "a frame has one root view");
(field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv = (parameter) lazystack.Env envenv;
(field) ulong lazystack.Ui.msgKeymsgKey = (field) ulong lazystack.Ui.appMsgKeyappMsgKey;
(field) string lazystack.Ui.msgNamemsgName = (field) string lazystack.Ui.appMsgNameappMsgName;
return lazystack.Node lazystack.Ui.evalChild(uint pos, scope lazystack.Node delegate() pure nothrow @nogc @safe child) pure nothrow @nogc @safeEvaluates one child slot: the node that opens in it gets argument
position pos. A debug build checks the slot is used exactly as meant.
evalChild(0, (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] rootroot[0]);
}
/// Drops the frame's nodes, texts and messages, keeping the storage.
void void lazystack.Ui.reset() pure nothrow @nogc @safeDrops the frame's nodes, texts and messages, keeping the storage.
reset() @safe pure nothrow @nogc
{
foreach (ref (parameter) lazystack.NodeRec rr; (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[])
{
if ((local variable) lazystack.NodeRec rr.(field) benchtext.BumpTextPool.Id lazystack.NodeRec.texttext != (struct) benchtext.BumpTextPool.IdTextId.(constant) benchtext.BumpTextPool.Id benchtext.BumpTextPool.Id.init = Id(4294967295u, 0u)init)
cast(void) (field) benchtext.BumpTextPool lazystack.Ui.textstexts.bool benchtext.BumpTextPool.release(in benchtext.BumpTextPool.Id) pure nothrow @nogc @saferelease((local variable) lazystack.NodeRec rr.(field) benchtext.BumpTextPool.Id lazystack.NodeRec.texttext);
if ((local variable) lazystack.NodeRec rr.(field) benchtext.BumpTextPool.Id lazystack.NodeRec.text2text2 != (struct) benchtext.BumpTextPool.IdTextId.(constant) benchtext.BumpTextPool.Id benchtext.BumpTextPool.Id.init = Id(4294967295u, 0u)init)
cast(void) (field) benchtext.BumpTextPool lazystack.Ui.textstexts.bool benchtext.BumpTextPool.release(in benchtext.BumpTextPool.Id) pure nothrow @nogc @saferelease((local variable) lazystack.NodeRec rr.(field) benchtext.BumpTextPool.Id lazystack.NodeRec.text2text2);
}
static if (__traits(hasMember, texts, "clearAll"))
(field) benchtext.BumpTextPool lazystack.Ui.textstexts.void benchtext.BumpTextPool.clearAll() pure nothrow @nogc @safeclearAll();
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.void sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).clear(bool releaseStorage = true) pure nothrow @nogc scope @safeRemoves all elements (BUF15).
``releaseStorage: true — the default, and what a buffer whose work is
finished wants — also gives the heap block back, reverting an inline
policy to its inline slots. Pass false to keep the block: a builder
reused across iterations then allocates once and refills, which is
the whole point of having reserved it.
A policy without Storage.inline has nothing to revert to, so its
block survives either way and only the destructor releases it.
Output range interface: appends a single element.
clear(releaseStorage: false);
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.msgsmsgs.void sparkles.base.buffer.Buffer!(lazystack.MsgRec, 0LU, cast(Storage)cast(ubyte)6u).clear(bool releaseStorage = true) pure nothrow @nogc scope @safeRemoves all elements (BUF15).
``releaseStorage: true — the default, and what a buffer whose work is
finished wants — also gives the heap block back, reverting an inline
policy to its inline slots. Pass false to keep the block: a builder
reused across iterations then allocates once and refills, which is
the whole point of having reserved it.
A policy without Storage.inline has nothing to revert to, so its
block survives either way and only the destructor releases it.
Output range interface: appends a single element.
clear(releaseStorage: false);
(field) sparkles.base.buffer.Buffer!(Diag, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.diagsdiags.void sparkles.base.buffer.Buffer!(lazystack.Diag, 0LU, cast(Storage)cast(ubyte)6u).clear(bool releaseStorage = true) pure nothrow @nogc scope @safeRemoves all elements (BUF15).
``releaseStorage: true — the default, and what a buffer whose work is
finished wants — also gives the heap block back, reverting an inline
policy to its inline slots. Pass false to keep the block: a builder
reused across iterations then allocates once and refills, which is
the whole point of having reserved it.
A policy without Storage.inline has nothing to revert to, so its
block survives either way and only the destructor releases it.
Output range interface: appends a single element.
clear(releaseStorage: false);
(field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending.void sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).clear(bool releaseStorage = true) pure nothrow @nogc scope @safeRemoves all elements (BUF15).
``releaseStorage: true — the default, and what a buffer whose work is
finished wants — also gives the heap block back, reverting an inline
policy to its inline slots. Pass false to keep the block: a builder
reused across iterations then allocates once and refills, which is
the whole point of having reserved it.
A policy without Storage.inline has nothing to revert to, so its
block survives either way and only the destructor releases it.
Output range interface: appends a single element.
clear(releaseStorage: false);
(field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids.void sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u).clear(bool releaseStorage = true) pure nothrow @nogc scope @safeRemoves all elements (BUF15).
``releaseStorage: true — the default, and what a buffer whose work is
finished wants — also gives the heap block back, reverting an inline
policy to its inline slots. Pass false to keep the block: a builder
reused across iterations then allocates once and refills, which is
the whole point of having reserved it.
A policy without Storage.inline has nothing to revert to, so its
block survives either way and only the destructor releases it.
Output range interface: appends a single element.
clear(releaseStorage: false);
(field) sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline) lazystack.Ui.scratchscratch.void sparkles.base.buffer.Buffer!(char, 1024LU, Storage.inline).clear() pure nothrow @nogc @safeRemoves all elements.
There is no storage to release — N is the whole capacity — so this
is the length reset alone. It is what makes a fixed buffer
rewritable: clear then Buffer.tryWrite builds a new value
in pieces, where Buffer.assign takes one already assembled.
clear();
() @trusted { (field) std.experimental.allocator.building_blocks.region.InSituRegion!(8388608LU, 16LU) lazystack.Ui.argArenaargArena.bool std.experimental.allocator.building_blocks.region.InSituRegion!(8388608LU, 16LU).deallocateAll() pure nothrow @nogc @safeDeallocates all memory allocated with this allocator.
deallocateAll(); }();
(field) uint lazystack.Ui.depthdepth = 0;
}
/// The number of nodes the frame built.
(alias) object.size_t = ulongsize_t ulong lazystack.Ui.nodeCount() const pure nothrow @nogc @safeThe number of nodes the frame built.
nodeCount() const @safe pure nothrow @nogc => (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length;
// ── building ───────────────────────────────────────────────────────────
private (alias) lazystack.TextId = benchtext.BumpTextPool.IdTextId benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern(scope const(char)[] (parameter) const(char)[] ss) @safe pure nothrow @nogc
=> (parameter) const(char)[] ss.(field) ulong const(char)[].lengthlength ? (field) benchtext.BumpTextPool lazystack.Ui.textstexts.benchtext.BumpTextPool.Result benchtext.BumpTextPool.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] ss).(field) benchtext.BumpTextPool.Id benchtext.BumpTextPool.Result.valuevalue : (struct) benchtext.BumpTextPool.IdTextId.(constant) benchtext.BumpTextPool.Id benchtext.BumpTextPool.Id.init = Id(4294967295u, 0u)init;
private uint uint lazystack.Ui.top() const pure nothrow @nogc @safetop() const @safe pure nothrow @nogc => (field) uint lazystack.Ui.depthdepth ? (field) lazystack.OpenRec[64] lazystack.Ui.stackstack[(field) uint lazystack.Ui.depthdepth - 1].(field) uint lazystack.OpenRec.nodenode : (constant) uint lazystack.none = 4294967295unone;
/// Evaluates one child slot: the node that opens in it gets argument
/// position `pos`. A debug build checks the slot is used exactly as meant.
private (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.Ui.evalChild(uint pos, scope lazystack.Node delegate() pure nothrow @nogc @safe child) pure nothrow @nogc @safeEvaluates one child slot: the node that opens in it gets argument
position pos. A debug build checks the slot is used exactly as meant.
evalChild(uint (parameter) uint pospos, scope (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn (parameter) lazystack.Node delegate() pure nothrow @nogc @safe childchild) @safe pure nothrow @nogc
{
const (local variable) const(uint) beforebefore = cast(uint) (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length;
(field) uint lazystack.Ui.nextPosnextPos = (parameter) uint pospos;
debug
{
armed = true;
slotOwner = none;
}
const (local variable) const(lazystack.Node) rr = (parameter) lazystack.Node delegate() pure nothrow @nogc @safe childchild();
debug
{
armed = false;
if (!r.isNone && r.index < before)
diags ~= Diag(DiagKind.childBuiltOutsideSlot, r.index, top, position: pos);
}
return (local variable) const(lazystack.Node) rr;
}
/// Fills in what the slot and the open elements give `rec`, appends it
/// and returns its index. No other record is touched.
pragma(inline, true)
private uint uint lazystack.Ui.append(ref lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, out ulong id) pure nothrow @nogc @safeFills in what the slot and the open elements give rec, appends it
and returns its index. No other record is touched.
append(ref (struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec (parameter) lazystack.NodeRec recrec, (struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride (parameter) lazystack.EnvOverride overover, bool (parameter) bool disableddisabled, out ulong (parameter) ulong idid) @safe pure nothrow @nogc
{
const (local variable) const(uint) selfself = cast(uint) (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length;
debug
{
if (!armed)
diags ~= Diag(DiagKind.slotAlreadyTaken, self, slotOwner);
armed = false;
slotOwner = self;
}
(parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.positionposition = (field) uint lazystack.Ui.nextPosnextPos;
(parameter) lazystack.NodeRec recrec.(field) bool lazystack.NodeRec.keyedkeyed = (field) bool lazystack.Ui.nextKeyednextKeyed;
(parameter) lazystack.NodeRec recrec.(field) ulong lazystack.NodeRec.keykey = (field) ulong lazystack.Ui.nextKeynextKey;
(parameter) lazystack.NodeRec recrec.(field) lazystack.Env lazystack.NodeRec.envenv = (parameter) lazystack.EnvOverride overover.(field) bool lazystack.EnvOverride.activeactive ? (parameter) lazystack.EnvOverride overover.(field) lazystack.Env lazystack.EnvOverride.envenv : (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv;
(parameter) lazystack.NodeRec recrec.(field) lazystack.Env lazystack.NodeRec.envenv.(field) bool lazystack.Env.disableddisabled = (parameter) lazystack.NodeRec recrec.(field) lazystack.Env lazystack.NodeRec.envenv.(field) bool lazystack.Env.disableddisabled || (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv.(field) bool lazystack.Env.disableddisabled || (parameter) bool disableddisabled;
ulong (local variable) ulong parentIdparentId;
if ((field) uint lazystack.Ui.depthdepth)
{
(parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.parentparent = (field) lazystack.OpenRec[64] lazystack.Ui.stackstack[(field) uint lazystack.Ui.depthdepth - 1].(field) uint lazystack.OpenRec.nodenode;
(local variable) ulong parentIdparentId = (field) lazystack.OpenRec[64] lazystack.Ui.stackstack[(field) uint lazystack.Ui.depthdepth - 1].(field) ulong lazystack.OpenRec.idid;
}
(parameter) ulong idid = (parameter) lazystack.NodeRec recrec.(field) bool lazystack.NodeRec.keyedkeyed ? ulong lazystack.mix(ulong a, ulong b) pure nothrow @nogc @safemix(ulong lazystack.mix(ulong a, ulong b) pure nothrow @nogc @safemix((local variable) ulong parentIdparentId, (parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.positionposition), (parameter) lazystack.NodeRec recrec.(field) ulong lazystack.NodeRec.keykey | 1)
: ulong lazystack.mix(ulong a, ulong b) pure nothrow @nogc @safemix((local variable) ulong parentIdparentId, (parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.positionposition);
(parameter) lazystack.NodeRec recrec.(field) ulong lazystack.NodeRec.idid = (parameter) ulong idid;
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes ~= void sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(lazystack.NodeRec element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
rec;
return (local variable) const(uint) selfself;
}
/// Opens an element: appended, pushed on the open stack.
pragma(inline, true)
private uint uint lazystack.Ui.open(lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled) pure nothrow @nogc @safeOpens an element: appended, pushed on the open stack.
open((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec (parameter) lazystack.NodeRec recrec, (struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride (parameter) lazystack.EnvOverride overover, bool (parameter) bool disableddisabled) @safe pure nothrow @nogc
{
ulong (local variable) ulong idid;
const (local variable) const(uint) selfself = uint lazystack.Ui.append(ref lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, out ulong id) pure nothrow @nogc @safeFills in what the slot and the open elements give rec, appends it
and returns its index. No other record is touched.
append((parameter) lazystack.NodeRec recrec, (parameter) lazystack.EnvOverride overover, (parameter) bool disableddisabled, (local variable) ulong idid);
assert((field) uint lazystack.Ui.depthdepth < (field) lazystack.OpenRec[64] lazystack.Ui.stackstack.(constant) ulong lazystack.OpenRec[64].length = 64LUlength, "elements nest too deep");
(field) lazystack.OpenRec[64] lazystack.Ui.stackstack[(field) uint lazystack.Ui.depthdepth++] = (struct) lazystack.OpenRecAn open element: where its children start on the children stack, and its
id, kept here so a child's id never reads its parent's record.
OpenRec((local variable) const(uint) selfself, cast(uint) (field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending.ulong sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length, (local variable) ulong idid);
(field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv = (parameter) lazystack.NodeRec recrec.(field) lazystack.Env lazystack.NodeRec.envenv;
return (local variable) const(uint) selfself;
}
/// Closes the innermost element: its fit size from its children's run on
/// the children stack, which moves into `kids`; then it joins its own
/// parent's run, and the context it pushed pops.
pragma(inline, true)
private void void lazystack.Ui.close(lazystack.Env saved) pure nothrow @nogc @safeCloses the innermost element: its fit size from its children's run on
the children stack, which moves into kids; then it joins its own
parent's run, and the context it pushed pops.
close((struct) lazystack.EnvContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
Env (parameter) lazystack.Env savedsaved) @safe pure nothrow @nogc
{
const (local variable) const(lazystack.OpenRec) oo = (field) lazystack.OpenRec[64] lazystack.Ui.stackstack[--(field) uint lazystack.Ui.depthdepth];
const (local variable) const(lazystack.Pending[]) runrun = (field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending[(local variable) const(lazystack.OpenRec) oo.(field) uint lazystack.OpenRec.pendingBasependingBase .. (field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending.ulong sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length];
ref (local variable) lazystack.NodeRec recrec = (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(local variable) const(lazystack.OpenRec) oo.(field) uint lazystack.OpenRec.nodenode];
uint (local variable) uint ww, (local variable) uint hh;
if ((local variable) const(lazystack.Pending[]) runrun.(field) ulong const(lazystack.Pending[]).lengthlength)
{
const (local variable) const(bool) horizontalhorizontal = (local variable) lazystack.NodeRec recrec.(field) lazystack.Kind lazystack.NodeRec.kindkind == (enum) lazystack.KindKind.(enum value) lazystack.Kind.row = 1row;
uint (local variable) uint alongalong, (local variable) uint acrossacross;
const (local variable) const(uint) kidStartkidStart = cast(uint) (field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids.ulong sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length;
foreach (ref (parameter) const(lazystack.Pending) cc; (local variable) const(lazystack.Pending[]) runrun)
{
(local variable) uint alongalong += (local variable) const(bool) horizontalhorizontal ? (local variable) const(lazystack.Pending) cc.(field) uint lazystack.Pending.ww : (local variable) const(lazystack.Pending) cc.(field) uint lazystack.Pending.hh;
const (local variable) const(uint) aa = (local variable) const(bool) horizontalhorizontal ? (local variable) const(lazystack.Pending) cc.(field) uint lazystack.Pending.hh : (local variable) const(lazystack.Pending) cc.(field) uint lazystack.Pending.ww;
if ((local variable) const(uint) aa > (local variable) uint acrossacross)
(local variable) uint acrossacross = (local variable) const(uint) aa;
(field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids ~= void sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(uint element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
c.void sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(uint element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
node;
}
(local variable) uint alongalong += (local variable) lazystack.NodeRec recrec.(field) int lazystack.NodeRec.gapgap * cast(uint) ((local variable) const(lazystack.Pending[]) runrun.(field) ulong const(lazystack.Pending[]).lengthlength - 1);
(local variable) uint ww = (local variable) const(bool) horizontalhorizontal ? (local variable) uint alongalong : (local variable) uint acrossacross;
(local variable) uint hh = (local variable) const(bool) horizontalhorizontal ? (local variable) uint acrossacross : (local variable) uint alongalong;
(local variable) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.kidStartkidStart = (local variable) const(uint) kidStartkidStart;
(local variable) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.childCountchildCount = cast(uint) (local variable) const(lazystack.Pending[]) runrun.(field) ulong const(lazystack.Pending[]).lengthlength;
(local variable) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.ww = (local variable) uint ww;
(local variable) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.hh = (local variable) uint hh;
}
(field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending.void sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).length(ulong newLength) pure nothrow @nogc @property @trustedSets the element count. Growing appends T.init-filled elements (one
storage growth); shrinking drops elements from the back and keeps the
storage, whichever it is (BUF13) — a buffer that has spilled to the
heap stays there until clear or the destructor, so a shrink costs
neither a copy back into the inline slots nor a free.
Output range interface: appends a single element.
length = (local variable) const(lazystack.OpenRec) oo.(field) uint lazystack.OpenRec.pendingBasependingBase;
(field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending ~= void sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(lazystack.Pending element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
Pending((local variable) const(lazystack.OpenRec) oo.(field) uint lazystack.OpenRec.nodenode, (local variable) uint ww, (local variable) uint hh);
(field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv = (parameter) lazystack.Env savedsaved;
}
/// A container: open, evaluate each child slot in order, close.
private (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.Ui.container(lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, scope lazystack.Node delegate() pure nothrow @nogc @safe[] children) pure nothrow @nogc @safeA container: open, evaluate each child slot in order, close.
container((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec (parameter) lazystack.NodeRec recrec, (struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride (parameter) lazystack.EnvOverride overover, bool (parameter) bool disableddisabled,
scope (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn[] (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren) @safe pure nothrow @nogc
{
const (local variable) const(lazystack.Env) savedsaved = (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv;
const (local variable) const(uint) selfself = uint lazystack.Ui.open(lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled) pure nothrow @nogc @safeOpens an element: appended, pushed on the open stack.
open((parameter) lazystack.NodeRec recrec, (parameter) lazystack.EnvOverride overover, (parameter) bool disableddisabled);
foreach ((parameter) ulong ii, (parameter) lazystack.Node delegate() pure nothrow @nogc @safe childchild; (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren)
cast(void) lazystack.Node lazystack.Ui.evalChild(uint pos, scope lazystack.Node delegate() pure nothrow @nogc @safe child) pure nothrow @nogc @safeEvaluates one child slot: the node that opens in it gets argument
position pos. A debug build checks the slot is used exactly as meant.
evalChild(cast(uint) (local variable) ulong ii, (local variable) lazystack.Node delegate() pure nothrow @nogc @safe childchild);
void lazystack.Ui.close(lazystack.Env saved) pure nothrow @nogc @safeCloses the innermost element: its fit size from its children's run on
the children stack, which moves into kids; then it joins its own
parent's run, and the context it pushed pops.
close((local variable) const(lazystack.Env) savedsaved);
return (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node((local variable) const(uint) selfself);
}
/// A leaf: open and close at once, with its own content size.
pragma(inline, true)
private (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.Ui.leaf(lazystack.NodeRec rec, uint w) pure nothrow @nogc @safeA leaf: open and close at once, with its own content size.
leaf((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec (parameter) lazystack.NodeRec recrec, uint (parameter) uint ww) @safe pure nothrow @nogc
{
const (local variable) const(lazystack.Env) savedsaved = (field) lazystack.Env lazystack.Ui.currentEnvcurrentEnv;
(parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.ww = (parameter) uint ww;
(parameter) lazystack.NodeRec recrec.(field) uint lazystack.NodeRec.hh = 1;
ulong (local variable) ulong idid;
const (local variable) const(uint) selfself = uint lazystack.Ui.append(ref lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, out ulong id) pure nothrow @nogc @safeFills in what the slot and the open elements give rec, appends it
and returns its index. No other record is touched.
append((parameter) lazystack.NodeRec recrec, (struct) lazystack.EnvOverrideditto
EnvOverride.(constant) lazystack.EnvOverride lazystack.EnvOverride.init = EnvOverride(false, Env(Layout.wide, Density.comfortable, false))init, false, (local variable) ulong idid);
(field) sparkles.base.buffer.Buffer!(Pending, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.pendingpending ~= void sparkles.base.buffer.Buffer!(lazystack.Pending, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(lazystack.Pending element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
Pending((local variable) const(uint) selfself, (parameter) uint ww, 1);
return (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node((local variable) const(uint) selfself);
}
private (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef lazystack.MsgRef lazystack.Ui.addMsg(lazystack.MsgRec rec) pure nothrow @nogc @safeaddMsg((struct) lazystack.MsgRecMsgRec (parameter) lazystack.MsgRec recrec) @safe pure nothrow @nogc
{
const (local variable) const(lazystack.MsgRef) selfself = (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef(cast(uint) (field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.msgsmsgs.ulong sparkles.base.buffer.Buffer!(lazystack.MsgRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length);
(field) sparkles.base.buffer.Buffer!(MsgRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.msgsmsgs ~= void sparkles.base.buffer.Buffer!(lazystack.MsgRec, 0LU, cast(Storage)cast(ubyte)6u).opOpAssign!"~"(lazystack.MsgRec element) pure nothrow @nogc scope @safeAppends a single element using ~= operator.
Output range interface: appends a single element.
rec;
return (local variable) const(lazystack.MsgRef) selfself;
}
/// Checks, at `ui.on` time, that `got` is what the open `mapMsg` scope
/// (or the app) expects. Run time only: the enclosing scope is a runtime
/// fact of the call stack, not a type the `ui` carries.
private void void lazystack.Ui.checkMsg(ulong got, string gotName) pure nothrow @nogc @safeChecks, at ui.on time, that got is what the open mapMsg scope
(or the app) expects. Run time only: the enclosing scope is a runtime
fact of the call stack, not a type the ui carries.
checkMsg(ulong (parameter) ulong gotgot, (alias) object.string = stringstring (parameter) string gotNamegotName) @safe pure nothrow @nogc
{
debug if (got != msgKey)
diags ~= Diag(DiagKind.messageTypeMismatch, top, got: gotName, expected: msgName);
}
private const(void)[] const(void)[] keep(T)(ref scope const T value)keep(T)(scope ref const T (parameter) T valuevalue)
{
const _error_ blockblock = () @trusted {
auto _error_ bb = argArena.allocate(T.sizeof);
if (b !is null)
b[] = (cast(const(void)*) &value)[0 .. T.sizeof];
return b;
}();
assert(block !is null, "the frame's argument arena is full");
return block;
}
// ── after the frame: find, dump, diagnostics, dispatch ─────────────────
private bool bool lazystack.Ui.textIs(uint n, scope const(char)[] text) pure nothrow @nogc @safetextIs(uint (parameter) uint nn, scope const(char)[] (parameter) const(char)[] texttext) @safe pure nothrow @nogc
{
bool (local variable) bool samesame = (parameter) const(char)[] texttext.(field) ulong const(char)[].lengthlength == 0;
(field) benchtext.BumpTextPool lazystack.Ui.textstexts.bool benchtext.BumpTextPool.withText!(void delegate(scope const(char)[]) pure nothrow @nogc @safe)(in benchtext.BumpTextPool.Id id, scope void delegate(scope const(char)[]) pure nothrow @nogc @safe fn) pure nothrow @nogc @safewithText((field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(parameter) uint nn].(field) benchtext.BumpTextPool.Id lazystack.NodeRec.texttext, (scope const(char)[] (parameter) const(char)[] heldheld) { (local variable) bool samesame = (parameter) const(char)[] heldheld == (parameter) const(char)[] texttext; });
return (local variable) bool samesame;
}
/// The first node of `kind` whose text is `text` (the demo's hit test).
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.Ui.find(string kind, scope const(char)[] text, uint from = 0u) pure nothrow @nogc @safeThe first node of kind whose text is text (the demo's hit test).
find((alias) object.string = stringstring (parameter) string kindkind, scope const(char)[] (parameter) const(char)[] texttext, uint (parameter) uint fromfrom = 0) @safe pure nothrow @nogc
{
foreach ((local variable) uint ii; (parameter) uint fromfrom .. cast(uint) (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length)
if ((field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(local variable) uint ii].(field) lazystack.Kind lazystack.NodeRec.kindkind.string sparkles.base.text.enums.enumMemberName!(CaseStyle.original, lazystack.Kind)(in lazystack.Kind value) pure nothrow @nogc @safeThe name of the declared member equal to value, recased per style as a
compile-time string literal (so the call allocates nothing).
value must be a declared member of E. The generated final switch rejects a
duplicate-valued enum at compile time (duplicate case labels) and asserts on a
value that is not a declared member.
enumMemberName == (parameter) string kindkind && bool lazystack.Ui.textIs(uint n, scope const(char)[] text) pure nothrow @nogc @safetextIs((local variable) uint ii, (parameter) const(char)[] texttext))
return (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node((local variable) uint ii);
return (struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node.(constant) lazystack.Node lazystack.Node.init = Node(4294967295u)init;
}
/// Writes every root (normally one) and its subtree, indented: kind,
/// text, fit size, id prefix, `key`, the env children see, `[msg]`.
void void dump(W)(scope W write)Writes every root (normally one) and its subtree, indented: kind,
text, fit size, id prefix, key, the env children see, [msg].
dump(W)(scope W (parameter) W writewrite)
{
foreach ((parameter) ii; 0 .. cast(uint) nodes.nodes.lengthlength)
if (nodes[i].nodes[i].parentparent == none)
dumpFrom(write, i, 0);
}
private void void dumpFrom(W)(scope W write, uint n, uint depth)dumpFrom(W)(scope W (parameter) W writewrite, uint (parameter) uint nn, uint (parameter) uint depthdepth)
{
const _error_ rr = nodes[n];
UniqueBuffer!(char, 160) _error_ lineline;
line.line.writeTextwriteText(i"$(r.kind.enumMemberName)");
texts.texts.withTextwithText(r.r.texttext, (scope const(char)[] (parameter) const(char)[] texttext) { line.line.writeTextwriteText(i` "$(text)"`); });
line.line.writeTextwriteText(i" $(r.w)×$(r.h) @$(r.position) #$(hex4(r.id))");
if (r.r.keyedkeyed)
line.line.writeTextwriteText(i" key");
if (r.r.kindkind == Kind.Kind.columncolumn || r.r.kindkind == Kind.Kind.rowrow || r.r.kindkind == Kind.Kind.mapMsgmapMsg || r.r.kindkind == Kind.Kind.memomemo)
line.line.writeTextwriteText(i" [$(r.env.density.enumMemberName)]");
if (r.r.envenv.r.env.disableddisabled)
line.line.writeTextwriteText(i" disabled");
if (r.r.kindkind == Kind.Kind.memomemo)
line.line.writeTextwriteText(i" memoKey #$(hex4(r.memoKey))");
if (r.r.msgmsg.r.msg.isSetisSet)
line.line.writeTextwriteText(i" [msg]");
write(depth, line[].idup);
foreach ((parameter) cc; kids[r.kidStart .. r.kidStart + r.childCount])
dumpFrom(write, c, depth + 1);
}
/// The 16-bit id prefix `dump` shows.
char[4] char[4] lazystack.Ui.shortId(lazystack.Node n) const pure nothrow @nogc @safeThe 16-bit id prefix dump shows.
shortId((struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node (parameter) lazystack.Node nn) const @safe pure nothrow @nogc => char[4] lazystack.hex4(ulong v) pure nothrow @nogc @safehex4((field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(parameter) lazystack.Node nn.(field) uint lazystack.Node.indexindex].(field) ulong lazystack.NodeRec.idid);
/// Whether the frame recorded no message-type diagnostic.
bool bool lazystack.Ui.messagesTypeCheck() const pure nothrow @nogc @safeWhether the frame recorded no message-type diagnostic.
messagesTypeCheck() const @safe pure nothrow @nogc
{
foreach ((parameter) const(lazystack.Diag) dd; (field) sparkles.base.buffer.Buffer!(Diag, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.diagsdiags[])
if ((local variable) const(lazystack.Diag) dd.(field) lazystack.DiagKind lazystack.Diag.kindkind == (enum) lazystack.DiagKindWhat a debug build reports instead of guessing.
DiagKind.(enum value) lazystack.DiagKind.messageTypeMismatch = 2ui.on sent a message of another type than the innermost mapMsg
(or the app) expects.
messageTypeMismatch || (local variable) const(lazystack.Diag) dd.(field) lazystack.DiagKind lazystack.Diag.kindkind == (enum) lazystack.DiagKindWhat a debug build reports instead of guessing.
DiagKind.(enum value) lazystack.DiagKind.mapMsgTargetMismatch = 3A mapMsg lifts into another type than its own scope expects.
mapMsgTargetMismatch)
return false;
return true;
}
private void void lazystack.Ui.describe(ref sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) line, uint n)describe(ref (alias) sparkles.base.buffer.UniqueBuffer!(char, 240LU) = sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u)Small-buffer optimization with a sole owner: inline while the elements fit, heap
when they do not, and copying is disabled.
Disabling copies is what removes the reference count from the grow path — there
is no second owner to consult. Hand a finished one to the shared world with
toShared, which consumes it and transfers any heap block without reallocating.
UniqueBuffer!(char, 240) (parameter) sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) lineline, uint (parameter) uint nn)
{
const (local variable) const(lazystack.NodeRec) rr = (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(parameter) uint nn];
(parameter) sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) lineline.void sparkles.base.text.writers.writeText!(sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u), core.interpolation.InterpolatedExpression!"r.kind.enumMemberName", string)(ref sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) w, core.interpolation.InterpolationHeader __param_1, core.interpolation.InterpolatedExpression!"r.kind.enumMemberName" __param_2, string __param_3, core.interpolation.InterpolationFooter __param_4) pure nothrow @nogc @safeWrites an interpolated sequence to an output range, verbatim.
SharedBuffer!(char, 128) buf;
buf.writeText(i"pid $(pid) exited with $(status)");
Plain, not styled. Literals are copied through and interpolated values go
via writeValue; nothing is parsed. That is the difference from
sparkles.base.styled_template.writeStyled, which reads {red …} as markup —
and the reason to reach for this one whenever the text is not a style template.
Interpolating a value that may contain a brace (a file path, a user's input)
through the styled writer silently eats it as a style block; here a brace is a
brace.
The @nogc half of the pair. std.conv.text already renders an
interpolated sequence to a string, so use that where a GC allocation is fine;
this is for the paths where it is not, and it inherits Writer's attributes the
way every template in this module does.
Examples
SharedBuffer!(char, 64) buf;
const pid = 1234;
buf.writeText(i"/proc/$(pid)/status");
assert(buf[] == "/proc/1234/status");
writeText((template instance) core.interpolation.InterpolatedExpression!"r.kind.enumMemberName"i"$(r.kind.enumMemberName)");
(field) benchtext.BumpTextPool lazystack.Ui.textstexts.bool benchtext.BumpTextPool.withText!(void delegate(scope const(char)[]) pure nothrow @nogc @safe)(in benchtext.BumpTextPool.Id id, scope void delegate(scope const(char)[]) pure nothrow @nogc @safe fn) pure nothrow @nogc @safewithText((local variable) const(lazystack.NodeRec) rr.(field) benchtext.BumpTextPool.Id lazystack.NodeRec.texttext, (scope const(char)[] (parameter) const(char)[] texttext) { (parameter) sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) lineline.void sparkles.base.text.writers.writeText!(sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u), core.interpolation.InterpolatedLiteral!" \"", core.interpolation.InterpolatedExpression!"text", const(char)[], core.interpolation.InterpolatedLiteral!"\"")(ref sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) w, core.interpolation.InterpolationHeader __param_1, core.interpolation.InterpolatedLiteral!" \"" __param_2, core.interpolation.InterpolatedExpression!"text" __param_3, const(char)[] __param_4, core.interpolation.InterpolatedLiteral!"\"" __param_5, core.interpolation.InterpolationFooter __param_6) pure nothrow @nogc @safeWrites an interpolated sequence to an output range, verbatim.
SharedBuffer!(char, 128) buf;
buf.writeText(i"pid $(pid) exited with $(status)");
Plain, not styled. Literals are copied through and interpolated values go
via writeValue; nothing is parsed. That is the difference from
sparkles.base.styled_template.writeStyled, which reads {red …} as markup —
and the reason to reach for this one whenever the text is not a style template.
Interpolating a value that may contain a brace (a file path, a user's input)
through the styled writer silently eats it as a style block; here a brace is a
brace.
The @nogc half of the pair. std.conv.text already renders an
interpolated sequence to a string, so use that where a GC allocation is fine;
this is for the paths where it is not, and it inherits Writer's attributes the
way every template in this module does.
Examples
SharedBuffer!(char, 64) buf;
const pid = 1234;
buf.writeText(i"/proc/$(pid)/status");
assert(buf[] == "/proc/1234/status");
writeText((template instance) core.interpolation.InterpolatedLiteral!" \""i` "$(text)"`); });
(parameter) sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) lineline.void sparkles.base.text.writers.writeText!(sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u), core.interpolation.InterpolatedLiteral!" #", core.interpolation.InterpolatedExpression!"hex4(r.id)", char[4])(ref sparkles.base.buffer.Buffer!(char, 240LU, cast(Storage)cast(ubyte)7u) w, core.interpolation.InterpolationHeader __param_1, core.interpolation.InterpolatedLiteral!" #" __param_2, core.interpolation.InterpolatedExpression!"hex4(r.id)" __param_3, char[4] __param_4, core.interpolation.InterpolationFooter __param_5) pure nothrow @nogc @safeWrites an interpolated sequence to an output range, verbatim.
SharedBuffer!(char, 128) buf;
buf.writeText(i"pid $(pid) exited with $(status)");
Plain, not styled. Literals are copied through and interpolated values go
via writeValue; nothing is parsed. That is the difference from
sparkles.base.styled_template.writeStyled, which reads {red …} as markup —
and the reason to reach for this one whenever the text is not a style template.
Interpolating a value that may contain a brace (a file path, a user's input)
through the styled writer silently eats it as a style block; here a brace is a
brace.
The @nogc half of the pair. std.conv.text already renders an
interpolated sequence to a string, so use that where a GC allocation is fine;
this is for the paths where it is not, and it inherits Writer's attributes the
way every template in this module does.
Examples
SharedBuffer!(char, 64) buf;
const pid = 1234;
buf.writeText(i"/proc/$(pid)/status");
assert(buf[] == "/proc/1234/status");
writeText((template instance) core.interpolation.InterpolatedLiteral!" #"i" #$(hex4(r.id))");
}
/// Reports every diagnostic of the frame (debug builds only record them).
void void diagnostics(W)(scope W write)Reports every diagnostic of the frame (debug builds only record them).
diagnostics(W)(scope W (parameter) W writewrite)
{
foreach ((parameter) dd; diags[])
{
UniqueBuffer!(char, 240) _error_ lineline;
line.line.writeTextwriteText(i"$(d.kind.enumMemberName): ");
describe(line, d.d.nodenode);
final switch (d.d.kindkind)
{
case DiagKind.DiagKind.slotAlreadyTakenslotAlreadyTaken:
line.line.writeTextwriteText(i" opened in a slot already taken by ");
if (d.d.otherother == none)
line.line.writeTextwriteText(i"a node");
else
describe(line, d.d.otherother);
line.line.writeTextwriteText(i", built outside a children slot");
break;
case DiagKind.DiagKind.childBuiltOutsideSlotchildBuiltOutsideSlot:
line.line.writeTextwriteText(i" was passed as child @$(d.position) of ");
if (d.d.otherother == none)
line.line.writeTextwriteText(i"the frame");
else
describe(line, d.d.otherother);
line.line.writeTextwriteText(i" but built before it opened");
break;
case DiagKind.DiagKind.messageTypeMismatchmessageTypeMismatch:
case DiagKind.DiagKind.mapMsgTargetMismatchmapMsgTargetMismatch:
line.line.writeTextwriteText(i" sends $(d.got) where $(d.expected) is expected");
break;
}
write(line[].idup);
}
}
/**
Delivers the message `target` sends, as the app's `Msg`: decoded, then
mapped by every `mapMsg` between `target` and the root.
*/
void void dispatch(Msg)(Node target, scope void delegate(Msg) @safe deliver, int payload = 0)Delivers the message target sends, as the app's Msg: decoded, then
mapped by every mapMsg between target and the root.
dispatch(Msg)((unresolved type) NodeNode (parameter) Node targettarget, scope void delegate(Msg) @safe (parameter) void delegate(Msg) @safe deliverdeliver, int (parameter) int payloadpayload = 0)
{
align(16) ubyte[256] _error_ aa, _error_ bb;
const _error_ mm = msgs[nodes[target.target.indexindex].nodes[target.index].msgmsg.nodes[target.index].msg.indexindex];
ulong _error_ keykey = m.m.typeKeytypeKey;
if (m.m.payloadpayload !is null)
{
assert(m.m.payloadKeypayloadKey == (template instance) typeKey!inttypeKey!int, "the payload is not an `int`");
(() @trusted => m.m.payloadpayload(&payload, &a[0]))();
}
else
a[0 .. m.value.length] = cast(const(ubyte)[]) m.m.valuevalue;
for (uint _error_ nn = nodes[target.target.indexindex].nodes[target.index].parentparent; n != none; n = nodes[n].parent)
if (nodes[n].nodes[n].kindkind == Kind.Kind.mapMsgmapMsg)
{
assert(nodes[n].nodes[n].mapmap.nodes[n].map.fromfrom == key, "a message reached a mapMsg of another type");
(() @trusted => nodes[n].nodes[n].mapmap.nodes[n].map.applyapply(&a[0], &b[0]))();
a = b;
key = nodes[n].nodes[n].mapmap.nodes[n].map.toto;
}
assert(key == (template instance) typeKey!MsgtypeKey!Msg, "the message is not the app's Msg");
deliver((() @trusted => *cast(Msg*) &a[0])());
}
// ── a layout pass after the build: positions, top-down ─────────────────
/// Positions every element from the fit sizes: a child sits at its
/// parent's position plus the extent of its earlier siblings and gaps.
/// One sweep in node order (parents precede their children).
void void lazystack.Ui.place() pure nothrow @nogc @safePositions every element from the fit sizes: a child sits at its
parent's position plus the extent of its earlier siblings and gaps.
One sweep in node order (parents precede their children).
place() @safe pure nothrow @nogc
{
if ((field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length == 0)
return;
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[0].(field) int lazystack.NodeRec.xx = 0;
(field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[0].(field) int lazystack.NodeRec.yy = 0;
foreach ((local variable) uint ii; 0 .. cast(uint) (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes.ulong sparkles.base.buffer.Buffer!(lazystack.NodeRec, 0LU, cast(Storage)cast(ubyte)6u).length() const pure nothrow @nogc @property @safeReturns the number of elements in the buffer.
length)
{
ref (local variable) lazystack.NodeRec pp = (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(local variable) uint ii];
if ((local variable) lazystack.NodeRec pp.(field) uint lazystack.NodeRec.childCountchildCount == 0)
continue;
const (local variable) const(bool) horizontalhorizontal = (local variable) lazystack.NodeRec pp.(field) lazystack.Kind lazystack.NodeRec.kindkind == (enum) lazystack.KindKind.(enum value) lazystack.Kind.row = 1row;
int (local variable) int xx = (local variable) lazystack.NodeRec pp.(field) int lazystack.NodeRec.xx, (local variable) int yy = (local variable) lazystack.NodeRec pp.(field) int lazystack.NodeRec.yy;
foreach ((parameter) uint cc; (field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids[(local variable) lazystack.NodeRec pp.(field) uint lazystack.NodeRec.kidStartkidStart .. (local variable) lazystack.NodeRec pp.(field) uint lazystack.NodeRec.kidStartkidStart + (local variable) lazystack.NodeRec pp.(field) uint lazystack.NodeRec.childCountchildCount])
{
ref (local variable) lazystack.NodeRec kk = (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(local variable) uint cc];
(local variable) lazystack.NodeRec kk.(field) int lazystack.NodeRec.xx = (local variable) int xx;
(local variable) lazystack.NodeRec kk.(field) int lazystack.NodeRec.yy = (local variable) int yy;
if ((local variable) const(bool) horizontalhorizontal)
(local variable) int xx += (local variable) lazystack.NodeRec kk.(field) uint lazystack.NodeRec.ww + (local variable) lazystack.NodeRec pp.(field) int lazystack.NodeRec.gapgap;
else
(local variable) int yy += (local variable) lazystack.NodeRec kk.(field) uint lazystack.NodeRec.hh + (local variable) lazystack.NodeRec pp.(field) int lazystack.NodeRec.gapgap;
}
}
}
/// A checksum of every element's position.
ulong ulong lazystack.Ui.positionsHash() const pure nothrow @nogc @safeA checksum of every element's position.
positionsHash() const @safe pure nothrow @nogc
{
ulong (local variable) ulong hh = 1469598103934665603UL;
foreach (ref (parameter) const(lazystack.NodeRec) rr; (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[])
(local variable) ulong hh = ((local variable) ulong hh ^ (cast(ulong) cast(uint) (local variable) const(lazystack.NodeRec) rr.(field) int lazystack.NodeRec.xx << 32 | cast(uint) (local variable) const(lazystack.NodeRec) rr.(field) int lazystack.NodeRec.yy)) * 1099511628211UL;
return (local variable) ulong hh;
}
// ── read-only access for the benchmark's tree checksum ─────────────────
const((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec)[] const(lazystack.NodeRec)[] lazystack.Ui.records() const pure nothrow @nogc return @saferecords() const return @safe pure nothrow @nogc => (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[];
/// Pre-order checksum of the tree under `n`.
void void lazystack.Ui.checksum(lazystack.Node n, ref ulong h, ref ulong count) const pure nothrow @nogc @safePre-order checksum of the tree under n.
checksum((struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node (parameter) lazystack.Node nn, ref ulong (parameter) ulong hh, ref (alias) object.size_t = ulongsize_t (parameter) ulong countcount) const @safe pure nothrow @nogc
{
import (module) treehashThe tree checksum every builder folds its nodes into, in pre-order.
treehash : (alias) treeHash = ulong treehash.treeHash(ulong h, scope const(char)[] kind, uint w, uint hgt, uint children) pure nothrow @nogc @safetreeHash;
const (local variable) const(lazystack.NodeRec) rr = (field) sparkles.base.buffer.Buffer!(NodeRec, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.nodesnodes[(parameter) lazystack.Node nn.(field) uint lazystack.Node.indexindex];
(parameter) ulong hh = ulong treehash.treeHash(ulong h, scope const(char)[] kind, uint w, uint hgt, uint children) pure nothrow @nogc @safetreeHash((parameter) ulong hh, (local variable) const(lazystack.NodeRec) rr.(field) lazystack.Kind lazystack.NodeRec.kindkind.string sparkles.base.text.enums.enumMemberName!(CaseStyle.original, lazystack.Kind)(in lazystack.Kind value) pure nothrow @nogc @safeThe name of the declared member equal to value, recased per style as a
compile-time string literal (so the call allocates nothing).
value must be a declared member of E. The generated final switch rejects a
duplicate-valued enum at compile time (duplicate case labels) and asserts on a
value that is not a declared member.
enumMemberName, (local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.ww, (local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.hh, (local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.childCountchildCount);
(parameter) ulong countcount++;
foreach ((parameter) const(uint) cc; (field) sparkles.base.buffer.Buffer!(uint, 0LU, cast(Storage)cast(ubyte)6u) lazystack.Ui.kidskids[(local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.kidStartkidStart .. (local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.kidStartkidStart + (local variable) const(lazystack.NodeRec) rr.(field) uint lazystack.NodeRec.childCountchildCount])
void lazystack.Ui.checksum(lazystack.Node n, ref ulong h, ref ulong count) const pure nothrow @nogc @safePre-order checksum of the tree under n.
checksum((struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node((local variable) const(uint) cc), (parameter) ulong hh, (parameter) ulong countcount);
}
}
/// Display width of UTF-8 text: one cell per code point (the trivial model).
package uint uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells(scope const(char)[] (parameter) const(char)[] ss) @safe pure nothrow @nogc
{
uint (local variable) uint nn;
foreach ((parameter) const(char) cc; (parameter) const(char)[] ss)
(local variable) uint nn += ((local variable) const(char) cc & 0xC0) != 0x80;
return (local variable) uint nn;
}
package uint uint lazystack.digits(int v) pure nothrow @nogc @safedigits(int (parameter) int vv) @safe pure nothrow @nogc
{
uint (local variable) uint nn = (parameter) int vv < 0 ? 2 : 1;
for ((parameter) int vv /= 10; v; v /= 10)
(local variable) uint nn++;
return (local variable) uint nn;
}
private char[4] char[4] lazystack.hex4(ulong v) pure nothrow @nogc @safehex4(ulong (parameter) ulong vv) @safe pure nothrow @nogc
{
char[4] (local variable) char[4] rr;
foreach ((local variable) int ii; 0 .. 4)
(local variable) char[4] rr[(local variable) int ii] = "0123456789abcdef"[((parameter) ulong vv >> (60 - 4 * (local variable) int ii)) & 0xF];
return (local variable) char[4] rr;
}
// ── containers: `ui.column(gap: 1, children: a, b, c)` ─────────────────────
/// A vertical stack. `env` and `disabled` reach its whole subtree, which is
/// evaluated after it opens.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.column(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), int gap = 0, bool disabled = false, lazystack.EnvOverride env = EnvOverride(false, Env(Layout.wide, Density.comfortable, false)), lazystack.NamedOnly _children = NamedOnly(), lazystack.Node delegate() pure nothrow @nogc @safe[] children...) pure nothrow @nogc @safeA vertical stack. env and disabled reach its whole subtree, which is
evaluated after it opens.
column(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, int (parameter) int gapgap = 0, bool (parameter) bool disableddisabled = false,
(struct) lazystack.EnvOverrideContext pushed by an element on open and popped on close. A child is
evaluated after its parent opens, so it reads the context directly.
EnvOverride (parameter) lazystack.EnvOverride envenv = (struct) lazystack.EnvOverrideditto
EnvOverride.(constant) lazystack.EnvOverride lazystack.EnvOverride.init = EnvOverride(false, Env(Layout.wide, Density.comfortable, false))init, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly _children_children = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init,
scope (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn[] (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren...) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.container(lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, scope lazystack.Node delegate() pure nothrow @nogc @safe[] children) pure nothrow @nogc @safeA container: open, evaluate each child slot in order, close.
container((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.column = cast(ubyte)0ucolumn, gap: (parameter) int gapgap), (parameter) lazystack.EnvOverride envenv, (parameter) bool disableddisabled, (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren);
/// A horizontal stack.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.row(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), int gap = 0, lazystack.NamedOnly _children = NamedOnly(), lazystack.Node delegate() pure nothrow @nogc @safe[] children...) pure nothrow @nogc @safeA horizontal stack.
row(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, int (parameter) int gapgap = 0,
(struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly _children_children = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, scope (alias) lazystack.ChildFn = lazystack.Node delegate() pure nothrow @nogc @safeWhat a child slot holds: a lazy, non-capturing-by-GC subtree builder.
scope at every use site is what keeps it off the GC (with the patch).
ChildFn[] (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren...) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.container(lazystack.NodeRec rec, lazystack.EnvOverride over, bool disabled, scope lazystack.Node delegate() pure nothrow @nogc @safe[] children) pure nothrow @nogc @safeA container: open, evaluate each child slot in order, close.
container((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.row = 1row, gap: (parameter) int gapgap), (struct) lazystack.EnvOverrideditto
EnvOverride.(constant) lazystack.EnvOverride lazystack.EnvOverride.init = EnvOverride(false, Env(Layout.wide, Density.comfortable, false))init, false, (parameter) lazystack.Node delegate() pure nothrow @nogc @safe[] childrenchildren);
// ── leaves ─────────────────────────────────────────────────────────────────
/// One run of text.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.label(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), lazystack.Slot slot = Slot.code, scope const(char)[] text = null) pure nothrow @nogc @safeOne run of text.
label(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, (enum) lazystack.SlotSlot (parameter) lazystack.Slot slotslot = (enum) lazystack.SlotSlot.(enum value) lazystack.Slot.code = cast(ubyte)0ucode,
scope const(char)[] (parameter) const(char)[] texttext = null) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.leaf(lazystack.NodeRec rec, uint w) pure nothrow @nogc @safeA leaf: open and close at once, with its own content size.
leaf((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.label = 2label, slot: (parameter) lazystack.Slot slotslot, text: (parameter) lazystack.Ui uiui.benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] texttext)), (parameter) const(char)[] texttext.uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells);
/// A switch; `onPress` is whatever message the caller wants on a press.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.toggle(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), bool on = false, scope const(char)[] label = null, lazystack.MsgRef onPress = MsgRef(4294967295u)) pure nothrow @nogc @safeA switch; onPress is whatever message the caller wants on a press.
toggle(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, bool (parameter) bool onon = false,
scope const(char)[] (parameter) const(char)[] labellabel = null, (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef (parameter) lazystack.MsgRef onPressonPress = (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef.(constant) lazystack.MsgRef lazystack.MsgRef.init = MsgRef(4294967295u)init) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.leaf(lazystack.NodeRec rec, uint w) pure nothrow @nogc @safeA leaf: open and close at once, with its own content size.
leaf((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.toggle = 3toggle, on: (parameter) bool onon, text: (parameter) lazystack.Ui uiui.benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] labellabel), msg: (parameter) lazystack.MsgRef onPressonPress),
(parameter) const(char)[] labellabel.uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells + 4);
/// A number field; `onChange` carries the new value as an `int` payload.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.numberField(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), int value = 0, scope const(char)[] unit = null, lazystack.MsgRef onChange = MsgRef(4294967295u)) pure nothrow @nogc @safeA number field; onChange carries the new value as an int payload.
numberField(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, int (parameter) int valuevalue = 0,
scope const(char)[] (parameter) const(char)[] unitunit = null, (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef (parameter) lazystack.MsgRef onChangeonChange = (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef.(constant) lazystack.MsgRef lazystack.MsgRef.init = MsgRef(4294967295u)init) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.leaf(lazystack.NodeRec rec, uint w) pure nothrow @nogc @safeA leaf: open and close at once, with its own content size.
leaf((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.numberField = 4numberField, value: (parameter) int valuevalue, text: (parameter) lazystack.Ui uiui.benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] unitunit),
msg: (parameter) lazystack.MsgRef onChangeonChange), (parameter) int valuevalue.uint lazystack.digits(int v) pure nothrow @nogc @safedigits + 1 + (parameter) const(char)[] unitunit.uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells);
/// A name and its value; pressing it sends `onPress`.
(struct) lazystack.NodeA handle to a node this frame built. Children return it so a parent can
tell a child built in its slot from one built earlier (see evalChild).
Node lazystack.Node lazystack.keyValue(ref lazystack.Ui ui, lazystack.NamedOnly _ = NamedOnly(), scope const(char)[] name = null, scope const(char)[] value = null, lazystack.MsgRef onPress = MsgRef(4294967295u)) pure nothrow @nogc @safeA name and its value; pressing it sends onPress.
keyValue(ref (struct) lazystack.UiThe frame's builder, on its owner's stack (or heap-owned for big frames) and
passed ref. Storage as in the inside-out sketch: append-only HeapBuffers
for nodes and messages, a TextPool for text, an InlineBuffer scratch for
ui.text, and an InSituRegion for constant messages' bytes.
Ui (parameter) lazystack.Ui uiui, (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly (parameter) lazystack.NamedOnly __ = (struct) lazystack.NamedOnlyThe sentinel in front of every attribute list, and again in front of
children: a positional argument after the last named attribute would
otherwise fill children silently. With it, children: is required.
NamedOnly.(constant) lazystack.NamedOnly lazystack.NamedOnly.init = NamedOnly()init, scope const(char)[] (parameter) const(char)[] namename = null,
scope const(char)[] (parameter) const(char)[] valuevalue = null, (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef (parameter) lazystack.MsgRef onPressonPress = (struct) lazystack.MsgRefAn erased message: an index into the frame's message table.
MsgRef.(constant) lazystack.MsgRef lazystack.MsgRef.init = MsgRef(4294967295u)init) @safe pure nothrow @nogc
=> (parameter) lazystack.Ui uiui.lazystack.Node lazystack.Ui.leaf(lazystack.NodeRec rec, uint w) pure nothrow @nogc @safeA leaf: open and close at once, with its own content size.
leaf((struct) lazystack.NodeRecOne element, written once when it opens (its size and children once more
when it closes). Children are listed, not linked: a closing element copies
its children's indices from the children stack into the kids table, as
Clay does, so no earlier record is ever updated.
NodeRec(kind: (enum) lazystack.KindKind.(enum value) lazystack.Kind.keyValue = 5keyValue, text: (parameter) lazystack.Ui uiui.benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] namename), text2: (parameter) lazystack.Ui uiui.benchtext.BumpTextPool.Id lazystack.Ui.intern(scope const(char)[] s) pure nothrow @nogc @safeintern((parameter) const(char)[] valuevalue),
msg: (parameter) lazystack.MsgRef onPressonPress), (parameter) const(char)[] namename.uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells + 1 + (parameter) const(char)[] valuevalue.uint lazystack.cells(scope const(char)[] s) pure nothrow @nogc @safeDisplay width of UTF-8 text: one cell per code point (the trivial model).
cells);
// ── lists: keys are mandatory ──────────────────────────────────────────────
/// A range bound to the builder. It offers `mapKeyed` and `mapByIndex`, and no
/// plain `map`: it is not an input range, so Phobos' `map` does not apply.
struct (struct) lazystack.UiRange(R)A range bound to the builder. It offers mapKeyed and mapByIndex, and no
plain map: it is not an input range, so Phobos' map does not apply.
UiRange(R)
{
private R _error_ rangerange;
private (unresolved type) UiUi* _error_ uiui;
}
/// ditto
auto auto toUi(R)(R r, return ref Ui ui)A range bound to the builder. It offers mapKeyed and mapByIndex, and no
plain map: it is not an input range, so Phobos' map does not apply.
toUi(R)(R (parameter) R rr, return ref (unresolved type) UiUi (parameter) Ui uiui) => (template instance) UiRange!RUiRange!R(r, &ui);
/**
Splices one keyed row per element into the argument position it occupies:
no fragment node, so the rows are the parent's own children for layout (as
Clay's would be). It is itself a lazy child, so it runs while the parent is
open. A free function, not a `Ui` method: a method template taking a local
lambda by alias needs a dual context.
*/
Node Node mapKeyed(alias key, alias row, R)(UiRange!R r)Splices one keyed row per element into the argument position it occupies:
no fragment node, so the rows are the parent's own children for layout (as
Clay's would be). It is itself a lazy child, so it runs while the parent is
open. A free function, not a Ui method: a method template taking a local
lambda by alias needs a dual context.
mapKeyed(alias key, alias row, R)(UiRange!R (parameter) UiRange!R rr)
{
auto _error_ uiui = r.r.uiui;
const _error_ pospos = ui.ui.nextPosnextPos;
foreach (ref (parameter) ee; r.r.rangerange)
{
ui.ui.nextKeyednextKeyed = true;
ui.ui.nextKeynextKey = hashOf(key(e));
cast(void) ui.ui.evalChildevalChild(pos, () => row(e));
}
ui.ui.nextKeyednextKeyed = false;
return Node.Node.nonenone; // the rows are linked already; the slot itself is empty
}
/// ditto, opting into position as the key (static or append-only lists).
Node Node mapByIndex(alias row, R)(UiRange!R r)ditto, opting into position as the key (static or append-only lists).
mapByIndex(alias row, R)(UiRange!R (parameter) UiRange!R rr)
{
auto _error_ uiui = r.r.uiui;
const _error_ pospos = ui.ui.nextPosnextPos;
ulong _error_ ii;
foreach (ref (parameter) ee; r.r.rangerange)
{
ui.ui.nextKeyednextKeyed = true;
ui.ui.nextKeynextKey = i++;
cast(void) ui.ui.evalChildevalChild(pos, () => row(e));
}
ui.ui.nextKeyednextKeyed = false;
return Node.Node.nonenone;
}
// ── messages ───────────────────────────────────────────────────────────────
/// A constant message, copied into the frame's table. Checked (debug, at run
/// time) against the open `mapMsg` scope: the child is evaluated inside it.
MsgRef MsgRef on(M)(ref Ui ui, M value)A constant message, copied into the frame's table. Checked (debug, at run
time) against the open mapMsg scope: the child is evaluated inside it.
on(M)(ref (unresolved type) UiUi (parameter) Ui uiui, M (parameter) M valuevalue)
{
static assert(__traits(isPOD, M), "a message is plain data: it is copied as bytes");
ui.ui.checkMsgcheckMsg((template instance) typeKey!MtypeKey!M, M.stringof);
return ui.ui.addMsgaddMsg(MsgRec(typeKey: (template instance) typeKey!MtypeKey!M, value: ui.ui.keepkeep(value)));
}
/// A message built from a component's payload. `fn` may not capture.
MsgRef MsgRef on(alias fn)(ref Ui ui)A message built from a component's payload. fn may not capture.
on(alias fn)(ref (unresolved type) UiUi (parameter) Ui uiui)
{
ui.ui.checkMsgcheckMsg((template instance) typeKey!(ReturnType!fn)typeKey!(ReturnType!fn), (template instance) ReturnType!fnReturnType!fn.stringof);
return ui.ui.addMsgaddMsg(MsgRec(typeKey: (template instance) typeKey!(ReturnType!fn)typeKey!(ReturnType!fn), payload: &(template instance) applyErased!fnapplyErased!fn,
payloadKey: (template instance) typeKey!(Parameters!fn[0])typeKey!(Parameters!fn[0])));
}
/**
Lifts every message its child sends with `fn`. The child is lazy, so it is
evaluated *inside* the scope: each `ui.on` below sees `From` as the expected
type and checks against it right there.
*/
Node Node mapMsg(alias fn)(ref Ui ui, scope ChildFn[] children...)Lifts every message its child sends with fn. The child is lazy, so it is
evaluated inside the scope: each ``ui.on below sees From as the expected
type and checks against it right there.
mapMsg(alias fn)(ref (unresolved type) UiUi (parameter) Ui uiui, scope (unresolved type) ChildFnChildFn[] (parameter) ChildFn[] childrenchildren...)
{
alias (alias) From = Parameters!fn[0]From = Parameters!fn[0];
alias (alias) To = ReturnType!fnTo = ReturnType!fn;
debug if (typeKey!To != ui.msgKey)
ui.diags ~= Diag(DiagKind.mapMsgTargetMismatch, ui.top, got: To.stringof,
expected: ui.msgName);
const _error_ savedsaved = ui.ui.currentEnvcurrentEnv;
const _error_ savedKeysavedKey = ui.ui.msgKeymsgKey;
const _error_ savedNamesavedName = ui.ui.msgNamemsgName;
const _error_ selfself = ui.ui.openopen(NodeRec(kind: Kind.Kind.mapMsgmapMsg, map: MapRec(from: (template instance) typeKey!FromtypeKey!(unresolved type) FromFrom,
to: (template instance) typeKey!TotypeKey!(unresolved type) ToTo, apply: &(template instance) applyErased!fnapplyErased!fn, fromName: From.stringof, toName: To.stringof)),
EnvOverride.EnvOverride.initinit, false);
ui.ui.msgKeymsgKey = (template instance) typeKey!FromtypeKey!(unresolved type) FromFrom;
ui.ui.msgNamemsgName = From.stringof;
foreach ((parameter) ii, (parameter) childchild; children)
cast(void) ui.ui.evalChildevalChild(cast(uint) i, child);
ui.ui.msgKeymsgKey = savedKey;
ui.ui.msgNamemsgName = savedName;
ui.ui.closeclose(saved);
return Node(self);
}
/// `fn`, erased: reads its argument at `from`, emplaces its result at `to`.
private void @system void applyErased(alias fn)(scope const(void)* from, scope void* to)fn, erased: reads its argument at from, emplaces its result at to.
applyErased(alias fn)(scope const(void)* (parameter) const(void)* fromfrom, scope void* (parameter) void* toto) @system
{
alias (alias) Src = Parameters!fn[0]Src = const Parameters!fn[0];
alias (alias) Dst = ReturnType!fnDst = ReturnType!fn;
emplace(cast((unresolved type) DstDst*) to, fn(*cast((unresolved type) SrcSrc*) from));
}
// ── memo seam ──────────────────────────────────────────────────────────────
/**
A memo site (UI-Q3's seam): a `memo` element keyed by `fn`'s arguments and the
env, then `fn(ui, args)` built as its one child. A real host compares the key
with last frame's element of the same id and, when equal, splices last
frame's subtree instead of calling `fn`.
*/
Node Node memo(alias fn, Args...)(ref Ui ui, auto ref const Args args)A memo site (UI-Q3's seam): a memo element keyed by fn's arguments and the
env, then fn(ui, args) built as its one child. A real host compares the key
with last frame's element of the same id and, when equal, splices last
frame's subtree instead of calling fn.
memo(alias fn, Args...)(ref (unresolved type) UiUi (parameter) Ui uiui, auto ref const Args (parameter) Args argsargs)
{
static assert((template instance) functionAttributes!fnfunctionAttributes!fn & FunctionAttribute.pure_,
"a memoised composite must be `pure`");
ulong _error_ keykey = hashOf(ui.ui.currentEnvcurrentEnv);
static foreach (i; 0 .. Args.length)
key = mix(key, hashOf(args[i]));
const _error_ savedsaved = ui.ui.currentEnvcurrentEnv;
const _error_ selfself = ui.ui.openopen(NodeRec(kind: Kind.Kind.memomemo, memoKey: key), EnvOverride.EnvOverride.initinit, false);
cast(void) ui.ui.evalChildevalChild(0, () => fn(ui, args));
ui.ui.closeclose(saved);
return Node(self);
}
version (BenchBench) pragma(msg, __MODULE__, ": NodeRec.sizeof = ", NodeRec.sizeof);