85 w.log().d(
"DFA to match: {}", dfa);
90 auto pos_t = w.call<regex::Pos>(n);
91 auto end = w.call<regex::pos>(n, n);
92 auto one = w.call<regex::pos>(n, w.lit_nat_1());
94 = w.mut_fun({w.call<mem::M>(0), w.call<mem::Str>(n), pos_t}, {w.call<mem::M>(0), w.type_bool(), pos_t});
95 matcher->debug_prefix(std::string(
"match_regex"));
96 auto [args, exit] = matcher->vars<2>();
97 exit->debug_prefix(std::string(
"exit"));
98 auto [mem, string, pos] = args->projs<3>();
99 mem->debug_prefix(std::string(
"mem"));
100 string->debug_prefix(std::string(
"string"));
101 pos->debug_prefix(std::string(
"pos"));
103 auto error = mem::mut_con(pos_t);
104 error->debug_prefix(
"error");
106 auto [mem, pos] = error->vars<2>();
107 mem->debug_prefix(std::string(
"mem"));
108 pos->debug_prefix(std::string(
"pos"));
109 error->app(
false, exit, {mem, w.lit_ff(), pos});
112 auto accept = mem::mut_con(pos_t);
113 accept->debug_prefix(
"accept");
115 auto [mem, pos] = accept->vars<2>();
116 mem->debug_prefix(std::string(
"mem"));
117 pos->debug_prefix(std::string(
"pos"));
118 accept->app(
false, exit, {mem, w.lit_tt(), pos});
121 auto exiting = [error, accept](
const DFANode* state) {
return state->is_accepting() ? accept : error; };
123 for (
auto state : states) {
124 auto lam = mem::mut_con(pos_t);
125 lam->debug_prefix(state_to_name(state));
126 state2matcher.emplace(state, lam);
129 for (
auto [state, lam] : state2matcher) {
130 auto [mem, i] = lam->vars<2>();
132 if (state->is_erroring()) {
133 lam->app(
true, error, {mem, i});
137 auto is_end = w.call(core::icmp::e,
Defs{i, end});
138 auto not_end = mem::mut_con(pos_t);
139 not_end->debug_prefix(
"not_end_" + state_to_name(state));
140 lam->app(
false, w.select(is_end, exiting(state), not_end), {mem, i});
142 auto [mem2, j] = not_end->vars<2>();
143 auto lea = w.call<mem::lea>(
Defs{string, w.call(core::conv::u, n, j)});
144 auto [mem3, c] = w.call<mem::load>(
Defs{mem2, lea})->projs<2>();
145 auto new_i = w.call(core::wrap::add, core::Mode::nsuw,
Defs{j, one});
147 auto transitions = create_check_match_transitions_from(c, state);
148 auto next_check = exiting(state);
149 for (
auto [next_state, check] : transitions) {
150 auto next_lam = state2matcher[next_state];
151 auto checker = mem::mut_con(pos_t);
152 checker->debug_prefix(
"check_" + state_to_name(state) +
"_to_" + state_to_name(next_state));
153 auto [mem, pos] = checker->vars<2>();
154 checker->app(
false, w.select(check, next_lam, next_check), {mem, w.select(check, new_i, pos)});
155 next_check = checker;
157 not_end->app(
true, next_check, {mem3, j});
160 matcher->app(
false, state2matcher[dfa.
get_start()], {mem, pos});