How multidustry/mlogjit works
Project type and purpose
• This is a compiler‐style project: a JIT (just‐in‐time) compiler called “Mlogjit” for the Mindustry Logic (MLOG) language.
• Purpose: take MLOG text, parse it, build an intermediate representation (IR), then use Cranelift to emit native machine code, and finally execute that code against a ProcessorContext.
File structure
Top‐level:
• Cargo.toml / Cargo.lock – Rust package and dependency manifests
• README.md – project overview
src/ directory:
• parser.rs – MLOG text → AST/IR parser
• ir.rs – definition of the intermediate representation (Instr, types)
• jit.rs – orchestration of Cranelift JITModule, function signatures, codegen entrypoint
• compiled_function.rs – wrappers around the compiled code and JITModule handles
• ctx.rs – ProcessorContext struct (register file, stack, calling conventions)
• env.rs – trait definition for ProcessorEnv, DummyProcessorEnv, I/O hooks
• oper_functions/ – implementations of individual arithmetic or math operations (add, mul, pow, etc.)
• lib.rs – public API exports (JitCompiler, parse_code, ProcessorContext)
• main.rs – optional CLI/demo entrypoint
README for additional insights
• It describes the pipeline: parse_code → Vec<Instr> → JitCompiler.compile → machine‐code function pointer → extern “C” invocation
• Mentions Cranelift integration, performance metrics, and planned future additions.