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

Maybe "by design"?: x = 1 creates two Mindustry Logic instructions #11

Closed
schittli opened this issue Mar 31, 2021 · 3 comments
Closed

Comments

@schittli
Copy link

Good evening

my mindcode source created more than 1000 Lines of Mindustry Logic instructions (I have tried to create a generic Ressource manager for factories using drones).

Btw.: Good to know: If one tries to import more than 1000 Logic instructions into Mindustry, then the game will silently remove all instructions after the 1000th line :-( Therefore, one starts searching non-existent bugs...

This issue is maybe the result of the AST design, maybe it's a bug. I know programming compiler optimization is hard work and I was not able to find the source of this issue.

I report the problem anyway.
You can close it again as "it's too much work" - after all, we're talking about a game. 🙂

This code:

x = 1

Creates two Mindustry Logic instructions:

set tmp0 1
set x tmp0
end

This optimization would make the compiled code twice as fast 😊😉

Thanks a lot, kind regards,
Thomas

@francois
Copy link
Collaborator

Yup! I'm aware of this. In the code that is on https://mindcode.herokuapp.com/, I had to disable the optimizer. I remove it in 1c6afb3. I'm in the process of writing a better optimizer pipeline, and it is nearly ready. I don't want the new optimizer to generate more bugs than the old one!

The 1000 instructions limit of Mindustry Logic is something I encountered a short while ago. I need to make some tests: is it 1000 or 1024 lines? I wouldn't be surprised if it was the latter (2**10). I still want to give a warning to the developer about the problem, so they know they need to split their logic into multiple, independent, processors.

I won't promise when the new optimizer pipeline will be on main / production, but it shouldn't be too long. Pretty sure it'll be there this weekend, at the latest.

Anyway, thanks for taking the time to report all those bugs and misfeatures. I really appreciate you doing this.

@schittli
Copy link
Author

schittli commented Apr 1, 2021

Good evening @francois ,
I'm very glad, that it doesn't annoy you... ufff :-)

In Mindustry 126.2 (actually the lastest release) it just imports max. 1000 lines from the clipboard, I have tested it :-)

By the way, this limit is independent of the used Mindustry Processor ('Micro Processor', 'Logic Processor' or 'Hyper Processor')

It's great to hear you have an optimiser pipeline.
I'm just realising that it's quite tricky to test if the generated code is correct....

It's sad that the Mindustry logic doesn't have string functions, otherwise it might be an elegant idea to test the optimiser this way, by having the code generate strings for each test, which you can then quickly compare to the expected result:

expected result : abcdef
optimised result: abdefc

Maybe it is too simplistic...

@francois
Copy link
Collaborator

francois commented Apr 1, 2021

Your idea is sound, but the tests would have to be done manually, unfortunately. But still, it's something that could work. I'll have to think more about this.

1000 instructions... ouch. The script is 348 lines, unoptimized. When I run the same script through the optimization pipeline here, I can achieve a 60% reduction in the number of instructions; from 383 down to 235, or a nearly 40% reduction. The longer the script, and the more advanced features it uses, the more optimizations have a chance to kick in. Soon!

francois added a commit that referenced this issue Apr 2, 2021
Part of #11
francois added a commit that referenced this issue Apr 2, 2021
Some assignments are unused. If a case/when expression does not use the
result, then the assignments are useless and can be removed. This
reduces the total number of instructions, improving our ability to cram
more code into a processor's memory.

Part of #11
francois added a commit that referenced this issue Apr 2, 2021
francois added a commit that referenced this issue Apr 2, 2021
francois added a commit that referenced this issue Apr 2, 2021
francois added a commit that referenced this issue Apr 2, 2021
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