From 9ec4b189bb11601001b48b7aa14ce79bc38bebe8 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Wed, 8 Jan 2025 08:08:12 +0100 Subject: [PATCH] karm-base: Got ride of the weird Cons<> tuple like type. --- src/libs/karm-base/cons.h | 54 -------------------------- src/libs/karm-base/map.h | 40 +++++++++---------- src/libs/karm-base/range.h | 4 +- src/libs/karm-base/tuple.h | 27 +++++++++++++ src/libs/karm-gfx/borders.cpp | 44 ++++++++++----------- src/libs/karm-gfx/fill.cpp | 22 +++++------ src/libs/karm-gfx/fill.h | 2 +- src/libs/karm-gfx/filters.cpp | 1 + src/libs/karm-gfx/filters.h | 2 +- src/libs/karm-io/fmt.h | 8 ++-- src/libs/karm-io/funcs.h | 2 +- src/libs/karm-io/pack.h | 13 ++++--- src/libs/karm-io/tests/test-fmt.cpp | 2 +- src/libs/karm-json/values.cpp | 4 +- src/libs/karm-math/rect.h | 6 +-- src/libs/karm-rpc/base.h | 2 +- src/libs/karm-sys/_embed.h | 4 +- src/libs/karm-sys/fd.h | 4 +- src/libs/karm-sys/pipe.cpp | 5 ++- src/libs/karm-sys/socket.h | 12 +++--- src/libs/karm-text/ttf.h | 2 +- src/libs/karm-text/ttf/otlayout.h | 2 +- src/libs/karm-text/ttf/parser.h | 2 +- src/libs/karm-ui/input.cpp | 4 +- src/libs/karm-ui/layout.h | 6 +-- src/web/vaev-css/lexer.cpp | 2 +- src/web/vaev-markup/html.cpp | 60 ++++++++++++++--------------- src/web/vaev-markup/xml.cpp | 48 +++++++++++------------ src/web/vaev-script/lexer.cpp | 2 +- src/web/vaev-style/fonts.h | 2 +- src/web/vaev-style/media.cpp | 2 +- src/web/vaev-style/styles.h | 6 +-- 32 files changed, 186 insertions(+), 210 deletions(-) delete mode 100644 src/libs/karm-base/cons.h diff --git a/src/libs/karm-base/cons.h b/src/libs/karm-base/cons.h deleted file mode 100644 index a3323c4a..00000000 --- a/src/libs/karm-base/cons.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "base.h" - -namespace Karm { - -template -struct Cons { - using Car = TCar; - using Cdr = TCdr; - - Car car; - Cdr cdr; - - always_inline constexpr auto const &get(bool cond) const { - return cond ? cdr : car; - } - - always_inline constexpr void visit(auto f) { - f(car); - f(cdr); - } - - always_inline constexpr void visit(auto f) const { - f(car); - f(cdr); - } - - template - always_inline constexpr Cons cast() const { - return {static_cast(car), static_cast(cdr)}; - } - - template - always_inline constexpr U into() const { - return U{car, cdr}; - } - - always_inline bool operator==(Cons const &) const - requires Meta::Equatable - = default; - - always_inline auto operator<=>(Cons const &) const - requires Meta::Comparable and Meta::Comparable - = default; -}; - -template -Cons(TCar, TCdr) -> Cons; - -template -using Pair = Cons; - -} // namespace Karm diff --git a/src/libs/karm-base/map.h b/src/libs/karm-base/map.h index 2c6ad89f..e8af81d9 100644 --- a/src/libs/karm-base/map.h +++ b/src/libs/karm-base/map.h @@ -7,27 +7,27 @@ namespace Karm { template struct Map { - Vec> _els{}; + Vec> _els{}; Map() = default; - Map(std::initializer_list> &&list) + Map(std::initializer_list> &&list) : _els(std::move(list)) {} void put(K const &key, V value) { for (auto &i : ::mutIter(_els)) { - if (i.car == key) { - i.cdr = std::move(value); + if (i.v0 == key) { + i.v1 = std::move(value); return; } } - _els.pushBack(Cons{key, std::move(value)}); + _els.pushBack(Pair{key, std::move(value)}); } bool has(K const &key) const { for (auto &i : _els) { - if (i.car == key) { + if (i.v0 == key) { return true; } } @@ -37,8 +37,8 @@ struct Map { V &get(K const &key) { for (auto &i : _els) { - if (i.car == key) { - return i.cdr; + if (i.v0 == key) { + return i.v1; } } @@ -47,22 +47,22 @@ struct Map { MutCursor access(K const &key) { for (auto &i : _els) - if (i.car == key) - return &i.cdr; + if (i.v0 == key) + return &i.v1; return {}; } Cursor access(K const &key) const { for (auto &i : _els) - if (i.car == key) - return &i.cdr; + if (i.v0 == key) + return &i.v1; return {}; } V take(K const &key) { for (usize i = 0; i < _els.len(); i++) { - if (_els[i].car == key) { - V value = std::move(_els[i].cdr); + if (_els[i].v0 == key) { + V value = std::move(_els[i].v1); _els.removeAt(i); return value; } @@ -73,8 +73,8 @@ struct Map { Opt tryGet(K const &key) const { for (auto &i : _els) { - if (i.car == key) { - return i.cdr; + if (i.v0 == key) { + return i.v1; } } @@ -83,7 +83,7 @@ struct Map { bool del(K const &key) { for (usize i = 0; i < _els.len(); i++) { - if (_els[i].car == key) { + if (_els[i].v0 == key) { _els.removeAt(i); return true; } @@ -96,7 +96,7 @@ struct Map { bool changed = false; for (usize i = 1; i < _els.len() + 1; i++) { - if (_els[i - 1].cdr == value) { + if (_els[i - 1].v1 == value) { _els.removeAt(i - 1); changed = true; i--; @@ -108,7 +108,7 @@ struct Map { bool removeFirst(V const &value) { for (usize i = 1; i < _els.len() + 1; i++) { - if (_els[i - 1].cdr == value) { + if (_els[i - 1].v1 == value) { _els.removeAt(i - 1); return true; } @@ -126,7 +126,7 @@ struct Map { } V at(usize index) const { - return _els[index].cdr; + return _els[index].v1; } usize len() const { diff --git a/src/libs/karm-base/range.h b/src/libs/karm-base/range.h index 562e7687..ee467b49 100644 --- a/src/libs/karm-base/range.h +++ b/src/libs/karm-base/range.h @@ -2,7 +2,7 @@ #include "align.h" #include "clamp.h" -#include "cons.h" +#include "tuple.h" namespace Karm { @@ -96,7 +96,7 @@ struct Range { return {}; } - constexpr Cons split(Range other) { + constexpr Pair split(Range other) { return {halfUnder(other), halfOver(other)}; } diff --git a/src/libs/karm-base/tuple.h b/src/libs/karm-base/tuple.h index 950e80ec..ec94b4c6 100644 --- a/src/libs/karm-base/tuple.h +++ b/src/libs/karm-base/tuple.h @@ -18,6 +18,9 @@ namespace Karm { template struct Tuple; +template +using Pair = Tuple; + template <> struct Tuple<> { constexpr static usize len() { @@ -84,6 +87,9 @@ struct Tuple<_T0> { constexpr U into() const { return U{v0}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -134,6 +140,9 @@ struct Tuple<_T0, _T1> { constexpr U into() const { return U{v0, v1}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -195,6 +204,9 @@ struct Tuple<_T0, _T1, _T2> { constexpr U into() const { return U{v0, v1, v2}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -267,6 +279,9 @@ struct Tuple<_T0, _T1, _T2, _T3> { constexpr U into() const { return U{v0, v1, v2, v3}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -350,6 +365,9 @@ struct Tuple<_T0, _T1, _T2, _T3, _T4> { constexpr U into() const { return U{v0, v1, v2, v3, v4}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -444,6 +462,9 @@ struct Tuple<_T0, _T1, _T2, _T3, _T4, _T5> { constexpr U into() const { return U{v0, v1, v2, v3, v4, v5}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -549,6 +570,9 @@ struct Tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6> { constexpr U into() const { return U{v0, v1, v2, v3, v4, v5, v6}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template @@ -665,6 +689,9 @@ struct Tuple<_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7> { constexpr U into() const { return U{v0, v1, v2, v3, v4, v5, v6, v7}; } + + bool operator==(Tuple const &) const = default; + auto operator<=>(Tuple const &) const = default; }; template diff --git a/src/libs/karm-gfx/borders.cpp b/src/libs/karm-gfx/borders.cpp index 541586da..fb111a8d 100644 --- a/src/libs/karm-gfx/borders.cpp +++ b/src/libs/karm-gfx/borders.cpp @@ -53,7 +53,7 @@ void Borders::_paintCurveEdge(Gfx::Canvas &c, Pair const &start, P c.beginPath(); // Outer edge - auto outerStart = start.car, outerEnd = end.car; + auto outerStart = start.v0, outerEnd = end.v0; c.moveTo(outerStart.a); c.cubicTo(outerStart.b, outerStart.c, outerStart.d); @@ -61,7 +61,7 @@ void Borders::_paintCurveEdge(Gfx::Canvas &c, Pair const &start, P c.cubicTo(outerEnd.b, outerEnd.c, outerEnd.d); // Inner edge - auto innerStart = start.cdr, innerEnd = end.cdr; + auto innerStart = start.v1, innerEnd = end.v1; c.lineTo(innerEnd.d); c.cubicTo(innerEnd.c, innerEnd.b, innerEnd.a); @@ -107,12 +107,12 @@ void Borders::_paintCurveEdges(Gfx::Canvas &c, Math::Rectf rect) { _paintCurveEdge( c, { - outerTopStart.split(topStartRatio).cdr, - innerTopStart.split(topStartRatio).cdr, + outerTopStart.split(topStartRatio).v1, + innerTopStart.split(topStartRatio).v1, }, { - outerTopEnd.split(topEndRatio).car, - innerTopEnd.split(topEndRatio).car, + outerTopEnd.split(topEndRatio).v0, + innerTopEnd.split(topEndRatio).v0, }, fills[0] ); @@ -121,12 +121,12 @@ void Borders::_paintCurveEdges(Gfx::Canvas &c, Math::Rectf rect) { _paintCurveEdge( c, { - outerTopEnd.split(topEndRatio).cdr, - innerTopEnd.split(topEndRatio).cdr, + outerTopEnd.split(topEndRatio).v1, + innerTopEnd.split(topEndRatio).v1, }, { - outerBottomEnd.split(bottomEndRatio).car, - innerBottomEnd.split(bottomEndRatio).car, + outerBottomEnd.split(bottomEndRatio).v0, + innerBottomEnd.split(bottomEndRatio).v0, }, fills[1] ); @@ -135,12 +135,12 @@ void Borders::_paintCurveEdges(Gfx::Canvas &c, Math::Rectf rect) { _paintCurveEdge( c, { - outerBottomEnd.split(bottomEndRatio).cdr, - innerBottomEnd.split(bottomEndRatio).cdr, + outerBottomEnd.split(bottomEndRatio).v1, + innerBottomEnd.split(bottomEndRatio).v1, }, { - outerBottomStart.split(bottomStartRatio).car, - innerBottomStart.split(bottomStartRatio).car, + outerBottomStart.split(bottomStartRatio).v0, + innerBottomStart.split(bottomStartRatio).v0, }, fills[2] ); @@ -149,12 +149,12 @@ void Borders::_paintCurveEdges(Gfx::Canvas &c, Math::Rectf rect) { _paintCurveEdge( c, { - outerBottomStart.split(bottomStartRatio).cdr, - innerBottomStart.split(bottomStartRatio).cdr, + outerBottomStart.split(bottomStartRatio).v1, + innerBottomStart.split(bottomStartRatio).v1, }, { - outerTopStart.split(topStartRatio).car, - innerTopStart.split(topStartRatio).car, + outerTopStart.split(topStartRatio).v0, + innerTopStart.split(topStartRatio).v0, }, fills[3] ); @@ -164,12 +164,12 @@ void Borders::_paintStraightEdge(Gfx::Canvas &c, Pair const &start, c.beginPath(); // Outer edge - c.moveTo(start.car); - c.lineTo(end.car); + c.moveTo(start.v0); + c.lineTo(end.v0); // Inner edge - c.lineTo(end.cdr); - c.lineTo(start.cdr); + c.lineTo(end.v1); + c.lineTo(start.v1); c.closePath(); diff --git a/src/libs/karm-gfx/fill.cpp b/src/libs/karm-gfx/fill.cpp index beb23f22..d8abe09e 100644 --- a/src/libs/karm-gfx/fill.cpp +++ b/src/libs/karm-gfx/fill.cpp @@ -3,8 +3,8 @@ namespace Karm::Gfx { static Color _lerp(Gradient::Stop lhs, Gradient::Stop rhs, f64 pos) { - f64 t = (pos - lhs.cdr) / (rhs.cdr - lhs.cdr); - return lhs.car.lerpWith(rhs.car, t); + f64 t = (pos - lhs.v1) / (rhs.v1 - lhs.v1); + return lhs.v0.lerpWith(rhs.v0, t); } static void _bakeStops(Slice stops, Gradient::Buf &buf, bool wraparound) { @@ -14,35 +14,35 @@ static void _bakeStops(Slice stops, Gradient::Buf &buf, bool wra return; if (stops.len() == 1) { - fill(mutSub(buf), stops[0].car); + fill(mutSub(buf), stops[0].v0); return; } - for (float j = 0; j < stops[0].cdr * 256; j++) { + for (float j = 0; j < stops[0].v1 * 256; j++) { if (wraparound) { auto lhs = stops[stops.len() - 1]; - lhs.cdr -= 1; + lhs.v1 -= 1; buf[j] = _lerp(lhs, stops[0], j / 256.0); } else { - buf[j] = stops[0].car; + buf[j] = stops[0].v0; } } for (usize i = 0; i < stops.len() - 1; i++) { - auto iPos = stops[i].cdr; - auto jPos = stops[i + 1].cdr; + auto iPos = stops[i].v1; + auto jPos = stops[i + 1].v1; for (f64 j = iPos * 256; j < jPos * 256; j++) buf[j] = _lerp(stops[i], stops[i + 1], j / 256.0); } - for (f64 j = last(stops).cdr * 256; j < 256; j++) { + for (f64 j = last(stops).v1 * 256; j < 256; j++) { if (wraparound) { auto rhs = stops[0]; - rhs.cdr += 1; + rhs.v1 += 1; buf[j] = _lerp(last(stops), rhs, j / 256.0); } else { - buf[j] = last(stops).car; + buf[j] = last(stops).v0; } } } diff --git a/src/libs/karm-gfx/fill.h b/src/libs/karm-gfx/fill.h index 20ae0b3c..aa41f06f 100644 --- a/src/libs/karm-gfx/fill.h +++ b/src/libs/karm-gfx/fill.h @@ -19,7 +19,7 @@ struct Gradient { }; using Buf = Array; - using Stop = Cons; + using Stop = Pair; Type _type = LINEAR; Math::Vec2f _start = {0.5, 0.5}; diff --git a/src/libs/karm-gfx/filters.cpp b/src/libs/karm-gfx/filters.cpp index cdfb239f..a8048500 100644 --- a/src/libs/karm-gfx/filters.cpp +++ b/src/libs/karm-gfx/filters.cpp @@ -252,6 +252,7 @@ void OverlayFilter::apply(MutPixels p) const { void FilterChain::apply(MutPixels p) const { filters.visit([&](auto &f) { f->apply(p); + return true; }); } diff --git a/src/libs/karm-gfx/filters.h b/src/libs/karm-gfx/filters.h index e8b6f38e..3dab5215 100644 --- a/src/libs/karm-gfx/filters.h +++ b/src/libs/karm-gfx/filters.h @@ -95,7 +95,7 @@ struct Filter; struct FilterChain { static constexpr auto NAME = "chain"; - Cons> filters; + Pair> filters; void apply(MutPixels) const; }; diff --git a/src/libs/karm-io/fmt.h b/src/libs/karm-io/fmt.h index 7db8d44f..899bd7a4 100644 --- a/src/libs/karm-io/fmt.h +++ b/src/libs/karm-io/fmt.h @@ -982,18 +982,18 @@ struct Formatter { // MARK: Format Tuple ---------------------------------------------------------- template -struct Formatter> { +struct Formatter> { - Res format(Io::TextWriter &writer, Cons const &val) { + Res format(Io::TextWriter &writer, Pair const &val) { usize written = 0; written += try$(writer.writeRune('{')); Formatter carFormatter; - written += try$(carFormatter.format(writer, val.car)); + written += try$(carFormatter.format(writer, val.v0)); written += try$(writer.writeStr(", "s)); Formatter cdrFormatter; - written += try$(cdrFormatter.format(writer, val.cdr)); + written += try$(cdrFormatter.format(writer, val.v1)); written += try$(writer.writeRune('}')); return Ok(written); } diff --git a/src/libs/karm-io/funcs.h b/src/libs/karm-io/funcs.h index 2679a1fd..b74b9719 100644 --- a/src/libs/karm-io/funcs.h +++ b/src/libs/karm-io/funcs.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include #include "impls.h" diff --git a/src/libs/karm-io/pack.h b/src/libs/karm-io/pack.h index e5307f9e..e3cabd64 100644 --- a/src/libs/karm-io/pack.h +++ b/src/libs/karm-io/pack.h @@ -6,6 +6,7 @@ #include #include #include + #include #include "bscan.h" @@ -242,15 +243,15 @@ struct Packer<_String> { // MARK: Tuple ----------------------------------------------------------------- template -struct Packer> { - static Res<> pack(PackEmit &e, Cons const &val) { - Io::pack(e, val.car); - Io::pack(e, val.cdr); +struct Packer> { + static Res<> pack(PackEmit &e, Pair const &val) { + Io::pack(e, val.v0); + Io::pack(e, val.v1); return Ok(); } - static Res> unpack(PackScan &s) { - Cons res = { + static Res> unpack(PackScan &s) { + Pair res = { try$(Io::unpack(s)), try$(Io::unpack(s)), }; diff --git a/src/libs/karm-io/tests/test-fmt.cpp b/src/libs/karm-io/tests/test-fmt.cpp index 8214a180..9c1843eb 100644 --- a/src/libs/karm-io/tests/test-fmt.cpp +++ b/src/libs/karm-io/tests/test-fmt.cpp @@ -198,7 +198,7 @@ test$("fmt-string") { // MARK: Format Tuple ---------------------------------------------------------- test$("fmt-cons") { - try$(testCase("{1, 2}", Cons{1, 2})); + try$(testCase("{1, 2}", Pair{1, 2})); return Ok(); } diff --git a/src/libs/karm-json/values.cpp b/src/libs/karm-json/values.cpp index cafb6a80..8fca41f8 100644 --- a/src/libs/karm-json/values.cpp +++ b/src/libs/karm-json/values.cpp @@ -31,9 +31,9 @@ Res<> stringify(Io::Emit &emit, Value const &v) { first = false; emit('"'); - emit(kv.car); + emit(kv.v0); emit("\":"); - try$(stringify(emit, kv.cdr)); + try$(stringify(emit, kv.v1)); } emit('}'); return Ok(); diff --git a/src/libs/karm-math/rect.h b/src/libs/karm-math/rect.h index c84e326a..28750545 100644 --- a/src/libs/karm-math/rect.h +++ b/src/libs/karm-math/rect.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include "insets.h" #include "vec.h" @@ -274,11 +274,11 @@ union Rect { return xy.hasNan() or wh.hasNan(); } - always_inline constexpr Cons hsplit(T v) const { + always_inline constexpr Pair hsplit(T v) const { return {Rect{x, y, v, height}, Rect{x + v, y, width - v, height}}; } - always_inline constexpr Cons vsplit(T v) const { + always_inline constexpr Pair vsplit(T v) const { return {Rect{x, y, width, v}, Rect{x, y + v, width, height - v}}; } diff --git a/src/libs/karm-rpc/base.h b/src/libs/karm-rpc/base.h index b520746d..82c6f873 100644 --- a/src/libs/karm-rpc/base.h +++ b/src/libs/karm-rpc/base.h @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/libs/karm-sys/_embed.h b/src/libs/karm-sys/_embed.h index 7ef0ee31..eae19ba9 100644 --- a/src/libs/karm-sys/_embed.h +++ b/src/libs/karm-sys/_embed.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include #include #include "async.h" @@ -31,7 +31,7 @@ Res> createFile(Mime::Url const &url); Res> openOrCreateFile(Mime::Url const &url); -Res, Strong>> createPipe(); +Res, Strong>> createPipe(); Res> createIn(); diff --git a/src/libs/karm-sys/fd.h b/src/libs/karm-sys/fd.h index 7d58868b..5ebad7b0 100644 --- a/src/libs/karm-sys/fd.h +++ b/src/libs/karm-sys/fd.h @@ -15,8 +15,8 @@ namespace Karm::Sys { struct Fd; -using _Accepted = Cons, SocketAddr>; -using _Sent = Cons; +using _Accepted = Pair, SocketAddr>; +using _Sent = Pair; using _Received = Tuple; struct Fd : Meta::NoCopy { diff --git a/src/libs/karm-sys/pipe.cpp b/src/libs/karm-sys/pipe.cpp index d17f49f8..6039bda2 100644 --- a/src/libs/karm-sys/pipe.cpp +++ b/src/libs/karm-sys/pipe.cpp @@ -1,6 +1,7 @@ #include "pipe.h" #include "_embed.h" + #include "proc.h" namespace Karm::Sys { @@ -9,8 +10,8 @@ Res Pipe::create() { try$(ensureUnrestricted()); auto pipe = try$(_Embed::createPipe()); return Ok(Pipe{ - FileWriter{pipe.car, "pipe:"_url}, - FileReader{pipe.cdr, "pipe:"_url}, + FileWriter{pipe.v0, "pipe:"_url}, + FileReader{pipe.v1, "pipe:"_url}, }); } diff --git a/src/libs/karm-sys/socket.h b/src/libs/karm-sys/socket.h index 8704dfb4..49ec644c 100644 --- a/src/libs/karm-sys/socket.h +++ b/src/libs/karm-sys/socket.h @@ -104,9 +104,9 @@ struct UdpConnection : return globalSched().sendAsync(_fd, buf, {}, addr); } - Res> recv(MutBytes buf) { + Res> recv(MutBytes buf) { auto [nbytes, _, addr] = try$(_fd->recv(buf, {})); - return Ok>(nbytes, addr); + return Ok>(nbytes, addr); } auto recvAsync(MutBytes buf) { @@ -165,9 +165,9 @@ struct IpcConnection { return Ok(); } - Res> recv(MutBytes buf, MutSlice hnds) { + Res> recv(MutBytes buf, MutSlice hnds) { auto [nbytes, nhnds, _] = try$(_fd->recv(buf, hnds)); - return Ok>(nbytes, nhnds); + return Ok>(nbytes, nhnds); } Async::Task<> sendAsync(Bytes buf, Slice hnds) { @@ -175,9 +175,9 @@ struct IpcConnection { co_return Ok(); } - Async::Task> recvAsync(MutBytes buf, MutSlice hnds) { + Async::Task> recvAsync(MutBytes buf, MutSlice hnds) { auto [nbytes, nhnds, _] = co_trya$(globalSched().recvAsync(_fd, buf, hnds)); - co_return Ok>(nbytes, nhnds); + co_return Ok>(nbytes, nhnds); } }; diff --git a/src/libs/karm-text/ttf.h b/src/libs/karm-text/ttf.h index 606aa668..64d9d80c 100644 --- a/src/libs/karm-text/ttf.h +++ b/src/libs/karm-text/ttf.h @@ -13,7 +13,7 @@ struct TtfFontface : public Fontface { Ttf::Parser _parser; Map _cachedEntries; Map _cachedAdvances; - Map, f64> _cachedKerns; + Map, f64> _cachedKerns; f64 _unitPerEm = 0; static Res> load(Sys::Mmap &&mmap); diff --git a/src/libs/karm-text/ttf/otlayout.h b/src/libs/karm-text/ttf/otlayout.h index d82f9331..135c3e98 100644 --- a/src/libs/karm-text/ttf/otlayout.h +++ b/src/libs/karm-text/ttf/otlayout.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include diff --git a/src/libs/karm-text/ttf/parser.h b/src/libs/karm-text/ttf/parser.h index 1272c5c7..691c65be 100644 --- a/src/libs/karm-text/ttf/parser.h +++ b/src/libs/karm-text/ttf/parser.h @@ -227,7 +227,7 @@ struct Parser { if (not positioning) return 0; - return positioning.unwrap().car.xAdvance; + return positioning.unwrap().v0.xAdvance; } void glyphContour(Gfx::Canvas &g, Text::Glyph glyph) const { diff --git a/src/libs/karm-ui/input.cpp b/src/libs/karm-ui/input.cpp index 41045120..9c193827 100644 --- a/src/libs/karm-ui/input.cpp +++ b/src/libs/karm-ui/input.cpp @@ -443,7 +443,7 @@ struct Slider : public ProxyNode { void layout(Math::Recti r) override { _bound = r; - child().layout(_bound.hsplit(((r.width - r.height) * _value) + r.height).car); + child().layout(_bound.hsplit(((r.width - r.height) * _value) + r.height).v0); } Math::Recti bound() override { @@ -460,7 +460,7 @@ struct Slider : public ProxyNode { if (_onChange) { _onChange(*this, _value); } else { - child().layout(_bound.hsplit(((_bound.width - _bound.height) * _value) + _bound.height).car); + child().layout(_bound.hsplit(((_bound.width - _bound.height) * _value) + _bound.height).v0); shouldRepaint(*this); } } diff --git a/src/libs/karm-ui/layout.h b/src/libs/karm-ui/layout.h index 60f22e13..c7cb5057 100644 --- a/src/libs/karm-ui/layout.h +++ b/src/libs/karm-ui/layout.h @@ -347,10 +347,10 @@ struct GridStyle { }; } - static GridStyle simpleFixed(Cons rows, Cons columns, Math::Vec2i gaps = {}) { + static GridStyle simpleFixed(Pair rows, Pair columns, Math::Vec2i gaps = {}) { return GridStyle{ - GridUnit::fixed(rows.cdr).repeated(rows.car), - GridUnit::fixed(columns.cdr).repeated(columns.car), + GridUnit::fixed(rows.v1).repeated(rows.v0), + GridUnit::fixed(columns.v1).repeated(columns.v0), gaps, Math::Flow::LEFT_TO_RIGHT, Math::Align::FILL, diff --git a/src/web/vaev-css/lexer.cpp b/src/web/vaev-css/lexer.cpp index f13ba285..d688003e 100644 --- a/src/web/vaev-css/lexer.cpp +++ b/src/web/vaev-css/lexer.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/src/web/vaev-markup/html.cpp b/src/web/vaev-markup/html.cpp index cfee8f46..6ca0e6c3 100644 --- a/src/web/vaev-markup/html.cpp +++ b/src/web/vaev-markup/html.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include "html.h" @@ -3496,38 +3496,38 @@ void HtmlLexer::consume(Rune rune, bool isEof) { // 0x9F 0x0178 LATIN CAPITAL LETTER Y WITH DIAERESIS (Ÿ) Array const CONV = { - Cons{0x80u, 0x20ACuz}, - Cons{0x82u, 0x201Auz}, - Cons{0x83u, 0x0192uz}, - Cons{0x84u, 0x201Euz}, - Cons{0x85u, 0x2026uz}, - Cons{0x86u, 0x2020uz}, - Cons{0x87u, 0x2021uz}, - Cons{0x88u, 0x02C6uz}, - Cons{0x89u, 0x2030uz}, - Cons{0x8Au, 0x0160uz}, - Cons{0x8Bu, 0x2039uz}, - Cons{0x8Cu, 0x0152uz}, - Cons{0x8Eu, 0x017Duz}, - Cons{0x91u, 0x2018uz}, - Cons{0x92u, 0x2019uz}, - Cons{0x93u, 0x201Cuz}, - Cons{0x94u, 0x201Duz}, - Cons{0x95u, 0x2022uz}, - Cons{0x96u, 0x2013uz}, - Cons{0x97u, 0x2014uz}, - Cons{0x98u, 0x02DCuz}, - Cons{0x99u, 0x2122uz}, - Cons{0x9Au, 0x0161uz}, - Cons{0x9Bu, 0x203Auz}, - Cons{0x9Cu, 0x0153uz}, - Cons{0x9Eu, 0x017Euz}, - Cons{0x9Fu, 0x0178uz}, + Pair{0x80u, 0x20ACuz}, + Pair{0x82u, 0x201Auz}, + Pair{0x83u, 0x0192uz}, + Pair{0x84u, 0x201Euz}, + Pair{0x85u, 0x2026uz}, + Pair{0x86u, 0x2020uz}, + Pair{0x87u, 0x2021uz}, + Pair{0x88u, 0x02C6uz}, + Pair{0x89u, 0x2030uz}, + Pair{0x8Au, 0x0160uz}, + Pair{0x8Bu, 0x2039uz}, + Pair{0x8Cu, 0x0152uz}, + Pair{0x8Eu, 0x017Duz}, + Pair{0x91u, 0x2018uz}, + Pair{0x92u, 0x2019uz}, + Pair{0x93u, 0x201Cuz}, + Pair{0x94u, 0x201Duz}, + Pair{0x95u, 0x2022uz}, + Pair{0x96u, 0x2013uz}, + Pair{0x97u, 0x2014uz}, + Pair{0x98u, 0x02DCuz}, + Pair{0x99u, 0x2122uz}, + Pair{0x9Au, 0x0161uz}, + Pair{0x9Bu, 0x203Auz}, + Pair{0x9Cu, 0x0153uz}, + Pair{0x9Eu, 0x017Euz}, + Pair{0x9Fu, 0x0178uz}, }; for (auto &conv : CONV) - if (conv.car == _currChar) { - _currChar = conv.cdr; + if (conv.v0 == _currChar) { + _currChar = conv.v1; break; } diff --git a/src/web/vaev-markup/xml.cpp b/src/web/vaev-markup/xml.cpp index 73a1bf84..ed8c1fef 100644 --- a/src/web/vaev-markup/xml.cpp +++ b/src/web/vaev-markup/xml.cpp @@ -33,26 +33,26 @@ static constexpr auto RE_S = static bool _isNameStartChar(Rune r) { Array RANGES = { - Cons{':', ':'}, - Cons{'A', 'Z'}, - Cons{'_', '_'}, - Cons{'a', 'z'}, - Cons{0xC0, 0xD6}, - Cons{0xD8, 0xF6}, - Cons{0xF8, 0x2FF}, - Cons{0x370, 0x37D}, - Cons{0x37F, 0x1FFF}, - Cons{0x200C, 0x200D}, - Cons{0x2070, 0x218F}, - Cons{0x2C00, 0x2FEF}, - Cons{0x3001, 0xD7FF}, - Cons{0xF900, 0xFDCF}, - Cons{0xFDF0, 0xFFFD}, - Cons{0x10000, 0xEFFFF}, + Pair{':', ':'}, + Pair{'A', 'Z'}, + Pair{'_', '_'}, + Pair{'a', 'z'}, + Pair{0xC0, 0xD6}, + Pair{0xD8, 0xF6}, + Pair{0xF8, 0x2FF}, + Pair{0x370, 0x37D}, + Pair{0x37F, 0x1FFF}, + Pair{0x200C, 0x200D}, + Pair{0x2070, 0x218F}, + Pair{0x2C00, 0x2FEF}, + Pair{0x3001, 0xD7FF}, + Pair{0xF900, 0xFDCF}, + Pair{0xFDF0, 0xFFFD}, + Pair{0x10000, 0xEFFFF}, }; for (auto range : RANGES) - if (r >= range.car and r <= range.cdr) + if (r >= range.v0 and r <= range.v1) return true; return false; @@ -62,16 +62,16 @@ static constexpr auto RE_NAME_START_CHAR = Re::ctype(_isNameStartChar); static bool _isNameChar(Rune r) { Array RANGES = { - Cons{'-', '-'}, - Cons{'.', '.'}, - Cons{'0', '9'}, - Cons{0xB7, 0xB7}, - Cons{0x0300, 0x036F}, - Cons{0x203F, 0x2040}, + Pair{'-', '-'}, + Pair{'.', '.'}, + Pair{'0', '9'}, + Pair{0xB7, 0xB7}, + Pair{0x0300, 0x036F}, + Pair{0x203F, 0x2040}, }; for (auto range : RANGES) - if (r >= range.car and r <= range.cdr) + if (r >= range.v0 and r <= range.v1) return true; return false; diff --git a/src/web/vaev-script/lexer.cpp b/src/web/vaev-script/lexer.cpp index ff309b52..f2811cb8 100644 --- a/src/web/vaev-script/lexer.cpp +++ b/src/web/vaev-script/lexer.cpp @@ -17,7 +17,7 @@ void Token::repr(Io::Emit &e) const { // MARK: Lexer ----------------------------------------------------------------- -using Str2Token = Cons; +using Str2Token = Pair; static constexpr auto _singleCharTokens = [] { Array res{}; diff --git a/src/web/vaev-style/fonts.h b/src/web/vaev-style/fonts.h index 9ff609cc..cdc5725f 100644 --- a/src/web/vaev-style/fonts.h +++ b/src/web/vaev-style/fonts.h @@ -406,7 +406,7 @@ struct FontDesc : public _FontDesc { using _FontDesc::_FontDesc; static constexpr Array LEGACY_ALIAS = { - Cons("font-stretch", "font-width"), + Pair("font-stretch", "font-width"), }; static Str mapLegacyAlias(Str name) { diff --git a/src/web/vaev-style/media.cpp b/src/web/vaev-style/media.cpp index 70904668..5894f0ae 100644 --- a/src/web/vaev-style/media.cpp +++ b/src/web/vaev-style/media.cpp @@ -5,7 +5,7 @@ namespace Vaev::Style { -static Cons _explodeFeatureName(Io::SScan s) { +static Pair _explodeFeatureName(Io::SScan s) { if (s.skip("min-")) return {Style::RangePrefix::MIN, s.remStr()}; else if (s.skip("max-")) diff --git a/src/web/vaev-style/styles.h b/src/web/vaev-style/styles.h index 1ecbc6ca..2904410c 100644 --- a/src/web/vaev-style/styles.h +++ b/src/web/vaev-style/styles.h @@ -2917,9 +2917,9 @@ struct StyleProp : public _StyleProp { static constexpr Array LEGACY_ALIAS = { // https://drafts.csswg.org/css-align-3/#gap-legacy - Cons{"grid-row-gap", "row-gap"}, - Cons{"grid-column-gap", "column-gap"}, - Cons{"grid-gap", "gap"}, + Pair{"grid-row-gap", "row-gap"}, + Pair{"grid-column-gap", "column-gap"}, + Pair{"grid-gap", "gap"}, }; Str name() const;