Crates.io | dpc |
lib.rs | dpc |
version | 0.2.5 |
source | src |
created_at | 2024-01-03 15:58:23.841953 |
updated_at | 2024-01-28 23:49:44.850711 |
description | A compiler for Minecraft datapacks |
homepage | |
repository | https://github.com/CarbonSmasher/dpc |
max_upload_size | |
id | 1087505 |
size | 685,503 |
DPC is essentially just LLVM for Minecraft datapacks: a compilation backend that converts a common input language to Minecraft function files. It is not meant to be used as a high level language that you write datapacks in directly. Instead, a frontend language with more useful features will create IR that this project can easily optimize and turn into a pack for the targeted version.
DPC begins by processing IR, which is either given in code when used as a library, or parsed from text. The text representation looks (will look) something like this:
"foo:main/main" {
let x: score = val 7s;
let y: score = %x;
sub %y, %x;
if eq %x, 8s: call run "foo:main/bar";
}
"foo:main/bar" {
say "hello";
}
The IR will have support for:
IR is designed to be as simple as possible to create and have a stable interface between updates, but it is not always the easiest to optimize. Thus, IR is quickly lowered to MIR, a very similar format which has slightly less convenience, but is where most of the optimizations happen. Inside MIR, multiple passes run over the instructions such as:
Next, MIR is lowered one more time to LIR, which is as close as possible to actual commands. While some IR and MIR instructions might end up representing more than one command, LIR instructions are pretty much 1:1. Another difference is the representation of types. While IR and MIR instructions are generic across multiple types and just give errors for types they don't support, LIR has separate instructions for different types of data. In LIR, more passes are run that are more Minecraft-specific, such as:
Finally, the LIR is processed into Minecraft commands in the codegen stage. Codegen only looks at one instruction at a time, selecting the best and smallest variants to reduce output size.
Right now, the main thing that needs to be done is the implementation of all the commands in the game as instructions. That, along with fleshing out other optimizations and features like custom instructions, macros, and overlays.
/tellraw
and /title
/damage
/random
/advancement
and /recipe
/schedule
/particle
/bossbar
/team modify
, /scoreboard objectives/players modify