88 = w.call(core::bit2::or_, w.lit_nat(2), w.tuple({state2check[state], match_range(c, lo, hi)}));
96 w.DLOG(
"dfa to match: {}", dfa);
102 auto matcher = w.mut_fun({w.annex<
mem::M>(), w.call<
mem::Ptr0>(w.arr(n, w.type_i8())), w.type_idx(n)},
103 {w.annex<
mem::M>(), w.type_bool(), w.type_idx(n)});
104 matcher->debug_prefix(std::string(
"match_regex"));
105 auto [args, exit] = matcher->vars<2>();
106 exit->debug_prefix(std::string(
"exit"));
107 auto [
mem, string, pos] = args->projs<3>();
108 mem->debug_prefix(std::string(
"mem"));
109 string->debug_prefix(std::string(
"string"));
110 pos->debug_prefix(std::string(
"pos"));
113 error->debug_prefix(
"error");
116 mem->debug_prefix(std::string(
"mem"));
117 pos->debug_prefix(std::string(
"pos"));
118 error->app(
false, exit, {
mem, w.lit_ff(), pos});
122 accept->debug_prefix(
"accept");
124 auto [
mem, pos] = accept->vars<2>();
125 mem->debug_prefix(std::string(
"mem"));
126 pos->debug_prefix(std::string(
"pos"));
127 accept->app(
false, exit, {
mem, w.lit_tt(), pos});
130 auto exiting = [
error, accept](
const DFANode* state) {
return state->is_accepting() ? accept :
error; };
132 for (
auto state : states) {
134 lam->debug_prefix(state_to_name(state));
135 state2matcher.emplace(state, lam);
138 for (
auto [state, lam] : state2matcher) {
139 auto [
mem, i] = lam->vars<2>();
141 if (state->is_erroring()) {
146 auto lea = w.call<
mem::lea>(w.tuple({n, w.pack(n, w.type_i8()), w.lit_nat(0)}), w.tuple({string, i}));
147 auto [mem2, c] = w.call<
mem::load>(w.tuple({
mem, lea}))->projs<2>();
149 auto is_end = w.call(core::icmp::e, w.tuple({c, w.lit_i8(0)}));
151 not_end->debug_prefix(
"not_end_" + state_to_name(state));
153 auto new_i = w.call(core::wrap::add, core::Mode::nusw, w.tuple({i, w.call(core::conv::u, n, w.lit_i64(1))}));
154 lam->app(
false, w.select(is_end, exiting(state), not_end), {mem2, i});
156 auto transitions = create_check_match_transitions_from(c, state);
157 auto next_check = exiting(state);
158 for (
auto [next_state, check] : transitions) {
159 auto next_lam = state2matcher[next_state];
161 checker->debug_prefix(
"check_" + state_to_name(state) +
"_to_" + state_to_name(next_state));
162 auto [mem3, pos] = checker->vars<2>();
163 checker->app(
false, w.select(check, next_lam, next_check), {mem3, w.select(check, new_i, pos)});
164 next_check = checker;
167 auto [
mem, pos] = not_end->vars<2>();
168 not_end->app(
true, next_check, {
mem, pos});
172 matcher->app(
false, state2matcher[dfa.
get_start()], {mem, pos});