diff --git a/common/goos/Interpreter.cpp b/common/goos/Interpreter.cpp index 6502a683cd..d20dfe5c73 100644 --- a/common/goos/Interpreter.cpp +++ b/common/goos/Interpreter.cpp @@ -380,8 +380,8 @@ ArgumentSpec Interpreter::parse_arg_spec(const Object& form, Object& rest) { void Interpreter::vararg_check( const Object& form, const Arguments& args, - const std::vector>& unnamed, - const std::unordered_map>>& named) { + const std::vector>& unnamed, + const std::unordered_map>>& named) { assert(args.rest.empty()); if (unnamed.size() != args.unnamed.size()) { throw_eval_error(form, "Got " + std::to_string(args.unnamed.size()) + @@ -389,11 +389,10 @@ void Interpreter::vararg_check( } for (size_t i = 0; i < unnamed.size(); i++) { - if (unnamed[i] != args.unnamed[i].type) { - assert(!unnamed[i].is_wildcard); + if (unnamed[i].has_value() && unnamed[i] != args.unnamed[i].type) { throw_eval_error(form, "Argument " + std::to_string(i) + " has type " + object_type_to_string(args.unnamed[i].type) + " but " + - object_type_to_string(unnamed[i].value) + " was expected"); + object_type_to_string(unnamed[i].value()) + " was expected"); } } @@ -407,12 +406,12 @@ void Interpreter::vararg_check( } } else { // argument given. - if (kv.second.second != kv2->second.type) { + if (kv.second.second.has_value() && kv.second.second != kv2->second.type) { // but is wrong type - assert(!kv.second.second.is_wildcard); throw_eval_error(form, "Argument \"" + kv.first + "\" has type " + object_type_to_string(kv2->second.type) + " but " + - object_type_to_string(kv.second.second.value) + " was expected"); + object_type_to_string(kv.second.second.value()) + + " was expected"); } } } diff --git a/common/goos/Interpreter.h b/common/goos/Interpreter.h index 52eed89c23..92dbf93a12 100644 --- a/common/goos/Interpreter.h +++ b/common/goos/Interpreter.h @@ -9,9 +9,9 @@ #define JAK1_INTERPRETER_H #include +#include #include "Object.h" #include "Reader.h" -#include "common/util/MatchParam.h" namespace goos { class Interpreter { @@ -55,8 +55,8 @@ class Interpreter { void vararg_check( const Object& form, const Arguments& args, - const std::vector>& unnamed, - const std::unordered_map>>& named); + const std::vector>& unnamed, + const std::unordered_map>>& named); Object eval_pair(const Object& o, const std::shared_ptr& env); void eval_args(Arguments* args, const std::shared_ptr& env); diff --git a/decompiler/Disasm/InstructionMatching.h b/decompiler/Disasm/InstructionMatching.h index 7d67751eac..850cf7a0ce 100644 --- a/decompiler/Disasm/InstructionMatching.h +++ b/decompiler/Disasm/InstructionMatching.h @@ -9,7 +9,7 @@ #define JAK_DISASSEMBLER_INSTRUCTIONMATCHING_H #include "Instruction.h" -#include "common/util/MatchParam.h" +#include "decompiler/util/MatchParam.h" bool is_no_link_gpr_store(const Instruction& instr, MatchParam size, diff --git a/decompiler/IR/CfgBuilder.cpp b/decompiler/IR/CfgBuilder.cpp index d928800420..6c4582f3bd 100644 --- a/decompiler/IR/CfgBuilder.cpp +++ b/decompiler/IR/CfgBuilder.cpp @@ -1,6 +1,6 @@ #include "third-party/fmt/core.h" #include -#include "common/util/MatchParam.h" +#include "decompiler/util/MatchParam.h" #include "CfgBuilder.h" #include "decompiler/Function/CfgVtx.h" #include "decompiler/Function/Function.h" diff --git a/common/util/MatchParam.h b/decompiler/util/MatchParam.h similarity index 83% rename from common/util/MatchParam.h rename to decompiler/util/MatchParam.h index 0a2140ebff..c122a7c4fc 100644 --- a/common/util/MatchParam.h +++ b/decompiler/util/MatchParam.h @@ -1,8 +1,5 @@ #pragma once -#ifndef JAK1_MATCHPARAM_H -#define JAK1_MATCHPARAM_H - template struct MatchParam { MatchParam() { is_wildcard = true; } @@ -18,6 +15,4 @@ struct MatchParam { bool operator==(const T& other) const { return is_wildcard || (value == other); } bool operator!=(const T& other) const { return !(*this == other); } -}; - -#endif // JAK1_MATCHPARAM_H +}; \ No newline at end of file diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index f285d12be5..b376389a55 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -4,6 +4,7 @@ #define JAK_COMPILER_H #include +#include #include "common/type_system/TypeSystem.h" #include "Env.h" #include "goalc/listener/Listener.h" @@ -77,11 +78,11 @@ class Compiler { const std::function& f); goos::Arguments get_va(const goos::Object& form, const goos::Object& rest); - void va_check( - const goos::Object& form, - const goos::Arguments& args, - const std::vector>& unnamed, - const std::unordered_map>>& named); + void va_check(const goos::Object& form, + const goos::Arguments& args, + const std::vector>& unnamed, + const std::unordered_map>>& named); std::string as_string(const goos::Object& o); std::string symbol_string(const goos::Object& o); std::string quoted_sym_as_string(const goos::Object& o); diff --git a/goalc/compiler/Util.cpp b/goalc/compiler/Util.cpp index 40329ebdf7..b3f43d8a15 100644 --- a/goalc/compiler/Util.cpp +++ b/goalc/compiler/Util.cpp @@ -37,8 +37,9 @@ goos::Arguments Compiler::get_va(const goos::Object& form, const goos::Object& r void Compiler::va_check( const goos::Object& form, const goos::Arguments& args, - const std::vector>& unnamed, - const std::unordered_map>>& named) { + const std::vector>& unnamed, + const std::unordered_map>>& + named) { assert(args.rest.empty()); if (unnamed.size() != args.unnamed.size()) { throw_compile_error(form, "Got " + std::to_string(args.unnamed.size()) + @@ -46,11 +47,10 @@ void Compiler::va_check( } for (size_t i = 0; i < unnamed.size(); i++) { - if (unnamed[i] != args.unnamed[i].type) { - assert(!unnamed[i].is_wildcard); + if (unnamed[i].has_value() && unnamed[i] != args.unnamed[i].type) { throw_compile_error(form, "Argument " + std::to_string(i) + " has type " + object_type_to_string(args.unnamed[i].type) + " but " + - object_type_to_string(unnamed[i].value) + " was expected"); + object_type_to_string(unnamed[i].value()) + " was expected"); } } @@ -64,12 +64,11 @@ void Compiler::va_check( } } else { // argument given. - if (kv.second.second != kv2->second.type) { + if (kv.second.second.has_value() && kv.second.second != kv2->second.type) { // but is wrong type - assert(!kv.second.second.is_wildcard); throw_compile_error(form, "Argument \"" + kv.first + "\" has type " + object_type_to_string(kv2->second.type) + " but " + - object_type_to_string(kv.second.second.value) + + object_type_to_string(kv.second.second.value()) + " was expected"); } } diff --git a/test/goalc/framework/test_runner.cpp b/test/goalc/framework/test_runner.cpp index 2e18be2e9e..41447e323d 100644 --- a/test/goalc/framework/test_runner.cpp +++ b/test/goalc/framework/test_runner.cpp @@ -38,7 +38,7 @@ void CompilerTestRunner::run_static_test(inja::Environment& env, std::string& testCategory, const std::string& test_file, const std::vector& expected, - MatchParam truncate) { + std::optional truncate) { env.write(test_file, {}, test_file); run_test(testCategory, test_file, expected, truncate); } @@ -46,13 +46,13 @@ void CompilerTestRunner::run_static_test(inja::Environment& env, void CompilerTestRunner::run_test(const std::string& test_category, const std::string& test_file, const std::vector& expected, - MatchParam truncate) { + std::optional truncate) { fprintf(stderr, "Testing %s\n", test_file.c_str()); auto result = c->run_test_from_file("test/goalc/source_generated/" + test_category + "/" + test_file); - if (!truncate.is_wildcard) { + if (truncate.has_value()) { for (auto& x : result) { - x = x.substr(0, truncate.value); + x = x.substr(0, truncate.value()); } } diff --git a/test/goalc/framework/test_runner.h b/test/goalc/framework/test_runner.h index d332d15cc0..d5fb13a4ba 100644 --- a/test/goalc/framework/test_runner.h +++ b/test/goalc/framework/test_runner.h @@ -2,6 +2,7 @@ #include #include +#include #include "inja.hpp" #include "goalc/compiler/Compiler.h" @@ -26,12 +27,12 @@ struct CompilerTestRunner { std::string& testCategory, const std::string& test_file, const std::vector& expected, - MatchParam truncate = {}); + std::optional truncate = {}); void run_test(const std::string& test_category, const std::string& test_file, const std::vector& expected, - MatchParam truncate = {}); + std::optional truncate = {}); void run_always_pass(const std::string& test_category, const std::string& test_file);