Package: mlogevo
MlogEvoCompile C code to Mindustry logic, support C99 and some GNU extensions (mostlyGCC Extended ASM).Installpipinstallmlogevo...or install from GitHub:pip install git+https://github.com/umrninside/mlogevoMlogEvo does not havebuiltinfunctions likeSuperStormer/C2Logic, so it's recommended to installMlogEvo Standard LibraryUsagemlogevo--help# Or...python3-mmlogevo--help# or sometimes on Windows...python-mmlogevo--helpNOTE: Python 3.7 or later is required.cpp(from GCC/Clang) is required for comments, macros and preprocessor directives.If there is nocpp, you can still compile your source code bypython3 -m mlogevo -skip-preprocessFeatures and limitationsMlogEvo is a C-based DSL, thus support mose of the C99 features, except:switch-caseenumactual pointers, arrays and structures (not inmlogarchitecture at least)onlyintanddoublevariables are supportedConvenientprint()functionThe builtinprintfunction can take multiple arguments as input. Remember toprint_flush(message1).#include<mlogevo/io.h>externstructMlogObjectmessage1;voidmain(){print("The ultimate answer is ",42,"\n");print("62 * 1847 = ",62*1847,"\n");print_flush(message1);}Sensible Mlog ObjectsInmlogarch, there is astruct MlogObjectrepresentingObjectin Mlog. Unlike normal C structure, this is READONLY.
Every sensible attribute is considered as a "structure" member.NOTE:This requires mlogEvo-stdlib.The hyphens (-) in attribute names are replaced by underscores (_, e.g.container1.blast_compound)#include<mlogevo/mlog_object.h>#include<mlogevo/io.h>// extern is preferredexternstructMlogObjectmessage1;voidmain(){print("x=",message1.x,", y=",message1.y,"\n");print_flush(message1);}Access to Mlog Builtin ConstantsMindustry Wiki: Variables and ConstantsNOTE:This requires mlogEvo-stdlib.The building (type)switchis named afterSwitch(capitalized).The hyphens (-) in attribute names are replaced by underscores#include<mlogevo/mlog_object.h>#include<mlogevo/mlog_builtins.h>externstructMlogObjectmessage1;externstructMlogObjectswitch1;voidmain(){print(switch1.type==builtins.Switch);print_flush(message1);}GCC Extended Asm Template (not basic ones)This allows you to write Mlog assembly code, and make them work with the C part.
Asm Template can bevolatile-qualified, so they won't break in further optimizations.Do not useasm goto, useasm volatileinstead.See alsoExtended Asmvoidmain(){intresult;intx=1,y=2;__asm__volatile("ubind @mono");__asm__("op max %0 %1 %2\n":"=r"(result):"r"(x),"r"(y));}Local Common Subexpression Elimination (or LVN)This is a trivial and conservative optimization.intx1=3,x2=0,y1=0,y2=4;intr2;voidmain(){r2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);}Without LCSE (-fno-lcse):set x1 3
set x2 0
set y1 0
set y2 4
op sub ___vtmp_1@main x1 x2
op sub ___vtmp_2@main x1 x2
op mul ___vtmp_3@main ___vtmp_1@main ___vtmp_2@main
op sub ___vtmp_4@main y1 y2
op sub ___vtmp_5@main y1 y2
op mul ___vtmp_6@main ___vtmp_4@main ___vtmp_5@main
op add r2 ___vtmp_3@main ___vtmp_6@main
endWith default-O1:set x1 3
set x2 0
set y1 0
set y2 4
op sub ___vtmp_1@main x1 x2
op sub ___vtmp_4@main y1 y2
op mul ___vtmp_3@main ___vtmp_1@main ___vtmp_1@main
op mul ___vtmp_6@main ___vtmp_4@main ___vtmp_4@main
op add r2 ___vtmp_3@main ___vtmp_6@main
end