Skip to content

Commit

Permalink
Fix TSP
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrk24 committed Sep 15, 2024
1 parent ddc4198 commit b37d108
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. See [Keep a

### Changed

- `TSP` is now correctly identified by the disassembler, rather than becoming `BNG`.
- The web interface now indicates when the URL is invalid.

## [1.8.2] - 2024-05-03
Expand Down
6 changes: 6 additions & 0 deletions src/instruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public:
return instruction(operation::BNG, arg);
}

static CONSTEXPR_UNION instruction spawn_to(pair<pair<size_t>> choice) noexcept {
argument arg;
arg.choice = choice;
return instruction(operation::TSP, arg);
}

constexpr bool is_exit() const noexcept { return m_op == operation::EXT || m_op == operation::TKL; }
constexpr bool is_join() const noexcept { return m_op == operation::TJN; }
constexpr bool is_nop() const noexcept { return m_op == operation::NOP; }
Expand Down
6 changes: 5 additions & 1 deletion src/instruction_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ void instruction_scanner::build_state() {
second_dest = loc->second;
}

fragment->push_back(instruction::branch_to({ first_dest, second_dest }));
if (op == static_cast<int24_t>(THR_E) || op == static_cast<int24_t>(THR_W)) {
fragment->push_back(instruction::spawn_to({ first_dest, second_dest }));
} else {
fragment->push_back(instruction::branch_to({ first_dest, second_dest }));
}
} else {
fragment->push_back(instruction::jump_to(loc->second));
}
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/disassembler/cat.trg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<
> i
, @ #
# o . .
34 changes: 33 additions & 1 deletion tests/cli/disassembler/index.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
#!/bin/bash

set -euo pipefail
set -uo pipefail

folder=$(dirname "$0")

# https://stackoverflow.com/a/20460402/6253337
string_contain () {
case "$2" in
*"$1"*)
return 0
;;
*)
return 1
;;
esac
}

tsp_disassembly=$($TRILANGLE -D "${folder}/tsp.trg")

if string_contain BNG "$tsp_disassembly"
then
exit 1
fi

set -e

string_contain TSP "$tsp_disassembly"

test 6 -eq "$($TRILANGLE -D "${folder}/nopful.trg" | wc -l)"
test 1 -eq "$($TRILANGLE -Dn "${folder}/nopful.trg" | wc -l)"

cat_disassembly=$($TRILANGLE -Dn "${folder}/cat.trg")
test "${cat_disassembly//$'\r'/}" = $'0.1:\tGTC
0.2:\tBNG 2.0
1.0:\tPTC
1.1:\tPOP
1.5:\tJMP 0.1
2.0:\tPOP
2.2:\tEXT'
2 changes: 2 additions & 0 deletions tests/cli/disassembler/tsp.trg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.
\ {

0 comments on commit b37d108

Please sign in to comment.