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

Final ASMAPI cleanup, NumberType enum change, and new insertInsnList method #54

Merged

Conversation

Jonathing
Copy link
Member

This PR is, what I hope to be, my final cleanup PR for ASMAPI. There were a lot of things with it I wanted to change so that it could see better usage in CoreMods without needing to resort to (too much) extra work on the modder's part, given that CoreMods is sandboxed.

  • Renamed appendMethodCall to injectMethodCall.
    • The former still exists for compatibility.
  • Renamed LdcNumberType to NumberType.
  • Added castNumber, a method which returns an Object of the desired value casted to the given NumberType.
    • I realized that there are many cases where a direct object value (usually the primitive types) need to be fed into an instruction directly, the best example being FieldNode. This approach allows modders to cast numbers themselves without needing to rely on us to make additional stray methods into ASMAPI.
  • Added a new insertInsnList method which accepts AbstractInsnNode as opposed to the components of a MethodInsnNode.
    • This allows for modders to use ASMAPI to insert their instruction lists using ASMAPI's InsertMode, reducing the need to interface with the method node's instruction list directly.
    • As an additional code cleanup, the old insertInsnList now uses this new method along with findFirstMethodCall, which is essentially what it was doing in the first place.

My goal with these ASMAPI changes is to have them be added into Forge builds as far back as 1.18.2. These old versions only have so much to gain from these changes. The only logical breaking change is the bug fix to findFirstInstructionBefore which was added in #50.

Once this is merged, we can look into enhancing the Nashorn engine that CoreMods uses as described in this wishlist.

*
* @deprecated Renamed to {@link #injectMethodCall(MethodNode, MethodInsnNode)}
*/
@Deprecated(forRemoval = true, since = "5.1")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've marked this method as deprecated for removal, but should it be removed? It's existed in CoreMods for a long time and a lot of older CoreMods, some of which might still be used today in FMLOnly-type mods, might be using this method.

* @param mode How the given code should be inserted
* @return True if the list was inserted, false otherwise
*/
public static boolean insertInsnList(MethodNode method, AbstractInsnNode insn, InsnList list, InsertMode mode) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method returns boolean to have parity with the older insertInsnList method. However, I think that it might be better to crash the game if a modder tries to insert a list into the instructions using an instruction that is not included in the method. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it return a boolena means the CoreMod itself can determine to crash or not

*/
public enum LdcNumberType {
public enum NumberType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this renamed/does it break compatibility? How old is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was renamed because it is no longer exclusive to LdcInsnNode. There aren't any versions of Forge that have bumped CoreMods recently to include LdcNumberType, so it doesn't break compatibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then if you're done i can pull this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's ready

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

Successfully merging this pull request may close these issues.

2 participants