Skip to content
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

Opcode.java fields (require,ret) are wrongly named, replace them with (lookupDepth, popCount, pushCount) #1848

Open
SergioDemianLerner opened this issue Aug 3, 2022 · 3 comments

Comments

@SergioDemianLerner
Copy link
Contributor

SergioDemianLerner commented Aug 3, 2022

The Opcode class has the fields:

    private final int require;
  ...
    private final int ret;

And a comment describes them as : in-args,out-args
But they are not what is seems.

require is really a stack lookupDepth.
ret cannot be easily explained, it is basically (lookupDepth+pushCount).

I suggest removing ret and require and replace them with 3 arguments: (lookupDepth, popCount, pushCount).
While popCount won't be referenced in the code, it's useful to have it as reference and for debugging.
For most opcodes the definition won't change. For DUPx, SWAPx, DUPN, SWAPN it will change.

verifyStackOverflow() will also need to be modified.

@SergioDemianLerner SergioDemianLerner changed the title Opcode.java fields (require,ret) are wrongly named, replace them with (lookupDepth, popCount, and pushCount) Opcode.java fields (require,ret) are wrongly named, replace them with (lookupDepth, popCount, pushCount) Aug 3, 2022
@SergioDemianLerner
Copy link
Contributor Author

I think the original meaning was that you could implement those opcodes by removing all elements until lookupDepth, and them pushing back the same elements plus pushCount.

Not very intuitive, because that's not how it is implemented, but that was the code author's idea.

@Vovchyk
Copy link
Contributor

Vovchyk commented Aug 10, 2022

this will require to refactor all opcodes in the OpCode enum, won't it? Seems there are a lot of them. Can we just add toString() method to that enum, so that we could print opcode internals in a format that fits our debugging purposes?

@SergioDemianLerner
Copy link
Contributor Author

I don't mind doing the re-factor. In all cases except DUPx, SWAPx, DUPN, SWAPN, it will be simply duplicating the "retire" value so the line:
ADD(0x01, 2, 1, VERY_LOW_TIER),
will become:
ADD(0x01, 2, 2, 1, VERY_LOW_TIER),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants