From 5cad6c6d89ebef07bccc4fde57276720284c959a Mon Sep 17 00:00:00 2001 From: Jonas Minnberg Date: Sat, 27 Jun 2020 07:56:55 -0700 Subject: [PATCH] Fixed windows issues --- src/any_callable.h | 4 ++-- src/assembler.cpp | 33 ++++++++++++++++----------------- src/functions.cpp | 2 +- src/machine.h | 1 + src/meta.cpp | 4 ++-- src/wrap.cpp | 4 ++-- src/wrap.h | 2 ++ 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/any_callable.h b/src/any_callable.h index c3542b0..e6fc87d 100644 --- a/src/any_callable.h +++ b/src/any_callable.h @@ -16,8 +16,8 @@ ARG get_arg(std::vector const& vec, std::false_type) template ARG get_arg(std::vector const& vec, std::true_type) { - return A < vec.size() ? static_cast(std::any_cast(vec[A])) - : 0.0; + return static_cast(A < vec.size() ? std::any_cast(vec[A]) + : 0.0); } template diff --git a/src/assembler.cpp b/src/assembler.cpp index 632fc52..bceb09e 100644 --- a/src/assembler.cpp +++ b/src/assembler.cpp @@ -395,7 +395,7 @@ void Assembler::setupRules() sym = std::string(lastLabel) + sym; } // LOGI("Symbol:%s", sym); - syms.set(sym, sv[1], sv.line_info().first); + syms.set(sym, sv[1], sv.line()); } else if (sv.size() == 1) { mach->getCurrentSection().pc = number(sv[0]); } @@ -424,7 +424,7 @@ void Assembler::setupRules() } // LOGI("Label %s=%x", label, mach->getPC()); syms.set(label, static_cast(mach->getPC()), - sv.line_info().first); + sv.line()); return sv[0]; }; @@ -446,9 +446,8 @@ void Assembler::setupRules() auto meta = any_cast(sv[i++]); auto text = any_cast(sv[i++]); // Strip trailing spaces - auto p = text.size() - 1; - while (text[p] == ' ' || text[p] == '\t') { - if (p == 0) break; + auto p = (int)text.size() - 1; + while (p >= 0 && (text[p] == ' ' || text[p] == '\t')) { p--; } if (text.size() > p) { @@ -531,7 +530,7 @@ void Assembler::setupRules() auto contents = any_cast(sv[1]); auto name = any_cast(sv[0]); auto res = runTest(name, contents); - syms.set("tests."s + std::string(name), res, sv.line_info().first); + syms.set("tests."s + std::string(name), res, sv.line()); return sv[0]; }; @@ -620,7 +619,7 @@ void Assembler::setupRules() parser["Decimal"] = [&](SV& sv) -> Number { try { return std::stod(sv.c_str(), nullptr); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } @@ -631,7 +630,7 @@ void Assembler::setupRules() parser["Octal"] = [&](SV& sv) -> Number { try { return std::stoi(sv.c_str() + 2, nullptr, 8); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } @@ -642,7 +641,7 @@ void Assembler::setupRules() parser["Multi"] = [&](SV& sv) -> Number { try { return std::stoi(sv.c_str() + 2, nullptr, 4); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } @@ -653,7 +652,7 @@ void Assembler::setupRules() parser["Binary"] = [&](SV& sv) -> Number { try { return std::stoi(sv.c_str() + 2, nullptr, 2); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } @@ -666,7 +665,7 @@ void Assembler::setupRules() const char* ptr = sv.c_str(); if (*ptr == '0') ptr++; return std::stoi(ptr + 1, nullptr, 16); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } @@ -691,12 +690,12 @@ void Assembler::setupRules() try { auto result = static_cast(operation(ope, a, b)); return std::any(result); - } catch (std::out_of_range& e) { + } catch (std::out_of_range&) { if (finalPass) { throw parse_error("Out of range"); } return any_num(0); - } catch (dbz_error& e) { + } catch (dbz_error&) { if (finalPass) { throw parse_error("Division by zero"); } @@ -716,7 +715,7 @@ void Assembler::setupRules() if(sv.size() == 1) { return sv[0]; } - auto index = any_cast(sv[1]); + auto index = number(sv[1]); std::any vec = sv[0]; if (any_cast(&vec) != nullptr) { return any_num(0); @@ -761,9 +760,9 @@ void Assembler::setupRules() case '!': return static_cast(inum == 0); case '<': - return inum & 0xff; + return static_cast(inum & 0xff); case '>': - return inum >> 8; + return static_cast(inum >> 8); default: throw parse_error("Unknown unary operator"); } @@ -782,7 +781,7 @@ void Assembler::setupRules() full = utils::join(parts.begin(), parts.end(), "."); } - val = syms.get(full, sv.line_info().first); + val = syms.get(full, sv.line()); // Set undefined numbers to PC, to increase likelyhood of // correct code generation (less passes) if (val.type() == typeid(Number) && !syms.is_defined(full)) { diff --git a/src/functions.cpp b/src/functions.cpp index fd7ca7c..149b50a 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -52,7 +52,7 @@ void initFunctions(Assembler& a) try { utils::File f{p}; return f.readAll(); - } catch (utils::io_exception& e) { + } catch (utils::io_exception&) { throw parse_error(fmt::format("Could not load {}", name)); } }); diff --git a/src/machine.h b/src/machine.h index 553a6f6..7e0da89 100644 --- a/src/machine.h +++ b/src/machine.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/src/meta.cpp b/src/meta.cpp index 9b055ac..db82818 100644 --- a/src/meta.cpp +++ b/src/meta.cpp @@ -218,7 +218,7 @@ void initMeta(Assembler& a) for (size_t i = 0; i < size; i++) { uint8_t d = vec ? (*vec)[i] : 0; for (auto const& b : blocks) { - a.getSymbols().at("i") = i; + a.getSymbols().at("i") = static_cast(i); a.getSymbols().at("v") = d; auto res = a.evaluateExpression(b); d = number(res); @@ -309,7 +309,7 @@ void initMeta(Assembler& a) if (res >= 0x100000000) { flags = res >> 32; } else { - pc = res; + pc = static_cast(res); } } auto& s = mach.addSection(std::string(name), start); diff --git a/src/wrap.cpp b/src/wrap.cpp index a6085fb..f81ba98 100644 --- a/src/wrap.cpp +++ b/src/wrap.cpp @@ -144,7 +144,7 @@ void ParserWrapper::action( SVWrap s(sv); try { return fn(s); - } catch (dbz_error& e) { + } catch (dbz_error&) { LOGW("DBZ"); return std::any(); } catch (parse_error& e) { @@ -157,7 +157,7 @@ void ParserWrapper::action( throw peg::parse_error(e.what()); } catch (machine_error& e) { throw peg::parse_error(e.what()); - } catch (std::bad_any_cast& e) { + } catch (std::bad_any_cast&) { throw peg::parse_error("Data type error"); } catch (utils::io_exception& e) { throw peg::parse_error(e.what()); diff --git a/src/wrap.h b/src/wrap.h index 95e8bc9..5347383 100644 --- a/src/wrap.h +++ b/src/wrap.h @@ -33,6 +33,8 @@ struct SVWrap template std::vector transform() const; + int line() const { return static_cast(line_info().first);} + template T to(size_t i) const {