MlogEvo
Compile C code to Mindustry logic, support C99 and some GNU extensions (mostly GCC Extended ASM).
Install
pip install mlogevo
...or install from GitHub: pip install git+https://github.com/umrninside/mlogevo
MlogEvo does not have builtin functions like SuperStormer/C2Logic, so it's recommended to install MlogEvo Standard Library
Usage
mlogevo --help
# Or...
python3 -m mlogevo --help
# or sometimes on Windows...
python -m mlogevo --help
NOTE: Python 3.7 or later is required. cpp (from GCC/Clang) is required for comments, macros and preprocessor directives.
If there is no cpp, you can still compile your source code by python3 -m mlogevo -skip-preprocess
Features and limitations
MlogEvo is a C-based DSL, thus support mose of the C99 features, except:
switch-caseenum- actual pointers, arrays and structures (not in
mlogarchitecture at least) - only
intanddoublevariables are supported
Convenient print() function
The builtin print function can take multiple arguments as input. Remember to print_flush(message1).
#include <mlogevo/io.h>
extern struct MlogObject message1;
void main() {
print("The ultimate answer is ", 42, "\n");
print("62 * 1847 = ", 62*1847, "\n");
print_flush(message1);
}
Sensible Mlog Objects
In mlog arch, there is a struct MlogObject representing Object in 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 preferred
extern struct MlogObject message1;
void main() {
print("x=", message1.x, ", y=", message1.y, "\n");
print_flush(message1);
}
Access to Mlog Builtin Constants
Mindustry Wiki: Variables and Constants
NOTE:
- 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>
extern struct MlogObject message1;
extern struct MlogObject switch1;
void main() {
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 be volatile-qualified, so they won't break in further optimizations.
Do not use asm goto, use asm volatile instead.
See also Extended Asm
void main() {
int result;
int x = 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.
int x1 = 3, x2 = 0, y1 = 0, y2 = 4;
int r2;
void main() {
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
end
With 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
Metadata
Release files for mlogevo 0.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mlogevo-0.0.11-py3-none-any.whl | Python 3 | none | any | Details for mlogevo-0.0.11-py3-none-any.whl |
Release files / mlogevo-0.0.11-py3-none-any.whl
| Download URL | mlogevo-0.0.11-py3-none-any.whl |
|---|---|
| Size | 38.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d542f6097cfb3346765c9988170ce709d2e34a3bd2be62b81d41a90be46f8f7a
|
|
BLAKE2b-256 checksum How to use checksums |
64c914d25cfb9ac45c2b22ba696566003635c7baf67be6bf5f7436f54db0b763
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for mlogevo 0.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.