mirror of
https://github.com/open-goal/jak-project
synced 2026-09-03 18:23:39 -04:00
process-spawn + pretty printer improvements (#1428)
* some jp support to fix some errors in the original game * music fade toggle * recognize `process-new` macros!! * strip casts in this macro * rename macro * fix cast typecheck * update source 1 * detect kernel stack case * less boilerplate * `manipy-spawn` special case * pretty printer improvements * revert dumb thing from earlier * use shell detection on `send-event` * fix some events * remove unused argument * detect `static-attack-info` and add `CondNoElse` to shell detect * better `attack-info` detect * support `process-spawn` in multi-lets * detect `rand-float-gen` pt 1 * detect as return value * detect in `countdown` and `dotimes` * oops this wasnt working * fancier `send-event`s * clang * update source!! * fix tests * fine jeez * uh okay * fix some accidental regressions * fix more regressions * regression fixes * fix big bug... * extra safety!
This commit is contained in:
@@ -30,6 +30,14 @@ Matcher Matcher::op(const GenericOpMatcher& op, const std::vector<Matcher>& args
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::func(const Matcher& matcher, const std::vector<Matcher>& args) {
|
||||
return Matcher::op(GenericOpMatcher::func(matcher), args);
|
||||
}
|
||||
|
||||
Matcher Matcher::func(const std::string& name, const std::vector<Matcher>& args) {
|
||||
return Matcher::op(GenericOpMatcher::func(Matcher::constant_token(name)), args);
|
||||
}
|
||||
|
||||
Matcher Matcher::op_fixed(FixedOperatorKind op, const std::vector<Matcher>& args) {
|
||||
return Matcher::op(GenericOpMatcher::fixed(op), args);
|
||||
}
|
||||
@@ -42,12 +50,12 @@ Matcher Matcher::op_with_rest(const GenericOpMatcher& op, const std::vector<Matc
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::fixed_op(FixedOperatorKind op, const std::vector<Matcher>& args) {
|
||||
Matcher m;
|
||||
m.m_kind = Kind::GENERIC_OP;
|
||||
m.m_gen_op_matcher = std::make_shared<GenericOpMatcher>(GenericOpMatcher::fixed(op));
|
||||
m.m_sub_matchers = args;
|
||||
return m;
|
||||
Matcher Matcher::func_with_rest(const Matcher& matcher, const std::vector<Matcher>& args) {
|
||||
return Matcher::op_with_rest(GenericOpMatcher::func(matcher), args);
|
||||
}
|
||||
|
||||
Matcher Matcher::func_with_rest(const std::string& name, const std::vector<Matcher>& args) {
|
||||
return Matcher::op_with_rest(GenericOpMatcher::func(Matcher::constant_token(name)), args);
|
||||
}
|
||||
|
||||
Matcher Matcher::match_or(const std::vector<Matcher>& args) {
|
||||
@@ -86,6 +94,13 @@ Matcher Matcher::any_integer(int match_id) {
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::single(std::optional<float> value) {
|
||||
Matcher m;
|
||||
m.m_kind = Kind::FLOAT;
|
||||
m.m_float_match = value;
|
||||
return m;
|
||||
}
|
||||
|
||||
Matcher Matcher::any_quoted_symbol(int match_id) {
|
||||
Matcher m;
|
||||
m.m_kind = Kind::ANY_QUOTED_SYMBOL;
|
||||
@@ -257,27 +272,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
}
|
||||
} break;
|
||||
|
||||
case Kind::GENERIC_OP: {
|
||||
auto as_generic = dynamic_cast<GenericElement*>(input->try_as_single_active_element());
|
||||
if (as_generic) {
|
||||
if (!m_gen_op_matcher->do_match(as_generic->op(), maps_out)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (as_generic->elts().size() != m_sub_matchers.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_sub_matchers.size(); i++) {
|
||||
if (!m_sub_matchers.at(i).do_match(as_generic->elts().at(i), maps_out)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} break;
|
||||
|
||||
case Kind::GENERIC_OP:
|
||||
case Kind::GENERIC_OP_WITH_REST: {
|
||||
auto as_generic = dynamic_cast<GenericElement*>(input->try_as_single_active_element());
|
||||
if (as_generic) {
|
||||
@@ -285,7 +280,9 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (as_generic->elts().size() < m_sub_matchers.size()) {
|
||||
if ((m_kind == Kind::GENERIC_OP && as_generic->elts().size() != m_sub_matchers.size()) ||
|
||||
(m_kind == Kind::GENERIC_OP_WITH_REST &&
|
||||
as_generic->elts().size() < m_sub_matchers.size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -351,7 +348,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_int()) {
|
||||
if (!m_int_match.has_value()) {
|
||||
return true;
|
||||
@@ -363,6 +360,19 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
return false;
|
||||
} break;
|
||||
|
||||
case Kind::FLOAT: {
|
||||
auto as_const_float =
|
||||
dynamic_cast<ConstantFloatElement*>(input->try_as_single_active_element());
|
||||
if (as_const_float) {
|
||||
if (!m_float_match.has_value()) {
|
||||
return true;
|
||||
}
|
||||
return as_const_float->value() == *m_float_match;
|
||||
}
|
||||
|
||||
return false;
|
||||
} break;
|
||||
|
||||
case Kind::ANY_INT: {
|
||||
auto as_simple_atom = dynamic_cast<SimpleAtomElement*>(input->try_as_single_active_element());
|
||||
if (as_simple_atom) {
|
||||
@@ -376,7 +386,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_int()) {
|
||||
if (m_int_out_id != -1) {
|
||||
maps_out->ints[m_int_out_id] = atom.get_int();
|
||||
@@ -401,7 +411,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_ptr()) {
|
||||
if (m_string_out_id != -1) {
|
||||
maps_out->strings[m_string_out_id] = atom.get_str();
|
||||
@@ -425,7 +435,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_val()) {
|
||||
if (m_string_out_id != -1) {
|
||||
maps_out->strings[m_string_out_id] = atom.get_str();
|
||||
@@ -446,7 +456,7 @@ bool Matcher::do_match(Form* input, MatchResult::Maps* maps_out) const {
|
||||
|
||||
auto as_expr = dynamic_cast<SimpleExpressionElement*>(input->try_as_single_active_element());
|
||||
if (as_expr && as_expr->expr().is_identity()) {
|
||||
auto atom = as_expr->expr().get_arg(0);
|
||||
const auto& atom = as_expr->expr().get_arg(0);
|
||||
if (atom.is_sym_val()) {
|
||||
return atom.get_str() == m_str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user