Fixing issues with swap command and character input #1
Open
anthonykozar wants to merge 6 commits intoTryItOnline:masterfrom
Open
Fixing issues with swap command and character input #1anthonykozar wants to merge 6 commits intoTryItOnline:masterfrom
anthonykozar wants to merge 6 commits intoTryItOnline:masterfrom
Conversation
…rs when piping or redirecting input to the interpreter.
Reverted changes to getch.py. Only use getch() if stdin is a tty. This fixes an exception that occurs when piping or redirecting input to the interpreter. gaot_plus_plus.py seems like a better place to put this logic since the purpose of the getch module is to provide unbuffered input from a terminal. There is a small difference in the behavior of these two solutions when running a simple "cat" program with stdin redirected from a file. The former stops reading from the input file if an EOF byte (0x04) is encountered. The new solution stops reading if a null byte (0x00) is encountered. I don't think there is a solution for copying arbitrary binary files since Gaot++ doesn't provide a way to detect the true end of a file. (If stdin is a tty, then control-D still causes the cat program to exit).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 bleeeeeeeeeetOn 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