-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EOF is not working as intended #96
Comments
ELVM has a stupid ABI. All integer types are unsigned and have the same size (i.e., Since there is no negative number,
showed
by |
I see. I have confirmed that the issue is related to whitespace backend. If I run the code with By the way, is there a reason |
It should return char*, not int. Pointed out in #96.
Wow, I haven't realized I think #97 fixes the both of the issues? Thanks for pointing this out! |
You are so fast! Yes, this fixes both. Actually, it fixes another bug that I haven't mentioned yet :D. The previous version was copying EOF to buffer, just like The only difference in our approaches, your version does nothing and return null pointer if size is 1. Mine puts a null byte at the beginning of the buffer and returns the buffer. I have referred to this implementation to decide that. |
Ah, yours is better! Could you send a PR to re-correct the implementation? If you don't have time for it, I'll do it this night. |
Sure! By the way, there is one more bug. All i/o functions stop when they encounter a null byte in ELVM's implementation. I don't know the reason, but it seems On a side note, using |
Yeah, it's unfortunate we cannot distinguish an EOF and a null byte and it's impossible to handle binary files without preprocessing. If it's a bug rather than a limitation, it's due to the definition of ELVM's GETC instruction. When it reaches to EOF, ELVM implementation should fill 0 instead of -1: Line 169 in c30d33f
I think I chose this definition because some backend esolangs do not distinguish EOF from 0 anyway. For example, many brainfuck implementation fills -1 or 0 when Line 529 in c30d33f
Some backends have more limitations in their inputs. Please check https://github.com/shinh/elvm/blob/master/tools/runtex.sh for example. It converts |
Oh I see. Maybe we can choose some defaults and provide other stuff as options while converting to backends. For example, we can set EOF as -1. However, the user should be able to provide a flag to change it if he wants such as: Still, it might make things too complicated. I am not sure if that's worth it, just an idea. |
I think As for |
This looks good to me. Should I create another issue for the Whitespace backend? So, you said that all numbers should be 24-bit and unsigned. Doesn't this contradict with Whitespace language itself? From my understanding, the Whitespace language should be able to use negative numbers and there is no bit limit for the numbers. So, I should be able to work with a 64-bit number. |
The EIR to WS translator should have no issue as it emits code which limits integers to 24bit range: Line 145 in 18b45bc
It's fine to define a 64bit or 32bit dialect of ELVM IR and support a mode like Line 232 in 18b45bc
|
I have just tested it again with our latest patch, it already works as intended. Both whitespace interpreter and Also, you are right that the translation is still valid even though numbers are 24-bit. I guess everything is working now? :D |
Oh sorry, the bug is still there. I forgot that it works fine if you provide |
By the way, tests for Whitespace backend crashes. This might be related to the issue.
|
Cool! Both are fixed now. There is no overflow and |
While I was trying to investigate some issues with
fgets
implementation, I've noticed that the source of the issue is EOF definition itself.After running the code snippet above, I have got the following result:
As you can see, EOF is 24-bit instead of 32-bit. Therefore,
if (c == EOF)
is always false. This can be seen in the generated EIR code as well:16777215 is simply 0xffffff. This causes some bugs. Even though interpreting the EIR output with
eli
works fine for some cases, it still fails if you try to convert EIR to Whitespace for instance.Since I haven't been able to pinpoint issue yet, I have made temporary fix by changing the condition from
c == EOF
toc < 0
. I will make a pull request soon.By the way,
printf
might have issues with hexadecimal representation as well since it literally printed back-1
instead offfffffff
.The text was updated successfully, but these errors were encountered: