在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):simon816/Command-Block-Assembly开源软件地址(OpenSource Url):https://github.com/simon816/Command-Block-Assembly开源编程语言(OpenSource Language):Python 99.4%开源软件介绍(OpenSource Introduction):Command Block AssemblyCommand Block Assembly started off as a tool that compiled assembly instructions into Minecraft commands. It has now grown into a much larger suite of tools for compiling source code into Minecraft commands, therefore the toolchain as a whole is known as the Minecraft Compiler Collection (MCC). Minecraft Compiler CollectionThe Minecraft Compiler Collection (MCC) is an umbrella tool composed of multiple compilers in a toolchain to compile high level code into Minecraft commands. It shares some similarities with the GNU Compiler Collection. MCC is composed of the following components: CBL CompilerCommand Block Language (CBL) is a C++ inspired programming language specifically designed for Minecraft commands. CBL has been designed to abstract away from commands to the point where you don't need to consider the underlying mechanics. The syntax is similar to C++ in a lot of ways. It also takes from Java's idea of having no pointers in the language. Exampleinclude "Text"
type point {
int x;
int y;
constructor(int x, int y) {
this.x = x;
this.y = y;
}
inline point operator +(point other) {
return point(this.x + other.x, this.y + other.y);
}
inline point operator *(int val) {
return point(this.x * val, this.y * val);
}
inline void print();
}
inline void point::print() {
Text output;
output += "(";
output.append_ref(this.x);
output += ", ";
output.append_ref(this.y);
output += ")";
output.send_to_all();
}
void main() {
point p1(2, 4);
point p2(5, 9);
p1 += p2;
p1 *= 2;
p1.print();
} This example demonstrates several language features of CBL, some of which should be familiar to C++ programmers. Because everything in this example can be determined statically (at compile time), the output is just: tellraw @a [{"text":"("},{"text":"14"},{"text":", "},{"text":"26"},{"text":")"}] DocumentationSee the CBL Wiki for more details on the CBL language. AssemblerThe assembler in MCC is the original assembler when this project was just Command Block Assembly. Assembly LanguageThe assembly language is simple and has instructions similar to x86. The language looks like the following: #include foo.asm
; Useful comment
.my_const #1 ; A constant value
.my_ref my_const ; A constant reference
main:
MOV #0x01, 0 ; Do the thing
_loop: ADD my_const, 0
JMP _loop ExampleThe first example code written for CBA was an assembly program that prints the fibinacci sequence until the next value overflows: .x 0x00
.y 0x01
.old_x 0x02
.counter 0x03
main:
MOV #0, x
MOV #1, y
MOV #1, counter
_loop:
PRINT "fib(", counter, ") = ", x
SYNC
ADD #1, counter
MOV x, old_x
MOV y, x
ADD old_x, y
CMP #0, x
JGE _loop ; if not >=0 then x has overflowed DocumentationThe instruction set and how write CBA programs is documented on the wiki. C CompilerMCC partially implements a C compiler, most language features are implemented and it includes a preprocessor. The C compiler sits on top of the assembler - all C code is compiled into assembly which is then passed through MCC's assembler. ExampleHere is the same fibinacci sequence program but implemented in C: #include <stdio.h>
int x;
int y;
int old_x;
int counter;
void main() {
x = 0;
y = 1;
counter = 1;
do {
printf("fib(%d) = %d", counter++, x);
sync;
old_x = x;
x = y;
y += old_x;
} while(x >= 0);
} DocumentationThe C compiler tries to stay as close as possible to the real C language, so documentation for most language features can be found elsewhere. There is only one built-in type, The mclib.h file contains several useful macros and definitions. Browse the code in the examples directory to see working examples of C code. Command IR CompilerCommand IR is the intermediate representation used by MCC. All compilers above ultimately generate Command IR code. It is designed to relate closely to Minecraft commands themselves but provide a level of abstraction and context which enables optimizations among other things. Command IR supports linking, which means it's possible to write code in CBL, C, ASM and IR directly and compile them together into one program. ExampleHere is a hello world program:
The output is a file tellraw @a [{"text":"Hello, "},{"text":"World!"}] DocumentationCommand IR's syntax, instruction reference and internal working is documented on the wiki. Datapack PackerFinally, to bring everything together and generate a datapack, MCC reads a "Datapack Definition" file which declares how to package the code into a datapack. The file is a simple INI file declaring attributes such as the namespace. To complete the fibinacci example, the datapack definition file [Datapack]
namespace=fib
place location=0 56 0
description = An example datapack that prints the fibonacci sequence DocumentationCurrently there is only one section in a DPD file, the Datapack section. In order to create a datapack, two values are required: the
MCC pipelineThere are 3 main stages to the compiler pipeline:
The MCC command takes a list of files, each code file goes through some number of transformations to end up as a Command IR object. The linker merges each Command IR object into a single Command IR object. Any conflicts when merging will abort the compiler. A datapack definition file is required for the packer. The packer takes the single Command IR object and generates the final mcfunction files. To get an idea of the hierarchy of components, here is a diagram:
Running MCCYou will need to generate the standalone parsers (from Lark) using the The Lark python package needs to be installed, Example: Alternatively, you don't need to create the standalone parsers if you keep Lark available in the python environment. MCC is implemented in python. Currently it is not bundled into an executable so it must be invoked using the python interpreter. MCC is invoked by Command help text:
MCC will dispatch a different tool depending on what the file extension of each input file is:
Depending on the command line arguments, MCC will perform different tasks on each file. Some files are ignored if they are not relevant for the desired action. ExamplesCompiling
Compiling
Compiling
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论