Fixing issues with swap command and character input #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found multiple problems with this implementation of Gaot++ while using it from TryItOnline. The first is that the swap command doesn't swap the top two entries on the stack. It pops them off and then pushes them back on in the same order they were in before. The following program demonstrates this bug.
The program pushes 1 and then 2 onto the stack, swaps them, and then outputs the top two entries of the stack as numbers. It should produce the output "12" but instead gives "21".
The second issue is that character input throws an exception whenever standard input is not connected to a terminal. This affects Gaot++ programs running on TryItOnline or running from a commandline with input redirection. This simple program should read a single character from stdin and output it as a character:
bleeeeeeeeeeeet bleeeeeeeeeet
On TryItOnline, it produces this exception:
This pull request resolves both of these issues. With these patches, the "cat" program example from esolangs.org can be used to copy the input to the output as expected. (Unless the input contains an embedded NULL character. See the notes on the last commit).
Dec. 8: I've added 3 more commits to this pull request that fix additional bugs. The first commit halts a Gaot++ program when the instruction pointer becomes negative which could happen if the direction of the instruction pointer was reversed and then went past the beginning of the program. Since the interpreter halts a program that reaches the end of its code, it seemed to make sense to halt when in reverse too.
The next two commits fix problems with the rotate command. (Try "baa baaa bleeeeeeeeeeeeeeeet" on TryItOnline). The code previously referenced an undefined variable which produced the exception below and it tried to concatenate a list and an integer which is not allowed. I also made sure that rotate does nothing when the stack is empty.
If you have any questions, please let me know. Thanks!
Anthony Kozar