-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Repeated string equate causes an infinite loop when referenced #64
Comments
Oops, this is not really a bug (except for the circular reference causing an infinite). |
It took me a while to understand the problem.
That is converted to:
If I don't think that a circular reference should be prohibited, it could be useful for recursive expansion of EQUS, so I don't know what to do. |
Maybe a warning? Something like "Self reference in an EQUS, it may cause an infinite loop." that is only shown once per execution of rbgasm. Not sure about how to detect it, though. It's not just a symbol referencing itself, it could be a chain. |
Hmm... I'm struggling to think of any reasons why someone would deliberately use As for detecting it, we could keep track of all the |
Well, an EQUS can be assigned a multiline string. You can do something like:
And you could use it to store an arbitrary number of macro arguments. You can't do that with a macro inside a macro. EDIT: No, that wouldn't work, sorry. But that's the idea, you could maybe use them to define things. I'm not too sure about limiting things just because we can't find an use case now. |
On the other hand, it is true that some of the most hacky constructs in C are done using Relevant: http://stackoverflow.com/a/12447739 |
By the way, the same problem exists with macros:
And this is a completely legitimate use-case of macros, so I'm really not sure about this. |
I think that the only thing that can realistically be done is to warn about this problem. I don't think there's a good way of solving this. Both EQUS and macros can have this problem, and it can be hidden very easily if the coder wants to (by having a chain of 2 or 3 definitions, for example). It cannot be detected by the parser either because when it finds a symbol that has to be replaced by an EQUS it simply sends the string to the lexer for it to handle. It cannot even be detected by preventing the replacement of the same EQUS in the same line twice, you could be trying to use it in two different places and that's not a problem. Also, it can only be detected when it is actually used: An EQUS may change if you redefine it. Macros are even worse. If you hide the recursive usage of the macro inside an IF, how can you even know if the problem is going to happen or not? You could even do crazy things like getting the assembler into a loop that only ends when a specific time is reached! xD EDIT: Actually, that last part isn't true, the time is only calculated when the assembler starts. |
I've pushed this: 4228e3e I really don't know if it makes sense to spend time trying to detect this considering that any possible test is going to be incomplete and, in the end, everything comes down to the programmer doing things right.. |
I would say to not expand macros nor equs when used as a macro or equ name |
I don't think I understand what you mean, could you show what you mean with an example? |
When defining an EQU, the part on the left of it should not be fed into the macro expanding part. That way, |
That doesn't help solve the problem. You can still do this:
|
A possible solution would be to enforce a recursion depth limit. This limit could be passed as a command-line argument, too, so a recursion-heavy program could be still made working. |
Fixed in e0e8170 |
rgbasm will accept the following without complaint if
string
is not referenced:If the equates don't match, rgbasm will raise
Buffer safety margin exceeded
:The text was updated successfully, but these errors were encountered: