fix ... in F_ARGS opcode assembly

This commit is contained in:
Martin Michelsen
2023-12-11 13:56:00 -08:00
parent bc017578e3
commit d9cdf9804f
+11 -3
View File
@@ -1895,6 +1895,15 @@ std::string assemble_quest_script(const std::string& text) {
if (line_tokens.size() < 2) { if (line_tokens.size() < 2) {
throw runtime_error(string_printf("(line %zu) arguments required for %s", line_num, opcode_def->name)); throw runtime_error(string_printf("(line %zu) arguments required for %s", line_num, opcode_def->name));
} }
strip_trailing_whitespace(line_tokens[1]);
strip_leading_whitespace(line_tokens[1]);
if (starts_with(line_tokens[1], "...")) {
if (!(opcode_def->flags & F_ARGS)) {
throw runtime_error(string_printf("(line %zu) \'...\' can only be used with F_ARGS opcodes", line_num));
}
} else { // Not "..."
auto args = split_context(line_tokens[1], ','); auto args = split_context(line_tokens[1], ',');
if (args.size() != opcode_def->args.size()) { if (args.size() != opcode_def->args.size()) {
throw runtime_error(string_printf("(line %zu) incorrect argument count for %s", line_num, opcode_def->name)); throw runtime_error(string_printf("(line %zu) incorrect argument count for %s", line_num, opcode_def->name));
@@ -1948,9 +1957,7 @@ std::string assemble_quest_script(const std::string& text) {
if (opcode_def->flags & F_ARGS) { if (opcode_def->flags & F_ARGS) {
auto label_it = labels_by_name.find(arg); auto label_it = labels_by_name.find(arg);
if (starts_with(line_tokens[1], "...")) { if (arg.empty()) {
// Args were specified by preceding arg_push calls; nothing to do here
} else if (arg.empty()) {
throw runtime_error("argument is empty"); throw runtime_error("argument is empty");
} else if (label_it != labels_by_name.end()) { } else if (label_it != labels_by_name.end()) {
code_w.put_u8(0x4B); // arg_pushw code_w.put_u8(0x4B); // arg_pushw
@@ -2116,6 +2123,7 @@ std::string assemble_quest_script(const std::string& text) {
throw runtime_error(string_printf("(arg %zu) %s", z + 1, e.what())); throw runtime_error(string_printf("(arg %zu) %s", z + 1, e.what()));
} }
} }
}
if (opcode_def->flags & F_ARGS) { if (opcode_def->flags & F_ARGS) {
if ((opcode_def->opcode & 0xFF00) == 0x0000) { if ((opcode_def->opcode & 0xFF00) == 0x0000) {