Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ PTN_JOIN_HEADERS(PTN_HEADERS
include/ptn/pattern/structural.hpp
include/ptn/pattern/combinator.hpp
include/ptn/pattern/pred.hpp
include/ptn/pattern/negation.hpp
include/ptn/pattern/modifiers/guard.hpp
include/ptn/pattern/modifiers/placeholder.hpp
include/ptn/pattern/modifiers/fwd.h
)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int classify(int x) {

- Literal, structural, and `std::variant` matching in one DSL.
- Explicit binding through `$` and `$(...)`.
- Declarative guards via `PTN_LET`, `PTN_WHERE`, `_0`, `arg<N>`, `rng(...)`, and callables.
- Declarative guards via `_`, `PTN_BIND`, `rng(...)`, and callables.
- No RTTI, no virtual dispatch, no heap allocation.
- Static literal and variant dispatch lowering for hot paths.

Expand All @@ -70,8 +70,8 @@ using namespace ptn;

const char *bucket(int x) {
return match(x) | on(
$[PTN_LET(value, value < 0)] >> "negative",
$[PTN_LET(value, value < 10)] >> "small",
$[_ < 0] >> "negative",
$[_ < 10] >> "small",
_ >> "large"
);
}
Expand Down
8 changes: 4 additions & 4 deletions bench/bench_scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace {
is<EvtDisconnect>() >> 2,
is<EvtMessage>() >> 3,
is<EvtAck>() >> 4,
__ >> 0);
_ >> 0);
}

int scaleN_ptn8(const Evt8 &e) {
Expand All @@ -231,7 +231,7 @@ namespace {
is<EvtPong>() >> 6,
is<EvtError>() >> 7,
is<EvtTimeout>() >> 8,
__ >> 0);
_ >> 0);
}

int scaleN_ptn16(const Evt16 &e) {
Expand All @@ -254,7 +254,7 @@ namespace {
is<EvtInput>() >> 14,
is<EvtFocus>() >> 15,
is<EvtRender>() >> 16,
__ >> 0);
_ >> 0);
}

int scaleN_ptn32(const Evt32 &e) {
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace {
is<EvtCompress>() >> 30,
is<EvtCache>() >> 31,
is<EvtRetry>() >> 32,
__ >> 0);
_ >> 0);
}

// ---- StdVisit dispatchers ----
Expand Down
52 changes: 26 additions & 26 deletions bench/bench_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ namespace {
using ptn::pat::is;

return match(v)
| on(is<int>() >> 1, is<std::string>() >> 2, __ >> 0);
| on(is<int>() >> 1, is<std::string>() >> 2, _ >> 0);
}

static int patternia_pipe_variant_route(const V &v) {
using namespace ptn;
using ptn::pat::is;

return match(v)
| on(is<int>() >> 1, is<std::string>() >> 2, __ >> 0);
| on(is<int>() >> 1, is<std::string>() >> 2, _ >> 0);
}

static int patternia_pipe_variant_alt_route(const V &v) {
using namespace ptn;

return match(v) | on(alt<0>() >> 1, alt<1>() >> 2, __ >> 0);
return match(v) | on(alt<0>() >> 1, alt<1>() >> 2, _ >> 0);
}

static int patternia_pipe_variant_alt_32_route(const VAlt32 &v) {
Expand Down Expand Up @@ -247,7 +247,7 @@ namespace {
alt<29>() >> 30,
alt<30>() >> 31,
alt<31>() >> 32,
__ >> 0);
_ >> 0);
}

static int
Expand Down Expand Up @@ -286,7 +286,7 @@ namespace {
alt<29>() >> 30,
alt<30>() >> 31,
alt<31>() >> 32,
__ >> 0);
_ >> 0);

return match(v) | cases;
}
Expand Down Expand Up @@ -407,11 +407,11 @@ namespace {
};

return match(v)
| on($(is<int>())[_0 > 100] >> 10,
| on($(is<int>())[_ > 100] >> 10,
is<int>() >> 1,
$(is<std::string>())[long_string] >> 20,
is<std::string>() >> 2,
__ >> 0);
_ >> 0);
}

