feat(dev): convert build mode to bit flag (#187)

This commit is contained in:
INeedGames 2024-01-23 15:24:40 -06:00 committed by GitHub
parent 8b03229a19
commit 228293c0bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 40 additions and 16 deletions

View File

@ -29,10 +29,18 @@ enum class instance : u8
enum class build : u8 enum class build : u8
{ {
dev, prod = 0 << 0,
prod, dev_blocks = 1 << 0,
dev_maps = 1 << 1,
dev = dev_blocks | dev_maps,
}; };
inline build operator&(build lhs, build rhs)
{
return static_cast<build>(static_cast<std::underlying_type<build>::type>(lhs) & static_cast<std::underlying_type<build>::type>(rhs));
}
enum class endian : u8 enum class endian : u8
{ {
little, little,

View File

@ -29,10 +29,18 @@ enum class instance : u8
enum class build : u8 enum class build : u8
{ {
dev, prod = 0 << 0,
prod, dev_blocks = 1 << 0,
dev_maps = 1 << 1,
dev = dev_blocks | dev_maps,
}; };
inline build operator&(build lhs, build rhs)
{
return static_cast<build>(static_cast<std::underlying_type<build>::type>(lhs) & static_cast<std::underlying_type<build>::type>(rhs));
}
enum class endian : u8 enum class endian : u8
{ {
little, little,

View File

@ -279,10 +279,14 @@ auto assembler::assemble_function(function& func) -> void
auto assembler::assemble_instruction(instruction const& inst) -> void auto assembler::assemble_instruction(instruction const& inst) -> void
{ {
script_.write<u8>(static_cast<u8>(ctx_->opcode_id(inst.opcode))); script_.write<u8>(static_cast<u8>(ctx_->opcode_id(inst.opcode)));
devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line); if ((ctx_->build() & build::dev_maps) != build::prod)
devmap_.write<u16>(inst.pos.column); {
devmap_count_++; devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line);
devmap_.write<u16>(inst.pos.column);
devmap_count_++;
}
switch (inst.opcode) switch (inst.opcode)
{ {

View File

@ -77,7 +77,7 @@ auto lexer::lex() -> token
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (ctx_->build() == build::dev) if ((ctx_->build() & build::dev_blocks) != build::prod)
{ {
indev_ = true; indev_ = true;
return token{ token::DEVBEGIN, spacing_, loc_ }; return token{ token::DEVBEGIN, spacing_, loc_ };

View File

@ -70,10 +70,14 @@ auto assembler::assemble_function(function const& func) -> void
auto assembler::assemble_instruction(instruction const& inst) -> void auto assembler::assemble_instruction(instruction const& inst) -> void
{ {
script_.write<u8>(ctx_->opcode_id(inst.opcode)); script_.write<u8>(ctx_->opcode_id(inst.opcode));
devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line); if ((ctx_->build() & build::dev_maps) != build::prod)
devmap_.write<u16>(inst.pos.column); {
devmap_count_++; devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line);
devmap_.write<u16>(inst.pos.column);
devmap_count_++;
}
switch (inst.opcode) switch (inst.opcode)
{ {

View File

@ -77,7 +77,7 @@ auto lexer::lex() -> token
if (indev_) if (indev_)
throw comp_error(loc_, "cannot recurse devblock ('/#')"); throw comp_error(loc_, "cannot recurse devblock ('/#')");
if (ctx_->build() == build::dev) if ((ctx_->build() & build::dev_blocks) != build::prod)
{ {
indev_ = true; indev_ = true;
return token{ token::DEVBEGIN, spacing_, loc_ }; return token{ token::DEVBEGIN, spacing_, loc_ };

View File

@ -296,7 +296,7 @@ auto compile_file(game game, mach mach, fs::path file, fs::path rel) -> result
utils::file::save(fs::path{ "compiled" } / rel, result); utils::file::save(fs::path{ "compiled" } / rel, result);
std::cout << fmt::format("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
if (contexts[game][mach]->build() == build::dev) if ((contexts[game][mach]->build() & build::dev_maps) != build::prod)
{ {
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension(".gscmap"), std::get<2>(outbin).data, std::get<2>(outbin).size); utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension(".gscmap"), std::get<2>(outbin).data, std::get<2>(outbin).size);
std::cout << fmt::format("saved developer map {}\n", rel.generic_string()); std::cout << fmt::format("saved developer map {}\n", rel.generic_string());
@ -803,7 +803,7 @@ auto compile_file(game game, mach mach, fs::path const& file, fs::path rel) -> r
utils::file::save(fs::path{ "compiled" } / rel, outbin.first.data, outbin.first.size); utils::file::save(fs::path{ "compiled" } / rel, outbin.first.data, outbin.first.size);
std::cout << fmt::format("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
if (contexts[game][mach]->build() == build::dev) if ((contexts[game][mach]->build() & build::dev_maps) != build::prod)
{ {
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension((rel.extension().string().starts_with(".gsc") ? ".gscmap" : ".cscmap")), outbin.second.data, outbin.second.size); utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension((rel.extension().string().starts_with(".gsc") ? ".gscmap" : ".cscmap")), outbin.second.data, outbin.second.size);
std::cout << fmt::format("saved developer map {}\n", rel.generic_string()); std::cout << fmt::format("saved developer map {}\n", rel.generic_string());