A transpiler for Mindustry Logic.
- Install the dependencies if you don't have them yet: NodeJS, NPM, Git
- Run
npm i -g mlogx
Usage: mlogx
- Validation
- Debugging MLOG code is painful. The only way to notice that you typed
ucontrol itemtake
instead ofucontrol itemTake
is to scroll through your entire program to see why units aren't taking items, and finally see the purple "invalid" box. There is also no warning for using a variable that doesn't exist. The MLOGX compiler will check your code before it compiles to make sure all commands are valid and all variables are of the correct type.
- Readability and Conciseness
- Text MLOG statements can be a bit weird. For example, the
ulocate building
instruction requires a meaningless ore as an argument, and several other instructions have repeated or strangely ordered arguments and/or meaningless zeros. MLOGX has more concise statements with better ordering of arguments, while still accepting the old ones. - It also supports shorthand instructions, such as infix op(
set x 5 + 5
=>op add x 5 5
) and infix jump(jump label x >= 5
=>jump label greaterThanEq x 5
) - The preferred variable naming convention is to use a thing.property syntax, for example,
sensor core.x
. This is a shorthand forsensor core.x core @x
as you would otherwise be typing things twice. This makes it very clear what each variable is meant to be. - Sometimes there are bits of data that you might want to change, but never while your code is running. Storing these as a variable in your MLOG code is a waste of instructions, so they often end up getting inlined, making them difficult to change and understand. MLOGX has compiler consts, which allow you to inline data without compromising readability.
- Advanced unit control logic often requires highly repetitive code, for example, the same block of code repeated an arbitrary number of times but with one number incrementing.
&for
loops clean this up easily, and allow you to change the target number of units by changing a single compiler const in a config.json file instead of copy pasting your code n times, forgetting to change a number in one place, and then wasting 15 minutes wondering why the 3rd flare doesn't get rebound. - Logic that prints information is both difficult to read and hard to change. The printf statement allows you to write
printf "Power: {powerIn}/{powerOut} ({powerPerc}%)"
. - MLOGX also allows you to split your code into multiple files, which is useful if you use a particular bit of code lots of times.
- Optimization
- Because MLOGX is a strict superset of MLOG, your code can be optimized just as much as if you were writing regular MLOG. The compiler does not inject extra executed instructions unless you ask for it.
- MLOGX is not currently an optimizing compiler, the instructions you put in are what you will get out.
MLOGX is more than just a compiler, it also has the mlogx info
command, which gives you information on a command or generic arg type(eg operandDouble will show all operators that accept two operands).
There is also mlogx port
, which ports mlog code to mlogx by removing trailing zeros, and mlogx genLabels
, which adds autogenerated jump labels to code from a processor.
Features:
- Stops you from writing silly code like
ubind "poly"
- Improved syntax for certain commands(ulocate, radar)
-
mlogx info
for information about a command - Compiler constants
- No more pasting weird unicode characters for the sand icon
- /**/ comments
- Static type checking
- NPM package
-
--watch
option - [?] Namespaces
- Loop unrolling syntax
- Functions
- Console output highlighting
- Porting tool
- Infix op and jump syntax
- More functions
- Inline functions
- Custom commands