static int patternia_pipe_variant_guarded_route(const V &v) {
Expand All @@ -421,11 +421,11 @@ namespace {
};

return match(v)
| on($(is<int>())[_0 > 100] >> 10,
| on($(is<int>())[_ > 100] >> 10,
is<int>() >> 1,
$(is<std::string>())[long_string] >> 20,
is<std::string>() >> 2,
__ >> 0);
_ >> 0);
}

static int std_visit_variant_guarded_route(const V &v) {
Expand Down Expand Up @@ -510,7 +510,7 @@ namespace {
is<ProtoError>() >> 3,
$(is<ProtoControl>())[control_ack] >> 44,
is<ProtoControl>() >> 4,
__ >> 0);
_ >> 0);
}

static int patternia_pipe_protocol_router(const ProtocolMsg &msg) {
Expand All @@ -533,7 +533,7 @@ namespace {
is<ProtoError>() >> 3,
$(is<ProtoControl>())[control_ack] >> 44,
is<ProtoControl>() >> 4,
__ >> 0);
_ >> 0);
}

static int if_else_protocol_router(const ProtocolMsg &msg) {
Expand Down Expand Up @@ -634,7 +634,7 @@ namespace {
is<CmdDel>() >> 300,
$(is<CmdScan>())[wide_scan] >> 401,
is<CmdScan>() >> 400,
__ >> 0);
_ >> 0);
}

static int patternia_pipe_command_parser(const CommandMsg &msg) {
Expand All @@ -657,7 +657,7 @@ namespace {
is<CmdDel>() >> 300,
$(is<CmdScan>())[wide_scan] >> 401,
is<CmdScan>() >> 400,
__ >> 0);
_ >> 0);
}

static int if_else_command_parser(const CommandMsg &msg) {
Expand Down Expand Up @@ -750,7 +750,7 @@ namespace {
lit(6) >> 6,
lit(7) >> 7,
lit(8) >> 8,
__ >> 0);
_ >> 0);
}

static int patternia_literal_match_route(int x) {
Expand All @@ -765,7 +765,7 @@ namespace {
lit(6) >> 6,
lit(7) >> 7,
lit(8) >> 8,
__ >> 0);
_ >> 0);
}

static int if_else_literal_match_route(int x) {
Expand Down Expand Up @@ -877,7 +877,7 @@ namespace {

static int patternia_pipe_literal_match_16_route(int x) {
using namespace ptn;
return match(x) | on(PTN_RT_LIT_BLOCK_16(1), __ >> 0);
return match(x) | on(PTN_RT_LIT_BLOCK_16(1), _ >> 0);
}

static int if_else_literal_match_16_route(int x) {
Expand All @@ -900,7 +900,7 @@ namespace {
return match(x)
| on(PTN_RT_LIT_BLOCK_16(1),
PTN_RT_LIT_BLOCK_16(17),
__ >> 0);
_ >> 0);
}

static int if_else_literal_match_32_route(int x) {
Expand All @@ -927,7 +927,7 @@ namespace {
PTN_RT_LIT_BLOCK_16(17),
PTN_RT_LIT_BLOCK_16(33),
PTN_RT_LIT_BLOCK_16(49),
__ >> 0);
_ >> 0);
}

static int if_else_literal_match_64_route(int x) {
Expand Down Expand Up @@ -971,7 +971,7 @@ namespace {
ptn::lit(84) >> 84,
ptn::lit(91) >> 91,
ptn::lit(98) >> 98,
__ >> 0);
_ >> 0);
}

static int if_else_literal_match_rdense_route(int x) {
Expand Down Expand Up @@ -1090,7 +1090,7 @@ namespace {
PTN_LIT_BLOCK_16(81),
PTN_LIT_BLOCK_16(97),
PTN_LIT_BLOCK_16(113),
__ >> 0);
_ >> 0);

return match(x) | cases;
}
Expand All @@ -1107,7 +1107,7 @@ namespace {
PTN_LIT_BLOCK_16(81),
PTN_LIT_BLOCK_16(97),
PTN_LIT_BLOCK_16(113),
__ >> 0);
_ >> 0);
}

