A web-based editor and source-to-source compiler for people that don't mind assembly but want something more laconic than what Mindustry offers by default -
historically, assembly languages leaned towards short instruction names
(sometimes leading to names like CVTPS2PD
in extended instruction sets), but MLOG is all but the opposite of that with jump greaterThan i 0
.
Therefore, the purpose of the tool is to offer shorthand versions of common instructions without making the whole thing much less "assembly-er" - there's a handful of other people's compilers for that.
Which apparently v6+ has, despite the only mention of it being in patch notes somewhere.
Any instruction can be preceded by a labelName:
, and labels may occupy separate lines as well.
You can do
instruction1; instruction2
instead of
instruction1
instruction2
if you really want.
Instruction now can be used as just jump labelName
for unconditional jumps (jump labelName always 0 0
).
A convenience wrapper for jump
, syntax as following
if a op b [then] instruction
# or
if a op b [then]
...instructions
endif
# or
if a op b [then]
...instructions
else instruction
# or
if a op b [then]
...instructions
else
...instructions
endif
So
am_dead = @unit.@dead
if am_dead == true end
becomes
sensor am_dead @unit @dead
jump 3 notEqual am_dead true
end
# end if (pc:0)
and
if debug == true
_x = @unit.@x
_y = @unit.@y
printflush cout "We're at" _x ", " _y
endif
becomes
jump 8 notEqual debug true
sensor _x @unit @x
sensor _y @unit @y
print "We're at"
print _x
print ", "
print _y
printflush cout
# end if (pc:0)
if
-blocks containing a single unconditional jump
will be turned into a single jump
instruction, so
if am_dead == true jump find_a_unit
...
find_a_unit:
becomes
jump <offset> equal _dead true # dest: find_a_unit
Instruction now accepts trailing arguments to produce multiple print
instructions, so
print "x:" @thisx ", y:" @thisy
becomes
print "x:"
print @thisx
print ", y:"
print @thisy
Instruction now can be used with trailing arguments to produce one or more print
instructions before it, so
printflush message1 "x:" @thisx ", y:" @thisy
becomes
print "x:"
print @thisx
print ", y:"
print @thisy
printflush message1
You can do the following:
MLOG+1 | Generated MLOG | Notes |
---|---|---|
|
| |
|
|
Most C-style binary operators are supported; |
|
|
Same as above |
|
|
Also same as above |
|
| |
|
|
Memory shorthands |
|
|
|
Macros are essentially custom instruction shorthands, defined as
macro macro_name
...instructions
endmacro
macro_name
# or:
macro macro_name(...parameters)
...instructions
endmacro
macro_name ...parameters # option 1
macro_name(...parameters) # option 2
for example,
macro ensure_unit
_dead = @unit.@dead
if _dead == true jump find_a_unit
endmacro
# ...
ensure_unit
becomes
# macro: ensure_unit
# ...
sensor _dead @unit @dead
jump 34 equal _dead true # dest: find_a_unit
and
macro dumpxy(u)
set _x = u.@x
set _y = u.@y
printflush cout "x:"_x ",y:"_y
endmacro
# ...
dumpxy @unit
becomes
# macro: dumpxy
# ...
sensor _x @unit @x
sensor _y @unit @y
print "x:"
print _x
print ",y:"
print _y
printflush cout
By default, parameters will be processed MLOG-style (simple string/number/variable name/@constant), but you can include arbitrary snippets by surrounding parameters in {}
, so
macro ifdead(instr)
_dead = @unit.@dead
if _dead == true instr
endmacro
# ...
ifdead {countdown -= 1}
becomes
# macro: ifdead
# ...
sensor _dead @unit @dead
jump 3 notEqual _dead true
op sub countdown countdown 1
# end if (pc:1)
- Doesn't do much error checking as of yet
- Collapses labels into numeric IDs even though it doesn't really have to for v6+
(I was not aware of named label support in MLOG due to that not being documented) - Only supports Latin variable names
(I was not aware that Mindustry allows any non-space character to be used in variable names since this also isn't mentioned on the wiki - an adventure for another time)
haxe -cp src -js bin/script.js -main Main
- Tool by YellowAfterlife
- Written in Haxe
- Uses Ace editor
- GPL 3.0