context wrapper & t6 bug fixing

This commit is contained in:
xensik
2022-02-21 16:08:55 +01:00
parent 6980506e88
commit 9b7eb28b84
18 changed files with 309 additions and 145 deletions

View File

@ -19,6 +19,8 @@ struct block
bool is_dev;
block() : is_dev(false), abort(abort_t::abort_none) {}
block(const std::string& lbreak, const std::string& lcont)
: is_dev(false), abort(abort_t::abort_none), loc_break(lbreak), loc_continue(lcont) {}
};
} // namespace xsk::arc

View File

@ -17,7 +17,6 @@ public:
virtual auto output() -> assembly::ptr = 0;
virtual auto output_data() -> std::vector<std::uint8_t> = 0;
virtual void compile(const std::string& file, std::vector<std::uint8_t>& data) = 0;
virtual void read_callback(std::function<std::vector<std::uint8_t>(const std::string&)> func) = 0;
};
} // namespace xsk::arc

View File

@ -0,0 +1,26 @@
// Copyright 2022 xensik. All rights reserved.
//
// Use of this source code is governed by a GNU GPLv3 license
// that can be found in the LICENSE file.
#pragma once
namespace xsk::arc
{
class context
{
public:
using ptr = std::unique_ptr<context>;
virtual ~context() = default;
virtual void init(build mode, read_cb_type callback) = 0;
virtual void cleanup() = 0;
virtual auto assembler() -> assembler& = 0;
virtual auto disassembler() -> disassembler& = 0;
virtual auto compiler() -> compiler& = 0;
virtual auto decompiler() -> decompiler& = 0;
};
} // namespace xsk::arc

View File

@ -8,10 +8,12 @@
namespace xsk::arc
{
using read_cb_type = std::function<std::vector<std::uint8_t>(const std::string&)>;
enum class build
{
dev,
prod,
dev,
};
enum class abort_t

View File

@ -37,3 +37,4 @@
#include "arc/interfaces/disassembler.hpp"
#include "arc/interfaces/compiler.hpp"
#include "arc/interfaces/decompiler.hpp"
#include "arc/interfaces/context.hpp"

View File

@ -227,4 +227,86 @@ auto string::parse_code(std::string& line) -> std::vector<std::string>
return data;
}
auto string::float_string(float value) -> std::string
{
enum flags_t : std::uint8_t { none = 0, negative = 1, integer = 2, has_exp = 4, exp_neg = 8 };
auto str = utils::string::va("%g", value);
auto flags = integer | (str[0] == '-' ? negative : none);
for (auto i = 1; i < str.size(); i++)
{
if (str[i] == '-') flags |= exp_neg;
else if (str[i] == 'e') flags |= has_exp;
else if ( str[i] == '.') flags &= ~integer;
}
if (!(flags & has_exp))
return str += (flags & integer) ? ".0" : "";
std::string p_int;
std::string p_dec;
std::string p_exp;
if(flags & integer)
{
auto i = (flags & negative) ? 1 : 0;
while (str[i] != 'e')
p_int.push_back(str[i++]);
i += 2;
while (i < str.size())
p_exp.push_back(str[i++]);
auto offset = std::stoi(p_exp);
if ((flags & exp_neg))
offset -= p_int.size();
while (offset--)
{
if((flags & exp_neg))
p_int.insert(p_int.begin(), '0');
else
p_int.push_back('0');
}
return ((flags & negative) ? "-" : "") + ((flags & exp_neg) ? "0." + p_int : p_int + ".0");
}
else
{
auto i = (flags & negative) ? 1 : 0;
while (str[i] != '.')
p_int.push_back(str[i++]);
i++;
while (str[i] != 'e')
p_dec.push_back(str[i++]);
i += 2;
while (i < str.size())
p_exp.push_back(str[i++]);
auto offset = std::stoi(p_exp);
offset -= (flags & exp_neg) ? p_int.size() : p_dec.size();
while (offset--)
{
if(flags & exp_neg)
p_int.insert(p_int.begin(), '0');
else
p_dec.push_back('0');
}
return ((flags & negative) ? "-" : "") + ((flags & exp_neg) ? "0." + p_int + p_dec : p_int + p_dec + ".0");
}
}
} // namespace xsk::utils

View File

@ -37,6 +37,7 @@ public:
static auto split(std::string& str, char delimiter) -> std::vector<std::string>;
static auto clean_buffer_lines(std::vector<std::uint8_t>& buffer) -> std::vector<std::string>;
static auto parse_code(std::string& line) -> std::vector<std::string>;
static auto float_string(float value) -> std::string;
};
} // namespace xsk::utils