mirror of
https://github.com/open-goal/jak-project
synced 2026-08-20 06:16:35 -04:00
Merge remote-tracking branch 'origin/master' into j2/progress
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "audio_formats.h"
|
||||
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/BinaryWriter.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
@@ -254,7 +255,7 @@ void test_encode_adpcm(const std::vector<s16>& samples,
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
fmt::print("Range: {}\n", max_sample - min_sample);
|
||||
lg::debug("Range: {}", max_sample - min_sample);
|
||||
}
|
||||
|
||||
// see how many bits we need and pick shift.
|
||||
@@ -283,11 +284,11 @@ void test_encode_adpcm(const std::vector<s16>& samples,
|
||||
|
||||
if (filter_errors[best_filter] || best_filter != filter_debug[block_idx] ||
|
||||
best_shift != shift_debug[block_idx]) {
|
||||
fmt::print("Block {} me {}, {} : answer {} {}: ERR {}\n", block_idx, best_filter, best_shift,
|
||||
filter_debug[block_idx], shift_debug[block_idx], filter_errors[best_filter]);
|
||||
fmt::print("filter errors:\n");
|
||||
lg::error("Block {} me {}, {} : answer {} {}: ERR {}", block_idx, best_filter, best_shift,
|
||||
filter_debug[block_idx], shift_debug[block_idx], filter_errors[best_filter]);
|
||||
lg::error("filter errors:");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
fmt::print(" [{}] {} {}\n", i, filter_errors[i], filter_shifts[i]);
|
||||
lg::error(" [{}] {} {}", i, filter_errors[i], filter_shifts[i]);
|
||||
}
|
||||
ASSERT_MSG(false, fmt::format("prev: {} {}", prev_block_samples[0], prev_block_samples[1]));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
#include "common/log/log.h"
|
||||
// clang-format on
|
||||
|
||||
int open_socket(int af, int type, int protocol) {
|
||||
@@ -29,7 +30,7 @@ int open_socket(int af, int type, int protocol) {
|
||||
// Initialize Winsock
|
||||
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (iResult != 0) {
|
||||
printf("WSAStartup failed: %d\n", iResult);
|
||||
lg::error("WSAStartup failed: {}", iResult);
|
||||
return 1;
|
||||
}
|
||||
return socket(af, type, protocol);
|
||||
@@ -71,7 +72,7 @@ int accept_socket(int socket, sockaddr* addr, int* addrLen) {
|
||||
// Initialize Winsock
|
||||
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (iResult != 0) {
|
||||
printf("WSAStartup failed: %d\n", iResult);
|
||||
lg::error("WSAStartup failed: {}", iResult);
|
||||
return 1;
|
||||
}
|
||||
return accept(socket, addr, addrLen);
|
||||
@@ -116,13 +117,13 @@ void close_socket(int sock) {
|
||||
int set_socket_option(int socket, int level, int optname, const void* optval, int optlen) {
|
||||
int ret = setsockopt(socket, level, optname, (const char*)optval, optlen);
|
||||
if (ret < 0) {
|
||||
printf("Failed to setsockopt(%d, %d, %d, _, _) - Error: %s\n", socket, level, optname,
|
||||
strerror(errno));
|
||||
lg::error("Failed to setsockopt({},{}, {}, _, _) - Error: {}", socket, level, optname,
|
||||
strerror(errno));
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (ret < 0) {
|
||||
int err = WSAGetLastError();
|
||||
printf("WSAGetLastError: %d\n", err);
|
||||
lg::error("WSAGetLastError: {}", err);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
@@ -153,7 +154,7 @@ int write_to_socket(int socket, const char* buf, int len) {
|
||||
bytes_wrote = send(socket, buf, len, 0);
|
||||
#endif
|
||||
if (bytes_wrote < 0) {
|
||||
fmt::print(stderr, "[XSocket:{}] Error writing to socket\n", socket);
|
||||
lg::error("[XSocket:{}] Error writing to socket", socket);
|
||||
}
|
||||
return bytes_wrote;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#endif
|
||||
#include "common/log/log.h"
|
||||
// clang-format on
|
||||
|
||||
XSocketServer::XSocketServer(std::function<bool()> shutdown_callback,
|
||||
@@ -67,19 +68,19 @@ bool XSocketServer::init_server() {
|
||||
addr.sin_port = htons(tcp_port);
|
||||
|
||||
if (bind(listening_socket, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
fmt::print("[XSocketServer:{}] failed to bind\n", tcp_port);
|
||||
lg::error("[XSocketServer:{}] failed to bind", tcp_port);
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (listen(listening_socket, 0) < 0) {
|
||||
fmt::print("[XSocketServer:{}] failed to listen\n", tcp_port);
|
||||
lg::error("[XSocketServer:{}] failed to listen", tcp_port);
|
||||
close_server_socket();
|
||||
return false;
|
||||
}
|
||||
|
||||
server_initialized = true;
|
||||
fmt::print("[XSocketServer:{}] initialized\n", tcp_port);
|
||||
lg::info("[XSocketServer:{}] initialized", tcp_port);
|
||||
post_init();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -259,10 +259,10 @@ struct Texture {
|
||||
};
|
||||
|
||||
// Tfrag trees have several kinds:
|
||||
enum class TFragmentTreeKind { NORMAL, TRANS, DIRT, ICE, LOWRES, LOWRES_TRANS, INVALID };
|
||||
enum class TFragmentTreeKind { NORMAL, TRANS, DIRT, ICE, LOWRES, LOWRES_TRANS, WATER, INVALID };
|
||||
|
||||
constexpr const char* tfrag_tree_names[] = {"normal", "trans", "dirt", "ice",
|
||||
"lowres", "lowres-trans", "invalid"};
|
||||
constexpr const char* tfrag_tree_names[] = {"normal", "trans", "dirt", "ice",
|
||||
"lowres", "lowres-trans", "water", "invalid"};
|
||||
|
||||
// A tfrag model
|
||||
struct TfragTree {
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "common/log/log.h"
|
||||
|
||||
constexpr float kClusterSize = 4096 * 40; // 100 in-game meters
|
||||
constexpr float kMasterOffset = 12000 * 4096;
|
||||
|
||||
std::pair<u64, u16> position_to_cluster_and_offset(float in) {
|
||||
in += kMasterOffset;
|
||||
if (in < 0) {
|
||||
fmt::print("negative: {}\n", in);
|
||||
lg::print("negative: {}\n", in);
|
||||
}
|
||||
ASSERT(in >= 0);
|
||||
int cluster_cell = (in / kClusterSize);
|
||||
@@ -69,4 +71,4 @@ void pack_tfrag_vertices(tfrag3::PackedTfragVertices* result,
|
||||
}
|
||||
|
||||
ASSERT(next_cluster_idx < UINT16_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "common/dma/dma_chain_read.h"
|
||||
#include "common/goal_constants.h"
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/Timer.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
@@ -36,11 +37,11 @@ void diff_dma_chains(DmaFollower ref, DmaFollower dma) {
|
||||
auto ref_tag = ref.current_tag();
|
||||
auto dma_tag = dma.current_tag();
|
||||
if (ref_tag.kind != dma_tag.kind) {
|
||||
fmt::print("Bad dma tag kinds\n");
|
||||
lg::warn("Bad dma tag kinds");
|
||||
}
|
||||
|
||||
if (ref_tag.qwc != dma_tag.qwc) {
|
||||
fmt::print("Bad dma tag qwc: {} {}\n", ref_tag.qwc, dma_tag.qwc);
|
||||
lg::warn("Bad dma tag qwc: {} {}", ref_tag.qwc, dma_tag.qwc);
|
||||
}
|
||||
|
||||
auto ref_result = ref.read_and_advance();
|
||||
@@ -48,19 +49,19 @@ void diff_dma_chains(DmaFollower ref, DmaFollower dma) {
|
||||
|
||||
for (int i = 0; i < (int)ref_result.size_bytes; i++) {
|
||||
if (ref_result.data[i] != dma_result.data[i]) {
|
||||
fmt::print("Bad data ({} vs {}) at {} into transfer: {} {}\n", ref_result.data[i],
|
||||
dma_result.data[i], i, ref_tag.print(), dma_tag.print());
|
||||
lg::error("Bad data ({} vs {}) at {} into transfer: {} {}", ref_result.data[i],
|
||||
dma_result.data[i], i, ref_tag.print(), dma_tag.print());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ref.ended()) {
|
||||
fmt::print("dma ended early\n");
|
||||
lg::warn("dma ended early");
|
||||
}
|
||||
|
||||
if (!dma.ended()) {
|
||||
fmt::print("dma had extra data\n");
|
||||
lg::warn("dma had extra data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,12 +176,12 @@ const DmaData& FixedChunkDmaCopier::run(const void* memory, u32 offset, bool ver
|
||||
auto v2 = flatten_dma(DmaFollower(m_result.data.data(), m_result.start_offset));
|
||||
|
||||
if (ref != v2) {
|
||||
fmt::print("Verification has failed.\n");
|
||||
fmt::print("size diff: {} {}\n", ref.size(), v2.size());
|
||||
lg::error("Verification has failed.");
|
||||
lg::error("size diff: {} {}", ref.size(), v2.size());
|
||||
|
||||
for (size_t i = 0; i < std::min(ref.size(), v2.size()); i++) {
|
||||
if (ref[i] != v2[i]) {
|
||||
fmt::print("first diff at {}\n", i);
|
||||
lg::error("first diff at {}", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -188,10 +189,10 @@ const DmaData& FixedChunkDmaCopier::run(const void* memory, u32 offset, bool ver
|
||||
DmaFollower(m_result.data.data(), m_result.start_offset));
|
||||
ASSERT(false);
|
||||
} else {
|
||||
fmt::print("verification ok: {} bytes\n", ref.size());
|
||||
lg::debug("verification ok: {} bytes", ref.size());
|
||||
}
|
||||
}
|
||||
|
||||
m_result.stats.sync_time_ms = timer.getMs();
|
||||
return m_result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ u32 get_current_tid() {
|
||||
return (u32)GetCurrentThreadId();
|
||||
}
|
||||
#endif
|
||||
#include "common/log/log.h"
|
||||
// clang-format on
|
||||
|
||||
u64 get_current_ts() {
|
||||
@@ -157,18 +158,17 @@ void GlobalProfiler::dump_to_json(const std::string& path) {
|
||||
// ts
|
||||
json_event["ts"] = (event.ts - lowest_ts) / 1000.f;
|
||||
if (event.ts < info.debug) {
|
||||
fmt::print("out of order: {} {} {} ms\n", event.ts / 1000.f, info.debug / 1000.f,
|
||||
(info.debug - event.ts) / 1000000.f);
|
||||
fmt::print(" idx: {}, range {} {}\n", event_idx, info.lowest_at_target,
|
||||
info.highest_at_target);
|
||||
fmt::print(" now: {}\n", m_next_idx);
|
||||
lg::debug("out of order: {} {} {} ms", event.ts / 1000.f, info.debug / 1000.f,
|
||||
(info.debug - event.ts) / 1000000.f);
|
||||
lg::debug(" idx: {}, range {} {}", event_idx, info.lowest_at_target, info.highest_at_target);
|
||||
lg::debug(" now: {}", m_next_idx);
|
||||
}
|
||||
info.debug = event.ts;
|
||||
}
|
||||
|
||||
for (auto& t : info_per_thread) {
|
||||
fmt::print("thread: {}: {} -> {}\n", t.first, t.second.lowest_at_target,
|
||||
t.second.highest_at_target);
|
||||
lg::debug("thread: {}: {} -> {}", t.first, t.second.lowest_at_target,
|
||||
t.second.highest_at_target);
|
||||
}
|
||||
|
||||
file_util::write_text_file(path, json.dump());
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "Reader.h"
|
||||
|
||||
#include "common/goos/PrettyPrinter2.h"
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/Assert.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
+11
-5
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "ReplUtils.h"
|
||||
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/FileUtil.h"
|
||||
#include "common/util/FontUtils.h"
|
||||
|
||||
@@ -291,11 +292,16 @@ Object Reader::internal_read(std::shared_ptr<SourceText> text,
|
||||
ts.seek_past_whitespace_and_comments();
|
||||
|
||||
// read list!
|
||||
auto objs = read_list(ts, false);
|
||||
if (add_top_level) {
|
||||
return PairObject::make_new(SymbolObject::make_new(symbolTable, "top-level"), objs);
|
||||
} else {
|
||||
return objs;
|
||||
try {
|
||||
auto objs = read_list(ts, false);
|
||||
if (add_top_level) {
|
||||
return PairObject::make_new(SymbolObject::make_new(symbolTable, "top-level"), objs);
|
||||
} else {
|
||||
return objs;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
lg::print("{}", e.what());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-7
@@ -44,12 +44,12 @@ void log_message(level log_level, LogTime& now, const char* message) {
|
||||
char date_time_buffer[128];
|
||||
time_t now_seconds = now.tv.tv_sec;
|
||||
auto now_milliseconds = now.tv.tv_usec / 1000;
|
||||
strftime(date_time_buffer, 128, "%Y-%m-%d %H:%M:%S", localtime(&now_seconds));
|
||||
std::string date_string = fmt::format("[{}:{:03d}]", date_time_buffer, now_milliseconds);
|
||||
strftime(date_time_buffer, 128, "%M:%S", localtime(&now_seconds));
|
||||
std::string time_string = fmt::format("[{}:{:03d}]", date_time_buffer, now_milliseconds);
|
||||
#else
|
||||
char date_time_buffer[128];
|
||||
strftime(date_time_buffer, 128, "%Y-%m-%d %H:%M:%S", localtime(&now.tim));
|
||||
std::string date_string = fmt::format("[{}]", date_time_buffer);
|
||||
strftime(date_time_buffer, 128, "%M:%S", localtime(&now.tim));
|
||||
std::string time_string = fmt::format("[{}]", date_time_buffer);
|
||||
#endif
|
||||
|
||||
{
|
||||
@@ -57,7 +57,7 @@ void log_message(level log_level, LogTime& now, const char* message) {
|
||||
if (gLogger.fp && log_level >= gLogger.file_log_level) {
|
||||
// log to file
|
||||
std::string file_string =
|
||||
fmt::format("{} [{}] {}\n", date_string, log_level_names[int(log_level)], message);
|
||||
fmt::format("{} [{}] {}\n", time_string, log_level_names[int(log_level)], message);
|
||||
fwrite(file_string.c_str(), file_string.length(), 1, gLogger.fp);
|
||||
if (log_level >= gLogger.flush_level) {
|
||||
fflush(gLogger.fp);
|
||||
@@ -65,17 +65,43 @@ void log_message(level log_level, LogTime& now, const char* message) {
|
||||
}
|
||||
|
||||
if (log_level >= gLogger.stdout_log_level) {
|
||||
fmt::print("{} [", date_string);
|
||||
fmt::print("{} [", time_string);
|
||||
fmt::print(fg(log_colors[int(log_level)]), "{}", log_level_names[int(log_level)]);
|
||||
fmt::print("] {}\n", message);
|
||||
if (log_level >= gLogger.flush_level) {
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log_level == level::die) {
|
||||
exit(-1);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
if (gLogger.fp) {
|
||||
fflush(gLogger.fp);
|
||||
}
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void log_print(const char* message) {
|
||||
{
|
||||
// We always immediately flush prints because since it has no associated level
|
||||
// it could be anything from a fatal error to a useless debug log.
|
||||
std::lock_guard<std::mutex> lock(gLogger.mutex);
|
||||
if (gLogger.fp) {
|
||||
// Log to File
|
||||
std::string msg(message);
|
||||
fwrite(msg.c_str(), msg.length(), 1, gLogger.fp);
|
||||
fflush(gLogger.fp);
|
||||
}
|
||||
|
||||
if (gLogger.stdout_log_level < lg::level::off) {
|
||||
fmt::print(message);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
#include "third-party/fmt/color.h"
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
namespace lg {
|
||||
@@ -27,6 +28,7 @@ enum class level { trace = 0, debug = 1, info = 2, warn = 3, error = 4, die = 5,
|
||||
namespace internal {
|
||||
// log implementation stuff, not to be called by the user
|
||||
void log_message(level log_level, LogTime& now, const char* message);
|
||||
void log_print(const char* message);
|
||||
} // namespace internal
|
||||
|
||||
void set_file(const std::string& filename);
|
||||
@@ -49,6 +51,17 @@ void log(level log_level, const std::string& format, Args&&... args) {
|
||||
internal::log_message(log_level, now, formatted_message.c_str());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void print(const std::string& format, Args&&... args) {
|
||||
std::string formatted_message = fmt::format(format, std::forward<Args>(args)...);
|
||||
internal::log_print(formatted_message.c_str());
|
||||
}
|
||||
template <typename... Args>
|
||||
void print(const fmt::text_style& ts, const std::string& format, Args&&... args) {
|
||||
std::string formatted_message = fmt::format(ts, format, std::forward<Args>(args)...);
|
||||
internal::log_print(formatted_message.c_str());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void trace(const std::string& format, Args&&... args) {
|
||||
log(level::trace, format, std::forward<Args>(args)...);
|
||||
|
||||
@@ -225,6 +225,15 @@ class Vector {
|
||||
return result + "]";
|
||||
}
|
||||
|
||||
std::string to_string_hex_word() const {
|
||||
std::string result = "[";
|
||||
for (auto x : m_data) {
|
||||
result.append(fmt::format("0x{:08x} ", x));
|
||||
}
|
||||
result.pop_back();
|
||||
return result + "]";
|
||||
}
|
||||
|
||||
T* data() { return m_data; }
|
||||
const T* data() const { return m_data; }
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ void GameSubtitleGroups::hydrate_from_asset_file() {
|
||||
m_groups[key] = val.get<std::vector<std::string>>();
|
||||
}
|
||||
} catch (std::exception& ex) {
|
||||
fmt::print("Bad subtitle group entry - {} - {}", key, ex.what());
|
||||
lg::print("Bad subtitle group entry - {} - {}", key, ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/Assert.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
@@ -196,8 +197,8 @@ std::string Type::get_name() const {
|
||||
|
||||
std::string Type::get_runtime_name() const {
|
||||
if (!m_allow_in_runtime) {
|
||||
fmt::print("[TypeSystem] Tried to use type {} as a runtime type, which is not allowed.\n",
|
||||
get_name());
|
||||
lg::print("[TypeSystem] Tried to use type {} as a runtime type, which is not allowed.\n",
|
||||
get_name());
|
||||
throw std::runtime_error("get_runtime_name");
|
||||
}
|
||||
return m_runtime_name;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "TypeSystem.h"
|
||||
|
||||
#include "common/log/log.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
namespace {
|
||||
@@ -452,8 +454,8 @@ void try_reverse_lookup(const FieldReverseLookupInput& input,
|
||||
FieldReverseMultiLookupOutput* output,
|
||||
int max_count) {
|
||||
if (debug_reverse_lookup) {
|
||||
fmt::print(" try_reverse_lookup on {} offset {} deref {} stride {}\n", input.base_type.print(),
|
||||
input.offset, input.deref.has_value(), input.stride);
|
||||
lg::debug(" try_reverse_lookup on {} offset {} deref {} stride {}", input.base_type.print(),
|
||||
input.offset, input.deref.has_value(), input.stride);
|
||||
}
|
||||
|
||||
auto base_input_type = input.base_type.base_type();
|
||||
@@ -484,15 +486,15 @@ FieldReverseLookupOutput TypeSystem::reverse_field_lookup(
|
||||
|
||||
/*
|
||||
if (multi_result.results.size() > 1) {
|
||||
fmt::print("Multiple:\n");
|
||||
lg::print("Multiple:\n");
|
||||
for (auto& result : multi_result.results) {
|
||||
fmt::print(" [{}] [{}] ", result.total_score, result.result_type.print());
|
||||
lg::print(" [{}] [{}] ", result.total_score, result.result_type.print());
|
||||
for (auto& tok : result.tokens) {
|
||||
fmt::print("{} ", tok.print());
|
||||
lg::print("{} ", tok.print());
|
||||
}
|
||||
fmt::print("\n");
|
||||
lg::print("\n");
|
||||
}
|
||||
fmt::print("\n\n\n");
|
||||
lg::print("\n\n\n");
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -510,8 +512,8 @@ FieldReverseMultiLookupOutput TypeSystem::reverse_field_multi_lookup(
|
||||
const FieldReverseLookupInput& input,
|
||||
int max_count) const {
|
||||
if (debug_reverse_lookup) {
|
||||
fmt::print("reverse_field_lookup on {} offset {} deref {} stride {}\n", input.base_type.print(),
|
||||
input.offset, input.deref.has_value(), input.stride);
|
||||
lg::debug("reverse_field_lookup on {} offset {} deref {} stride {}", input.base_type.print(),
|
||||
input.offset, input.deref.has_value(), input.stride);
|
||||
}
|
||||
|
||||
FieldReverseMultiLookupOutput result;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "common/log/log.h"
|
||||
#include "common/util/Assert.h"
|
||||
#include "common/util/math_util.h"
|
||||
|
||||
@@ -18,11 +19,11 @@
|
||||
namespace {
|
||||
template <typename... Args>
|
||||
[[noreturn]] void throw_typesystem_error(const std::string& str, Args&&... args) {
|
||||
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "-- Type Error! --\n");
|
||||
lg::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "-- Type Error! --\n");
|
||||
if (!str.empty() && str.back() == '\n') {
|
||||
fmt::print(fg(fmt::color::yellow), str, std::forward<Args>(args)...);
|
||||
lg::print(fg(fmt::color::yellow), str, std::forward<Args>(args)...);
|
||||
} else {
|
||||
fmt::print(fg(fmt::color::yellow), str + '\n', std::forward<Args>(args)...);
|
||||
lg::print(fg(fmt::color::yellow), str + '\n', std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
@@ -63,8 +64,8 @@ Type* TypeSystem::add_type(const std::string& name, std::unique_ptr<Type> type)
|
||||
if (m_allow_redefinition ||
|
||||
std::find(m_types_allowed_to_be_redefined.begin(), m_types_allowed_to_be_redefined.end(),
|
||||
kv->second->get_name()) != m_types_allowed_to_be_redefined.end()) {
|
||||
fmt::print("[TypeSystem] Type {} was originally\n{}\nand is redefined as\n{}\n",
|
||||
kv->second->get_name(), kv->second->print(), type->print());
|
||||
lg::print("[TypeSystem] Type {} was originally\n{}\nand is redefined as\n{}\n",
|
||||
kv->second->get_name(), kv->second->print(), type->print());
|
||||
// extra dangerous, we have allowed type redefinition!
|
||||
|
||||
// keep the unique_ptr around, just in case somebody references this old type pointer.
|
||||
@@ -1530,11 +1531,11 @@ bool TypeSystem::typecheck_and_throw(const TypeSpec& expected,
|
||||
if (!success) {
|
||||
if (print_on_error) {
|
||||
if (error_source_name.empty()) {
|
||||
fmt::print("[TypeSystem] Got type \"{}\" when expecting \"{}\"\n", actual.print(),
|
||||
expected.print());
|
||||
lg::print("[TypeSystem] Got type \"{}\" when expecting \"{}\"\n", actual.print(),
|
||||
expected.print());
|
||||
} else {
|
||||
fmt::print("[TypeSystem] For {}, got type \"{}\" when expecting \"{}\"\n",
|
||||
error_source_name, actual.print(), expected.print());
|
||||
lg::print("[TypeSystem] For {}, got type \"{}\" when expecting \"{}\"\n", error_source_name,
|
||||
actual.print(), expected.print());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "deftype.h"
|
||||
|
||||
#include "common/goos/ParseHelpers.h"
|
||||
#include "common/log/log.h"
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
|
||||
@@ -402,7 +403,7 @@ StructureDefResult parse_structure_def(
|
||||
fmt::format("Process heap underflow in type {}: heap-base is {} vs. auto-detected {}",
|
||||
type->get_name(), flags.heap_base, auto_hb));
|
||||
//} else if (flags.heap_base != auto_hb) {
|
||||
// fmt::print("Type {} has manual heap-base ({} vs {}). This is fine. \n", type->get_name(),
|
||||
// lg::print("Type {} has manual heap-base ({} vs {}). This is fine. \n", type->get_name(),
|
||||
// flags.heap_base, auto_hb);
|
||||
}
|
||||
}
|
||||
@@ -623,14 +624,14 @@ DeftypeResult parse_deftype(const goos::Object& deftype,
|
||||
new_type->set_pack(true);
|
||||
}
|
||||
if (sr.allow_misaligned) {
|
||||
fmt::print(
|
||||
lg::print(
|
||||
"[TypeSystem] :allow-misaligned was set on {}, which is a basic and cannot "
|
||||
"be misaligned\n",
|
||||
name);
|
||||
throw std::runtime_error("invalid pack option on basic");
|
||||
}
|
||||
if (sr.always_stack_singleton) {
|
||||
fmt::print(
|
||||
lg::print(
|
||||
"[TypeSystem] :always-stack-singleton was set on {}, which is a basic and cannot "
|
||||
"be a stack singleton\n",
|
||||
name);
|
||||
|
||||
@@ -87,6 +87,22 @@ TypeSpec get_state_handler_type(StateHandler kind, const TypeSpec& state_type) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> get_state_handler_arg_names(StateHandler kind) {
|
||||
switch (kind) {
|
||||
case StateHandler::CODE:
|
||||
// can have args, but are arbitrary
|
||||
case StateHandler::ENTER:
|
||||
case StateHandler::TRANS:
|
||||
case StateHandler::POST:
|
||||
case StateHandler::EXIT:
|
||||
return {};
|
||||
case StateHandler::EVENT:
|
||||
return {"proc", "arg1", "event-type", "event"};
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
TypeSpec func_to_state_type(const TypeSpec& func_type, const TypeSpec& proc_type) {
|
||||
TypeSpec result("state");
|
||||
|
||||
@@ -17,6 +17,7 @@ StateHandler handler_name_to_kind(const std::string& name);
|
||||
std::string handler_kind_to_name(StateHandler kind);
|
||||
TypeSpec get_state_handler_type(const std::string& handler_name, const TypeSpec& state_type);
|
||||
TypeSpec get_state_handler_type(StateHandler kind, const TypeSpec& state_type);
|
||||
std::vector<std::string> get_state_handler_arg_names(StateHandler kind);
|
||||
|
||||
std::optional<TypeSpec> get_state_type_from_enter_and_code(const TypeSpec& enter_func_type,
|
||||
const TypeSpec& code_func_type,
|
||||
|
||||
@@ -6,20 +6,23 @@
|
||||
#include <cstdlib>
|
||||
#include <string_view>
|
||||
|
||||
#include "common/log/log.h"
|
||||
|
||||
void private_assert_failed(const char* expr,
|
||||
const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
const char* msg) {
|
||||
if (!msg || msg[0] == '\0') {
|
||||
fprintf(stderr, "Assertion failed: '%s'\n\tSource: %s:%d\n\tFunction: %s\n", expr, file, line,
|
||||
function);
|
||||
std::string log = fmt::format("Assertion failed: '{}'\n\tSource: {}:{}\n\tFunction: {}\n", expr,
|
||||
file, line, function);
|
||||
lg::die(log);
|
||||
} else {
|
||||
fprintf(stderr, "Assertion failed: '%s'\n\tMessage: %s\n\tSource: %s:%d\n\tFunction: %s\n",
|
||||
expr, msg, file, line, function);
|
||||
std::string log =
|
||||
fmt::format("Assertion failed: '{}'\n\tMessage: {}\n\tSource: {}:{}\n\tFunction: {}\n",
|
||||
expr, msg, file, line, function);
|
||||
lg::die(log);
|
||||
}
|
||||
fflush(stdout); // ensure any stdout logs are flushed before we terminate
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,14 @@
|
||||
#define ASSERT(EX) \
|
||||
(void)((EX) || (private_assert_failed(#EX, __FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
|
||||
|
||||
#define ASSERT_NOT_REACHED() \
|
||||
(void)((private_assert_failed("not reached", __FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
|
||||
|
||||
#define ASSERT_MSG(EXPR, STR) \
|
||||
(void)((EXPR) || (private_assert_failed(#EXPR, __FILE__, __LINE__, __PRETTY_FUNCTION__, STR), 0))
|
||||
|
||||
#define ASSERT_NOT_REACHED_MSG(STR) \
|
||||
(void)((private_assert_failed("not reached", __FILE__, __LINE__, __PRETTY_FUNCTION__, STR), 0))
|
||||
#else
|
||||
|
||||
#define ASSERT(EX) ((void)0)
|
||||
|
||||
@@ -139,7 +139,7 @@ bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
if (project_path_override) {
|
||||
gFilePathInfo.path_to_data = *project_path_override;
|
||||
gFilePathInfo.initialized = true;
|
||||
fmt::print("Using explicitly set project path: {}\n", project_path_override->string());
|
||||
lg::info("Using explicitly set project path: {}", project_path_override->string());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
if (data_path) {
|
||||
gFilePathInfo.path_to_data = *data_path;
|
||||
gFilePathInfo.initialized = true;
|
||||
fmt::print("Using data path: {}\n", data_path->string());
|
||||
lg::info("Using data path: {}", data_path->string());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
if (development_repo_path) {
|
||||
gFilePathInfo.path_to_data = *development_repo_path;
|
||||
gFilePathInfo.initialized = true;
|
||||
fmt::print("Using development repo path: {}\n", *development_repo_path);
|
||||
lg::info("Using development repo path: {}", *development_repo_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
fmt::print("Failed to initialize project path.\n");
|
||||
lg::error("Failed to initialize project path.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user