static int patternia_pipe_literal_match_128_on_macro_route(int x) {
Expand All @@ -1122,7 +1122,7 @@ namespace {
PTN_LIT_BLOCK_16(81),
PTN_LIT_BLOCK_16(97),
PTN_LIT_BLOCK_16(113),
__ >> 0);
_ >> 0);
}

static int switch_literal_match_128_route(int x) {
Expand Down Expand Up @@ -1242,7 +1242,7 @@ namespace {
[is_valid_data_packet]
>> 2,
$(has<&Packet::type>)[is_error_packet] >> 3,
__ >> 0);
_ >> 0);
}

static int patternia_pipe_packet_route(const Packet &pkt) {
Expand Down Expand Up @@ -1272,7 +1272,7 @@ namespace {
[is_valid_data_packet]
>> 2,
$(has<&Packet::type>)[is_error_packet] >> 3,
__ >> 0);
_ >> 0);
}

static int switch_packet_route(const Packet &pkt) {
Expand Down Expand Up @@ -1335,7 +1335,7 @@ namespace {
$(has<&Packet::type,
&Packet::payload>)[is_error_packet]
>> 3,
__ >> 0);
_ >> 0);
}

static int
Expand Down Expand Up @@ -1375,7 +1375,7 @@ namespace {
$(has<&Packet::type,
&Packet::payload>)[is_error_packet]
>> 3,
__ >> 0);
_ >> 0);
}

static int switch_packet_heavy_bind_route(const Packet &pkt) {
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function(_ptn_ct_add_lit_tu N)
foreach(_i RANGE 0 ${_last} 1)
string(APPEND _cases " ptn::lit(${_i}) >> ${_i},\n")
endforeach()
string(APPEND _cases " __ >> 0);\n")
string(APPEND _cases " _ >> 0);\n")
file(APPEND "${_tufile}" "${_cases}")
file(APPEND "${_tufile}" "}\n\n")

Expand Down
4 changes: 2 additions & 2 deletions bench/compile-time/ct_bench_compound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace {
ptn::lit(2) >> 2,
ptn::lit(3) >> 3,
ptn::lit(4) >> 4,
__ >> 0);
_ >> 0);
}

int ct_combo_variant(const VariantT &v) {
using namespace ptn;
return match(v)
| on(is<int>() >> 100, is<std::string>() >> 200, __ >> 0);
| on(is<int>() >> 100, is<std::string>() >> 200, _ >> 0);
}

int (*volatile sink_lit)(int) = ct_combo_lit;
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ constexpr int ct_lit_128(int v) noexcept {
ptn::lit(125) >> 125,
ptn::lit(126) >> 126,
ptn::lit(127) >> 127,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_128(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ constexpr int ct_lit_16(int v) noexcept {
ptn::lit(13) >> 13,
ptn::lit(14) >> 14,
ptn::lit(15) >> 15,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_16(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr int ct_lit_32(int v) noexcept {
ptn::lit(29) >> 29,
ptn::lit(30) >> 30,
ptn::lit(31) >> 31,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_32(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ constexpr int ct_lit_64(int v) noexcept {
ptn::lit(61) >> 61,
ptn::lit(62) >> 62,
ptn::lit(63) >> 63,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_64(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ constexpr int ct_lit_8(int v) noexcept {
ptn::lit(5) >> 5,
ptn::lit(6) >> 6,
ptn::lit(7) >> 7,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_8(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_lit_rdense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace {
ptn::lit(84) >> 84,
ptn::lit(91) >> 91,
ptn::lit(98) >> 98,
__ >> 0);
_ >> 0);
}

static_assert(ct_lit_rdense(0) == 0, "");
Expand Down
2 changes: 1 addition & 1 deletion bench/compile-time/ct_bench_variant_32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace {
alt<29>() >> 30,
alt<30>() >> 31,
alt<31>() >> 32,
__ >> 0);
_ >> 0);
}

int (*volatile sink)(const VAlt32 &) = ct_var_alt_route;
Expand Down
Loading
Loading