mirror of
https://github.com/open-goal/jak-project.git
synced 2024-11-28 00:40:42 +00:00
remove match param (#127)
This commit is contained in:
parent
953c1512db
commit
29e4ff9e51
@ -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<MatchParam<ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, MatchParam<ObjectType>>>& named) {
|
||||
const std::vector<std::optional<ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, std::optional<ObjectType>>>& 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
#define JAK1_INTERPRETER_H
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#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<MatchParam<ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, MatchParam<ObjectType>>>& named);
|
||||
const std::vector<std::optional<ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, std::optional<ObjectType>>>& named);
|
||||
|
||||
Object eval_pair(const Object& o, const std::shared_ptr<EnvironmentObject>& env);
|
||||
void eval_args(Arguments* args, const std::shared_ptr<EnvironmentObject>& env);
|
||||
|
@ -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<int> size,
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "third-party/fmt/core.h"
|
||||
#include <unordered_set>
|
||||
#include "common/util/MatchParam.h"
|
||||
#include "decompiler/util/MatchParam.h"
|
||||
#include "CfgBuilder.h"
|
||||
#include "decompiler/Function/CfgVtx.h"
|
||||
#include "decompiler/Function/Function.h"
|
||||
|
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef JAK1_MATCHPARAM_H
|
||||
#define JAK1_MATCHPARAM_H
|
||||
|
||||
template <typename T>
|
||||
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
|
||||
};
|
@ -4,6 +4,7 @@
|
||||
#define JAK_COMPILER_H
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include "common/type_system/TypeSystem.h"
|
||||
#include "Env.h"
|
||||
#include "goalc/listener/Listener.h"
|
||||
@ -77,11 +78,11 @@ class Compiler {
|
||||
const std::function<void(const goos::Object&)>& 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<MatchParam<goos::ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, MatchParam<goos::ObjectType>>>& named);
|
||||
void va_check(const goos::Object& form,
|
||||
const goos::Arguments& args,
|
||||
const std::vector<std::optional<goos::ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string,
|
||||
std::pair<bool, std::optional<goos::ObjectType>>>& 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);
|
||||
|
@ -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<MatchParam<goos::ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, MatchParam<goos::ObjectType>>>& named) {
|
||||
const std::vector<std::optional<goos::ObjectType>>& unnamed,
|
||||
const std::unordered_map<std::string, std::pair<bool, std::optional<goos::ObjectType>>>&
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ void CompilerTestRunner::run_static_test(inja::Environment& env,
|
||||
std::string& testCategory,
|
||||
const std::string& test_file,
|
||||
const std::vector<std::string>& expected,
|
||||
MatchParam<int> truncate) {
|
||||
std::optional<int> 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<std::string>& expected,
|
||||
MatchParam<int> truncate) {
|
||||
std::optional<int> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#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<std::string>& expected,
|
||||
MatchParam<int> truncate = {});
|
||||
std::optional<int> truncate = {});
|
||||
|
||||
void run_test(const std::string& test_category,
|
||||
const std::string& test_file,
|
||||
const std::vector<std::string>& expected,
|
||||
MatchParam<int> truncate = {});
|
||||
std::optional<int> truncate = {});
|
||||
|
||||
void run_always_pass(const std::string& test_category, const std::string& test_file);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user