Skip to content

Commit 9e2ad2f

Browse files
committed
fix: PushChar handling in parser
1 parent f472477 commit 9e2ad2f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/bytecode_parser/scenarios/CommandFactory.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
namespace ovum::bytecode::parser {
88

9-
const std::unordered_set<std::string> CommandFactory::kStringCommands = {"PushString", "PushChar"};
9+
const std::unordered_set<std::string> CommandFactory::kStringCommands = {"PushString"};
10+
const std::unordered_set<std::string> CommandFactory::kCharCommands = {"PushChar"};
1011

1112
const std::unordered_set<std::string> CommandFactory::kIntegerCommands = {
1213
"PushInt", "PushByte", "Rotate", "LoadLocal", "SetLocal", "LoadStatic", "SetStatic", "GetField", "SetField"};
@@ -105,6 +106,23 @@ std::expected<std::unique_ptr<vm::execution_tree::IExecutable>, BytecodeParserEr
105106
return std::move(cmd.value());
106107
}
107108

109+
if (kCharCommands.contains(cmd_name)) {
110+
std::expected<int64_t, BytecodeParserError> value = ctx->ConsumeIntLiteral();
111+
112+
if (!value) {
113+
return std::unexpected(value.error());
114+
}
115+
116+
std::expected<std::unique_ptr<vm::execution_tree::IExecutable>, std::out_of_range> cmd =
117+
vm::execution_tree::CreateIntegerCommandByName(cmd_name, value.value());
118+
119+
if (!cmd) {
120+
return std::unexpected(BytecodeParserError("Failed to create char command: " + cmd_name));
121+
}
122+
123+
return std::move(cmd.value());
124+
}
125+
108126
std::expected<std::unique_ptr<vm::execution_tree::IExecutable>, std::out_of_range> cmd =
109127
vm::execution_tree::CreateSimpleCommandByName(cmd_name);
110128

lib/bytecode_parser/scenarios/CommandFactory.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CommandFactory : public ICommandFactory {
2727
static const std::unordered_set<std::string> kFloatCommands;
2828
static const std::unordered_set<std::string> kBooleanCommands;
2929
static const std::unordered_set<std::string> kIdentCommands;
30+
static const std::unordered_set<std::string> kCharCommands;
3031
};
3132

3233
} // namespace ovum::bytecode::parser

0 commit comments

Comments
 (0)