Anuken / Mindustry-Suggestions

Repository for Mindustry suggestions and feedback
130 stars 58 forks source link

Labels and/or PC relative jumps for textual logic processor assembly #3844

Closed wjl closed 2 years ago

wjl commented 2 years ago

Describe the content or mechanics you are proposing.

Logic processors are awesome, and I've been using them a lot, writing fairly complex programs. I really enjoy programming them, and their assembly-like textual representation is great. One major issue I have is that there are no labels, which means that when inserting statements, all jumps have to be adjusted because they are direct address jumps. I realize there are ways to simulate this using extra instructions involving the PC (@counter) but this eats into code efficiency and is something assembly programmers don't generally have to deal with, even with old 8051 code. =)

One of these two features would really help solve this problem without taking away the character of being an fairly low-level "assembly language" for the game:

  1. Being able to label lines, similar to what you can do in normal assembly languages. I'd propose the syntax is just "label: statement", where the label is just text and it becomes a variable the same as if you did a set or an op, and then you can jump to it just like you can any other number containing variable. Even if not used for jump targets, this also doubles as a lightweight way to allow "comments" in code (if you don't mind your comments being a single variable name). And obviously this makes not only inline loops and such position independent, but also makes function call implementation a bit easier because you can now effectively call by name.
  2. Another lesser alternative would be to allow relative jumps. Again, yes, this can be done by adding lots of extra ops involving @counter, but a simple modification to the jump which allowed a PC relative offset instead of a direct address would also make it extremely easy to write position independent code. I don't think this as as nice as having labels, but it would certainly help a lot when editing code textually. For syntax I assume there would have to be an option to the jump instruction to mark the jump target as relative. In this respect, this is in some ways more invasive of a change than labels, which don't require changing the syntax of any individual instruction.

Describe how you think this content will improve the game. If you're proposing new content, mention how it may add more gameplay options or how it will fill a new niche.

Programming logic processors is a ton of fun. It's supposed to be kind of hard and low-level! But even the earliest, most basic, and lowest-level assemblers for real computer languages have had features like labels and/or PC-relative jumps which make the task of editing a line of code a fairly local endeavor that won't generally break all other existing code by screwing up addresses.

I think adding labels (my preference) or at the very least PC-relative jumps would make it more feasible to write complex programs without frustration that stems from just updating jumps all over the place. Of course the logic programming itself can stay frustrating enough to keep it fun. =)

Also, while this COULD be presumably be done by a mod or an external assembler tool, I think this is basic and worthwhile enough functionality that it would be very appropriate to add to the base game.

Before making this issue, check the boxes below to confirm that you have acknowledged them.

KayyAyeAre commented 2 years ago

aren't there already labels?

end-me-please commented 2 years ago

There are labels

label:
print "frog"
printflush message1
jump label always

they get converted to line numbers when importing

wjl commented 2 years ago

Wow, I didn't realize you could already do this. That is excellent. I must have either missed this in the documentation, or possibly it's not documented.

Is this documented on the wiki? Maybe that's all that's missing. 😀

github-actions[bot] commented 2 years ago

This suggestion is now stale, and will be automatically closed.