Compare commits

...

5 Commits

Author SHA1 Message Date
Maddie Busig
7d660e215d Update gitignore 2025-05-06 01:47:45 -07:00
Maddie Busig
e613019f10 Implement add_mark_rule 2025-04-29 06:21:39 -07:00
Maddie Busig
25ce069a97 Implement add_branch_rule_weighted 2025-04-29 06:19:58 -07:00
Maddie Busig
1e045d9801 Implement add_branch_rule 2025-04-29 06:19:03 -07:00
Maddie Busig
07b94c996c Add valid_weighted_group 2025-04-29 06:16:12 -07:00
3 changed files with 54 additions and 2 deletions

1
.gitignore vendored
View File

@ -48,6 +48,7 @@ _deps
# ---> MISC & GBA # ---> MISC & GBA
.cache/ .cache/
build/ build/
build*
*.gba *.gba
*.elf *.elf

View File

@ -153,6 +153,9 @@ public:
bool weighted_groups_full() const { bool weighted_groups_full() const {
return m_weighted_groups.full(); return m_weighted_groups.full();
} }
bool valid_weighted_group(weighted_group_id_t wgroup) const {
return wgroup < m_weighted_groups.size();
}
/** /**
* @brief Add new weighted group * @brief Add new weighted group
@ -175,7 +178,9 @@ public:
* *
* @ret @c true if the number of branch rules in the ruleset equals @c g_max_branch_rules, @c false otherwise * @ret @c true if the number of branch rules in the ruleset equals @c g_max_branch_rules, @c false otherwise
*/ */
bool branch_rules_full() const; bool branch_rules_full() const {
return m_branch_rules.full();
}
/** /**
* @brief Add a new unweighted branch rule to the ruleset * @brief Add a new unweighted branch rule to the ruleset
@ -214,7 +219,9 @@ public:
* *
* @ret @c true if the number of mark rules in the ruleset equals @c g_max_mark_rules, @c false otherwise * @ret @c true if the number of mark rules in the ruleset equals @c g_max_mark_rules, @c false otherwise
*/ */
bool mark_rules_full() const; bool mark_rules_full() const {
return m_mark_rules.full();
}
/** @brief Add a new marking rule to the ruleset /** @brief Add a new marking rule to the ruleset
* *

View File

@ -66,6 +66,50 @@ weighted_group_id_t ruleset_t::add_weighted_group(const etl::ivector<etl::pair<g
return m_weighted_groups.size() - 1; return m_weighted_groups.size() - 1;
} }
branch_rule_id_t ruleset_t::add_branch_rule(token_id_t match, group_id_t group) {
if (!valid_token(match) || !valid_group_characteristic(group)) {
throw mtl::invalid_argument();
}
branch_rule_t rule {
.m_match = match,
.m_weighted = false,
.m_group = { .basic = group }
};
m_branch_rules.push_back(rule);
return m_branch_rules.size() - 1;
}
branch_rule_id_t ruleset_t::add_branch_rule_weighted(token_id_t match, weighted_group_id_t wgroup) {
if (!valid_token(match) || !valid_weighted_group(wgroup)) {
throw mtl::invalid_argument();
}
branch_rule_t rule {
.m_match = match,
.m_weighted = true,
.m_group = { .weighted = wgroup }
};
m_branch_rules.push_back(rule);
return m_branch_rules.size() - 1;
}
mark_rule_id_t ruleset_t::add_mark_rule(token_id_t match, uint32_t tag) {
if (!valid_token(match)) {
throw mtl::invalid_argument();
}
mark_rule_t rule {
.m_match = match,
.m_tag = tag
};
m_mark_rules.push_back(rule);
return m_mark_rules.size() - 1;
}
#if 0 #if 0
token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) { token_id_t generator_t::add_token(token_type_e type, mtl::fixed value) {
log::debug << "Adding token with type " << (int)type << endl; log::debug << "Adding token with type " << (int)type << endl;