diff options
-rw-r--r-- | lib94/warrior.cpp | 38 | ||||
-rw-r--r-- | warriors/big-nothing.red | 2 | ||||
-rw-r--r-- | warriors/dwarf-replicator.red | 18 | ||||
-rw-r--r-- | warriors/epson.red | 20 |
4 files changed, 38 insertions, 40 deletions
diff --git a/lib94/warrior.cpp b/lib94/warrior.cpp index 6efa409..47c9b02 100644 --- a/lib94/warrior.cpp +++ b/lib94/warrior.cpp @@ -383,22 +383,7 @@ namespace lib94 { for (char &ch : line) ch = tolower(ch); - while (true) { - size_t colon = line.find(':'); - if (colon == std::string::npos) - break; - - std::string label = trim_spaces(line.substr(0, colon)); - line = line.substr(colon + 1); - - if (!valid_label(label)) - return std::string("bad label on line ") + std::to_string(on_line); - if (label_offsets.contains(label) || macro_definitions.contains(label)) - return std::string("duplicate label on line ") + std::to_string(on_line); - - label_offsets[label] = instructions.size(); - } - + return_after_label: line = trim_spaces(line); if (line == "") continue; @@ -432,8 +417,12 @@ namespace lib94 { future_instruction instr; instr.source_line = on_line; - std::string opcode_str = line.substr(0, 3); - line = trim_spaces(line.substr(3)); + size_t sep = line.find_first_of(" ."); + if (sep == std::string::npos) + sep = line.size(); + + std::string opcode_str = trim_spaces(line.substr(0, sep)); + line = trim_spaces(line.substr(sep)); if (opcode_str == "org" || opcode_str == "end") { if (org.has_value()) @@ -451,8 +440,17 @@ namespace lib94 { auto opcode_it = opcode_names.find(opcode_str); - if (opcode_it == opcode_names.end()) - return std::string("unknown opcode on line ") + std::to_string(on_line); + if (opcode_it == opcode_names.end()) { + if (!valid_label(opcode_str)) + return std::string("bad label or unknown opcode on line ") + std::to_string(on_line); + + if (label_offsets.contains(opcode_str) || macro_definitions.contains(opcode_str)) + return std::string("duplicate label on line ") + std::to_string(on_line); + + label_offsets[opcode_str] = (number_t)instructions.size(); + + goto return_after_label; + } instr.op = opcode_it->second; diff --git a/warriors/big-nothing.red b/warriors/big-nothing.red index a9aa6c9..1d69675 100644 --- a/warriors/big-nothing.red +++ b/warriors/big-nothing.red @@ -1,7 +1,7 @@ ;author Benji Dial ;name Big Nothing -start: +start nop nop nop diff --git a/warriors/dwarf-replicator.red b/warriors/dwarf-replicator.red index 01a1494..c5022a2 100644 --- a/warriors/dwarf-replicator.red +++ b/warriors/dwarf-replicator.red @@ -3,27 +3,27 @@ ;not a particularly good warrior, but is sufficient to test a few things -start: +start mov 0, 2908 nop }start, >start jmp 2 dat - seq.a #end - start, start + seq.a #the_end - start, start jmp start jmp 2 dat - sub.ab #end - start, start + sub.ab #the_end - start, start spl @start jmp 2, <start dat -dwarf: - mov end, end + 4 +dwarf + mov the_end, the_end + 4 add.ab #4, dwarf jmp 2 @@ -35,8 +35,8 @@ dwarf: dat -core_clear: - mov end, end + 1 +core_clear + mov the_end, the_end + 1 add.ab #1, -1 jmp 2 @@ -48,8 +48,8 @@ core_clear: dat - mov.ab #end + 1, core_clear + mov.ab #the_end + 1, core_clear jmp core_clear dat -end: +the_end diff --git a/warriors/epson.red b/warriors/epson.red index a327807..eeceee1 100644 --- a/warriors/epson.red +++ b/warriors/epson.red @@ -3,13 +3,13 @@ period equ 10 -scan_init equ end - (end - scan) % period + period +scan_init equ the_end - (the_end - scan) % period + period -scan: +scan seq.i -period, scan_init jmp found -found_ret: +found_ret add.ab #period, scan seq.ab scan, scan jmp scan @@ -17,26 +17,26 @@ found_ret: add.f scan_add, scan jmn.a scan, scan -clear: - mov end, - 1 +clear + mov the_end, - 1 sub.ab #2, clear - seq.ab #end - clear - (end - clear) % 2 + 3, clear + seq.ab #the_end - clear - (the_end - clear) % 2 + 3, clear jmp clear mov.ab #-1, clear jmp clear -scan_add: +scan_add dat 2, period + scan_init + 2 -found: +found mov bomb, >scan mov bomb + 1, @scan jmp found_ret, <scan -bomb: +bomb spl 1 jmp bomb -end: +the_end |