All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project now adheres to Semantic Versioning.
- The
targetattribute specified in a Schemacode definition file now expects only the version number (e.g.,target = 8.0). The processor type cannot be specified using thetargetattribute, but is inferred from the block type in the schematic. - The web application has been completely overhauled. The highlights of the new web app are:
- Modern, mobile-friendly design.
- The compilation happens without page refresh, meaning the edit history of the code is not lost on compilation. It is also possible to undo (
Ctrl-Z) the action of loading an example code or clearing the editor. - Syntax highlighting in the source code editor. All syntaxes (Mindcode including mlog blocks, Schemacode) are supported.
- Code folding in all source code editors.
- Indicating syntax errors from the last compilation directly in the editor.
- Support for running schematics and generic mlog code on the built-in processor emulator.
- Fixed compiler crashing when an unsupported combination of a processor version and a processor type is specified (e.g.,
#set target = 6;). - Fixed wrong handling of linked blocks by the DFO (#303).
- Fixed Boolean Optimization bugs (#304):
- The optimization may crash when compiling for targets 8.0 and lower.
- The optimization incorrectly processes some noninteger values.
Note
Atomic code sections are only guaranteed to execute correctly in Minddustry build 155 Beta or later.
Note
The new Mlog Watcher functionality available with the tool app requires a new version of the Mlog Watcher mod. The new version has not yet been released, but a Mindustry 8-compatible binary is available here. To use that version, the --watcher-version v1 command line argument must be specified.
- Fixed a possible error in the tool app handling command-line parameters (#302).
- Breaking: the
loopkeyword has been reintroduced, to create infinite loops. Code that usesloopas a function or variable name will not compile, and the variable or function will have to be renamed. - Added the possibility to use the
breakstatement to exit code blocks. - Added implicit labels to loops and code blocks.
- Breaking: Changed the meaning of the
targetcompiler option: when no processor type is specified, the compiler generates the code for a non-processor context. Privileged instructions are supported, but atomic sections and waits aren't.
Note
Atomic code sections are only guaranteed to execute correctly in the latest BE version (build 26658 or later). The latest beta release (v154.3) doesn't provide necessary support for atomic code execution.
Note
The new Mlog Watcher functionality available with the tool app requires a new version of the Mlog Watcher mod. The new version has not yet been released, but a Mindustry 8-compatible binary is available here. To use that version, the --watcher-version v1 command line argument must be specified.
- Fixed an internal error when compiling a function in the main program declared as
export. - Fixed incorrect Temp variable elimination (#298).
- Fixed a possible internal error when parsing a syntactically incorrect file.
- Fixed incorrect handling of some privileged instructions by the Print Merging optimization (#300).
- Fixed incorrect handling of function calls in short-circuit expressions by the Data Flow Optimization (#301).
- Added the
atomic()intrinsic function andatomicfunction modifier. - Added support for nested atomic sections and atomic function calls from an atomic section. The entire topmost atomic section is executed atomically.
- Added support atomic section merging. The duration limit of a merged section can be specified using the
atomic-merge-levelcompiler option (one tick by default). - Added a
atomic-safety-margincompiler option. No safety margin is necessary with the latest Mindustry BE build, though. - Added new tool app functionalities:
- Support for the new version of Mlog Watcher mod, providing several useful new ways to send or extract mlog code and schematics to/from a running game. To use the new Mlog Watcher mod, the
--watcher-version v1command-line argument needs to be specified. - Ability to execute mlog code loaded from a file on the processor emulator and for sending it to the Mlog Watcher. Use the new
pmorprocess-mlogcommand-line argument. - Ability to execute schematics loaded from a file on the processor emulator and for sending it to the new version of the Mlog Watcher. Use the new
psorprocess-schematiccommand-line argument.
- Support for the new version of Mlog Watcher mod, providing several useful new ways to send or extract mlog code and schematics to/from a running game. To use the new Mlog Watcher mod, the
- Added a validation step to the compiler to verify the generated code doesn't exceed the maximum number of instructions. The
enforce-instruction-limitcompiler option can be used to control this behavior.
- When an atomic section doesn't contain any protected instruction, the
waitinstruction providing the atomicity of the section is not generated. - The
setrateinstruction is no longer allowed in atomic sections. - The
volatile-atomiccompiler option has been renamed toatomic-full-protection, with inverted meaning. - Changed Mindcode syntax to allow specifying multiple function modifiers in arbitrary order. For example, it is now possible to declare a function as
inline debugas well asdebug inline(which was the only allower order previously). - Compiler and optimizer messages are no longer output on the console in the command-line application. To access these messages, a log file needs to be generated.
- Console output is generated on the fly, instead of being cached and dumped all at once when the processing is finished.
- The
dm(decompile mlog) andds(decompile schematic) command-line arguments are deprecated. Usepmandpsinstead ("p" stands for "process" as the command-line tool now allows more actions to be performed in addition to decompilation, such as running it on the internal emulator). - The Schematics Refresher mod is deprecated and will be no longer maintained. The Mlog Watcher mod will provide better functionality for managing schematics in the game.
Note
Atomic code sections are only guaranteed to execute correctly in the latest BE version (build 26609 or higher). The latest beta release (v154.3) doesn't provide necessary support for atomic code execution.
- Fixed incorrect emulation of the instruction accumulator for targets 6 and 7 affecting instruction scheduling.
- Added new
@maxUnitssensable property. - Added an atomic code block: a section of code guaranteed to be executed atomically (without interruption), meaning that other processors or game updates do not change the world state.
- Added the
setrateandiptcompiler options. These options specify the rate at which a world processor executes instructions (used by the compiler when building atomic sections). - Added the
volatile-atomiccompiler option governing the way atomic sections are created. - Added the
processor-id,program-nameandprogram-versioncompiler options. These options take string values, which are then encoded into a*idvariable and can be used to identify the processor in the schematics. - Added the
emulator-fpscompiler options to specify the frame rate to be emulated by the processor emulator. While frames are always emulated fully by Mindcode emulator, the change in instruction scheduling caused by different frame rate only affects situations where an interaction between two or more processors is being emulated. - Added the ability to run the compiled schematics on the schematics emulator to the tool app.
- Added support for sensing
@xand@yin blocks when emulating schematics. - Added the
encode-zero-characterscompiler option, which allows encoding zero characters in string literals. Use with caution: resulting code cannot be edited or passed via clipboard. Option has no effect when used in the web app.
- Runtime errors generated when running the code in the processor emulator no longer prevent outputting the compiled code in the tool app.
- Changed the format of the
targetcompiler option. Instead of a processor edition (standard or world), a particular processor type is now specified, using the first letter of the type name (i.e.,mfor micro-,lfor logic-,hfor hyper-, andwfor world-processor, case-insensitive), for example,#set target = 8L;. - When compiling Mindcode for a processor in a schematic, the target type of the processor is determined by the block type in the schematic.
- Compiler-defined constants now follow the
@@VARIABLEpattern, instead of earlier__VARIABLE__(for example,@@MINDUSTRY_VERSION). - Changed the emulator handling of the
waitinstruction with zero argument to match the latest Mindustry BE behavior.
- The system of compiler options has been updated to allow determining whether a given option has been set. This allows the default values of unset options to be derived from the values of other options.
- The transfer variable, defined for uncached external and remote variables, is no longer used for reads. Instead, a fresh new temporary variable is used each time. This may increase the number of temporary variables generated but avoids unnecessary instructions when using postfix operators on these variables. This became quite important with atomic sections.
- Fixed the Data Flow optimization incorrectly marking a variable as uninitialized (#296).
- Fixed incorrect evaluation of some numeric mlog constants (#295).
- Fixed the Mandelbrot schematic sample not rendering after build.
- The Loop Rotation optimization has been updated:
- Full loop rotation is performed even for conditions which contain complex code (such as nested loops or function calls).
- A full loop rotation is also considered alongside a partial rotation if it could be beneficial to Loop Hoisting.
- The Loop Hoisting optimization has been extended:
- The optimizer gathers information to support the Loop Rotation optimization.
- When a loop is fully rotated, an instruction can be hoisted in such a way that it's executed at most once, but only if the loop actually runs.
- When a loop is not known to execute at least once, an instruction affecting just the loop can still get hoisted entirely out of the loop if the loop is nested.
- The mlog processor emulator has been completely rewritten. The emulator now matches the behavior if a Mindustry processor of the version identified by the
targetoremulator-targetcompiler options. - The execution flags have been updated to match the new processor emulator. Some flags have been removed, some have been added, and some have been renamed.
- The processor emulator is now able to execute supported instructions even when created using an
mlog()fuction or an mlog block. This includes the code generated by thecompatibilitylibrary.
Note: the new features in this release bring about changes to the best practices for writing Mindcode.
- Some
selectoptimizations were not applied when optimizing for size. As a result, code optimized for size might end up larger than code optimized for speed. - Some
selectoptimizations may have been incorrect. Due to the previous bug, the probability of them being applied was low (#290). - Fixed the wrong optimization of volatile variables in If Expression Optimization (#291).
- Fixed instructions being hoisted in front of the loop even when the loop is not guaranteed to run (#293).
- Fixed loop-dependent instructions being possibly hoisted in front of the loop (#294).
- Breaking: new keywords have been added to the language:
publicandprivateand are reserved for future use. Code that uses any of these keywords as a function or variable name will not compile, and the variable or function will have to be renamed. - Added the
no-argument-paddingcompiler option. When activated, instructions are not padded to the maximum number of arguments. - Added the
authorcompiler option. The option adds an entry to the list of authors, which is then displayed alongside the usual compiler signature. - Added support for new instruction opcode (
ucontrol deconstruct). - Added a binary
inoperator for testing whether a value is contained in a given range or a list of values.
- Breaking: The
andandoroperators now perform short-circuit evaluation. - The Jump Optimization has been renamed to Condition Optimization, and has been significantly extended:
- Condition streamlining is now applied to the
selectandorinstructions as well as tojump. - The optimization is applied to all variables, not just temporary ones. The results of the DFO analysis are used to track user-defined variables.
- On
advancedlevel, constant folding of conditional expressions is now also performed.
- Condition streamlining is now applied to the
- Breaking: The
jump-optimizationcompiler option has been renamed tocondition-optimization. - The Loop Optimization has been renamed to Loop Rotation, and has been extended to support short-circuit conditions. Full and partial loop rotations are now supported.
- Breaking: The
loop-optimizationcompiler option has been renamed toloop-rotation. - The Boolean Optimization, previously included in the If Expression Optimization as a Select Optimization, has been extracted into a separate optimization class and enhanced:
- Several optimizations aimed at short-circuited conditional expressions were added.
- Where possible, an
opinstruction is used instead ofselect. This allows applying some optimizations even when the compilation target doesn't supportselect.
- The Expression Optimization has been updated:
- More cases where a
selectinstruction can be replaced with asetinstruction are now supported. - When the resulting values of
selectare0and1and the condition allows it, the instruction is replaced with anopinstruction. - The instruction normalizing the result of an
||operator to0or1is removed when not needed. - Added an optimization turning a
readinstruction with a constant string and a constant index into asetinstruction setting the character value directly.
- More cases where a
- When evaluating
jumpandselectconditions during optimizations, cases where the operands of the condition are identical (the same variable) are handled. - The
compatibilitysystem library now also performs a test to find out whether assigningnullto@counteris ignored by the processor. - The mimex metadata have been updated to match the current BE version. The most significant change is a new set of sound constants.
- The documentation has been restructured. Individual optimizers are described in separate files, and the description of Logic functions with links to the Function reference was also moved to a separate file.
- A new optimization, Instruction Reordering, is being developed. The corresponding compiler directive is already present, but the optimization, even when explicitly enabled, is not yet functional.
- All experimental features are now considered standard. The default optimization level is now advanced. Going forward, only features controllable via compiler options will be marked experimental, and the default optimization level will be
advanced. Note that Mindcode is a live system and features may be modified to support new functionalities. A reasonable effort will be spent to ensure smooth conversion or backwards compatibility, but all features, both well-established and relatively recent, can be changed or removed in a new release.
- Fixed an error in the Single Step Elimination optimization causing some superfluous jumps not being removed.
- A new fast dispatch optimization is available for case expressions. Fast dispatch uses just a single instruction to transfer the control to the desired branch of a case expression, including the
elsebranch. - A new value translation optimization, which reads values encoded into a text string using the
readinstruction, may be applied on case expressions (#289). - Added the
use-text-translationscompiler option to allow/disallow using encoding values into a text string for the above optimization.
- Breaking: the
text-tablescompiler option has been renamed (yet again – sorry) touse-text-jump-tables. - The Case Switcher optimization was updated to fully support
nullvalues inwhenbranches (even in integer expressions). - The Extended testing tool now accepts values for any compiler directive in the settings file.
- Fixed an error on the Schematic Decompiler page (#288).
- Fixed the compiler not rejecting integer and double compiler option values outside their allowed range.
- Fixed the compiler not stopping the compilation when an error in a compiler directive gets detected.
- Fixed a rare internal error in Jump Threading optimization.
- Fixed broken reporting of source file positions when compiling Mindcode within a schematic.
- Breaking: new keywords have been added to the language:
debugandexport. Code that uses any of these keywords as a function or variable name will not compile, and the variable or function will have to be renamed. - Added support for implementing the
!==operator using aselect stricEqualinstruction in target8. - Added the
emulate-strict-not-equalcompiler option to allow/disallow usingselectinstead ofjump strictNotEqual. - Added new internal array implementations using new Mindustry 8 logic capabilities:
- Added support for using text-based table dispatch in array implementations.
- Added the
use-lookup-arraysanduse-short-arraysoptions. - Added warnings when a name specified by the
mlogmodifier collides with another user-defined variable or array element in the current processor. - Added the ability to output the final code size broken down by function and an accompanying
print-code-sizeoptions. - Added the
error()function, which can be used to report errors detected at runtime. - Added the
debugcompiler option for compiling code with debug support. - Added debug code blocks. Compiled only when
debugis set to true. - Added debug functions. Calls to debug functions are ignored unless
debugis set to true. - Added target selection to the Mindcode Compiler and Schematics Builder pages in the web app.
- Breaking: change to options governing runtime check generation:
- the
error-reportingoption now specifies the mechanism to be used by the compiler to report runtime errors. When set tonone, no runtime checks occur, regardless of other settings. This was previously governed by theboundary-checksoption. - the
boundary-checksoption now takes a value oftrueorfalse, activating/deactivating boundary checks on array accesses. - the
error-functionoption takes a value oftrueorfalse. Whentrue, the error is reported using the mechanism specified byerror-reporting; when false, theerror()` function has no effect.
- the
- Breaking: specifying the mlog name of a variable using the
remotemodifier is no longer supported. Theremotemodifier now takes only the name of the remote processor as a parameter, enclosed in parentheses. Use themlogmodifier to specify the mlog name of the remote variable. - The
mlogvariable name must not match a linked block name. - The
mlogmodifier accepts multiple expressions, allowing to specify names for individual array elements. - The
mlogmodifier also accepts one of the lookup keywords (:block,:unit,:item,:liquidor:team) in array declarations, allowing to specify the lookup type used by the array. - The
cachedandnoinit cachedmodifiers can be used with variables declaredremote, with the same effect as in case of variables declaredexternal. - Warnings are no longer issued for unused volatile variables. It is assumed that an unused volatile variable will be accessed indirectly.
- Changed the default value of the
mlog-block-optimizationfromfalsetotrue.
- Using the
remotemodifier to mark functions and variables to be accessible remotely is deprecated. Use theexportkeyword instead. - Using parameters with the
externalorremotemodifiers without parentheses is deprecated.
- The
loopkeyword, deprecated earlier and optional in thedo whileloop syntax, has been removed. - The optimization level setting was removed from the user interface on the web page.
- Circular module dependencies get correctly identified and reported (#226).
- Fixed a possible internal compiler error when performing the Temp Variable Elimination optimization.
- Added support for local compiler options.
- Added the
weightcompiler option.
- Breaking: files included via the
requiredirective or via the-acommand-ine argument must contain amoduledeclaration. - Breaking: modules must be compiled using the
strictsyntax mode. Thestrictmode is the default for any source file containing amoduledeclaration, regardless of whether the module contains remote functionality or not. - Breaking: the
text-jump-tablescompiler option has been renamed totext-tables.
- Reorganized the Compiler options documentation.
- Split the System library documentation into separate files.
- Updated the code size calculations for the System library documentation. The array jump tables are no longer included in the calculations.
- Added a section on Variable-based lookups and the
encode()function to the Performance tips documentation.
Note: this is a beta release. It's been released to provide bugfixes and new enhancements to Mindcode and Schemacode.
The newly added features are fully functional. There's an unfinished support for the #setlocal directive. It doesn't have any effect at this time.
- Fixed Jump Threading optimization causing an internal error (#283).
- Fixed Compiler error unrolling an unreachable loop (#285).
- Added support for calling remote functions locally.
- Added support for evaluating the
@nameproperty of all objects (not just objects with a logic ID) at compile time. The@nameproperty is always compile-time evaluated when possible, regardless of thebuiltin-evaluationoption. - Added support for evaluating the
@nameproperty to the Expression Optimization. The@nameproperty is always compile-time evaluated when possible, regardless of thebuiltin-evaluationoption. - Added new
filenameattribute to schematic definition, allowing to specify the name of the output file to use for the generated schematic. - Breaking added new
targetattribute to schematic definition, allowing to specify the target version for the schematic. This might break existing schematics, as previously schematics were compiled using the latest metadata version only. - Added support for a content map in schematics, both when reading and when writing them. The content map is included in all schematic files, regardless of target (older Mindustry versions which do not support a content map will ignore them when reading schematics).
- Added the
--output-directorycommand-line option; if the output directory isn't specified as part of an explicit output file designation, the file will be placed in the output directory.
- Breaking: mlog variable name specified using the
mlogandremotespecifier must be enclosed in parentheses. Any constant string expression is supported.
- Separated the mimex data into a standalone repository, which is now included as a git submodule at
compiler/src/main/resources/mimex. - Updated the BE version metadata to the latest available BE build.
Note: this is a beta release. It's been released primarily to support the newest Mindustry Logic instructions (select), and as a preview of the newest optimization features (namely, text-based jump tables).
The newly added features are fully functional. There's an unfinished support for the #setlocal directive. It doesn't have any effect at this time.
- Fixed a possible internal compiler error when using the Temp Variable Elimination and the select optimization.
- Added a new
encode()function for easier encoding of data into strings. - Added support for using user-defined functions in constant expressions.
- Breaking: remote functions and variables/arrays must always be specified with a fully qualified name (e.g.
processor1.xorprocessor2.foo()) when accessing or calling them from a main processor. - Removed restrictions on requiring the same source files from different modules.
- Remote variables are not reported as unused.
Note: this is a beta release. It's been released primarily to support the newest Mindustry Logic instructions (select), and as a preview of the newest optimization features (namely, text-based jump tables).
The newly added features are fully functional. There's an unfinished support for the #setlocal directive. It doesn't have any effect at this time.
- Fixed the Data Flow Optimization not optimizing global variables (#280).
- Fixed Loop Hoisting processing instructions that change variables already read by the loop (#282). Loop Hoisting can process global variables again.
- Fixed a bug in the
bubblesortfunction in thearrayssystem library.
- Changed the Jump Threading optimization to redirect jumps to a function call directly to the function. The optimization may currently only take place when
symbolic-labelsis set tofalse. - Improved the
selectoptimization in the If Expression Optimization to handle more cases as well as nested or chained conditional expressions.
Note: this is a beta release. It's been released primarily to support the newest Mindustry Logic instructions (select), and as a preview of the newest optimization features (namely, text-based jump tables).
The newly added features are fully functional. There's an unfinished support for the #setlocal directive. It doesn't have any effect at this time.
- Fixed the
targetdirective not recognizing minor target versions. - Fixed the compiler incorrectly refusing remote function parameters matching global variables or linked block names.
- Fixed the Data Flow optimization incorrectly eliminating writes to global variables (#279).
- Fixed the Loop Hoisting optimization incorrectly processing assignments to global variables (#281).
- Added target
8.1matching the latest supported BE version. Target8.0now corresponds to Mindustry Logic v8 Build 149 Beta. - Added a
null-counter-is-noopcompiler option. When active, Mindcode assumes assigning anullto@counteris ignored by the processor and may produce code depending on this behavior. - Added support for new instruction opcodes (
setmarker textAlignandsetmarker lineAlign). - Added specific support for the new
selectinstruction. The instruction is not accessible to the user directly but is used by optimizers to encode conditional expressions. - Added support for generating text-based jump tables.
- The code generation of list iteration loops with symbolic labels has been updated to avoid issues with assigning
nullto@counter. - Changed the Array Optimization to use the new
selectinstruction on theexperimetnallevel for target8.1or higher. - Changed the If Expression Optimization to use the new
selectinstruction on theexperimetnallevel for target8.1or higher. - Changed the Jump Threading optimization to replace the return address of a call with the target of the following unconditional jump on the
experimentallevel. - The compatibility testing (both in the
compatiblesystem library, and in code generated via thetarget-guardcompiler option) were updated to distinguish targets8.0and8.1.
- Added a separate version of the metadata (
v149) corresponding to the official Mindustry pre-release. - Updated the BE version metadata to the latest available BE build.
Note: this is a beta release. It contains a lot of bugfixes discovered during the Mindustry Logic jam, and is released to make these bugfixes available to other users possibly taking part in the jam. This release is available only as the command-line tool, the web application remains at version 3.7.0.
The newly added features are fully functional. There's an unfinished support for the #setlocal directive. It doesn't have any effect at this time.
- Fixed an internal error when function declaration contained duplicate parameters (#270).
- Fixed an internal error when passing a ref array to another function (#271).
- Fixed an error compiling unused inline functions with for-each loops over ref parameters (#273).
- Fixed possible error when using
returninside a for-each loop (#274). - Fixed variable modifiers causing errors in strict syntax mode (#275).
- Fixed incorrect handling of omitted optional arguments in built-in function calls (#276).
- Fixed Mindcode compiler mistakenly updating the compiler profile for all processors within a schematic.
- Fixed an internal error when using local variables in the
backgroundProcess()function. - Fixed a missing remote signature in remote modules not containing any remote functions.
- Fixed a mistakenly reported syntax error when specifying an external storage using an index instead of a range.
- Fixed a possible internal error when activating the
sort-variablescompiler option. - Fixed incorrect code generation of remote modules with an activated
sort-variablescompiler option. - Added missing support for configuring
@payload-router(with a block type or a unit type) to Schemacode.
- Breaking: new keyword has been added to the language:
mlog. Code that uses this keyword as a function or variable name will not compile, and the variable or function will have to be renamed. - Added mlog blocks for embedding complex mlog logic into Mindcode sources.
- Added a storage specification clause to remote variables.
- Added an mlog clause to regular variables, allowing to specify an mlog name for the variable to use.
- Modules included in the compilation via the
requiredirective must be compiled using thestrictsyntax mode. Thestrictmode is used for compiling the module even when a different syntax mode is specified in the main program. When using thesyntaxcompiler option within the module, only thestrictoption is allowed. - When a remote module containing an array is instantiated multiple times, a
@counterarray shared among all processors is created, instead of a separate@counterarray for each processor.
- Mindcode incorrectly warned about possible loss of precision for integer literals larger than 252-1. The correct maximum safe integer value is 253-1.
- Added missing
setruleinstruction variants (canGameOver,dragMultiplier,ban,unbanandunitMineSpeed) for target8.
- Added support for the new
setmarker outlineinstruction. - Added the new
@operationsproperty. - Added the
target-guardcompiler option. When set, generates a guard code which verifies the code is run by a Mindustry version compatible with both thetargetandbuiltin-evaluationoptions. - Added a new
compatibilitysystem library. The library provides a function that verifies Mindcode's compatibility with the Mindustry version in which it is run.
- Breaking: the
target-optimizationcompiler option has been replaced with thebuiltin-evaluationoption. Instead of#set target-optimization = specific;use#set builtin-evaluation = full;. - Improvements to the Case Switching optimization:
- The optimization now processes integer case expression with ranges too if ranges do not overlap other ranges or standalone values.
- The optimization now uses bisection search to locate the proper segment when performing Jump Table Compression.
- The jump table can be padded not just towards zero, but also towards the maximum value, to remove the need for the range check. Requires
builtin-evaluationto be set tofull. - The
case-optimization-strengthoption now has a range from0to6. Each additional value significantly increases the number of segment arrangements considered, as well as optimization time. The value of0doesn't consider any other configuration except a full jump table, effectively turning Jump Table compression off. - When
case-optimization-strengthis greater than zero, the optimizer also generates segment configuration for a full bisection search. This may improve case expressions which are too small for a full jump table optimization. - The bodies of
whenbranches are moved into correct places inside the case expression when possible, to avoid unnecessary jumps. - On the
experimentaloptimization level, the bodies ofwhenbranches may be duplicated to avoid even more jumps at the cost of additional code size increase. This optimization usually only kicks in with jump table compression for small branch bodies, since for larger code increases, a better performing solution can be achieved by a different segment arrangement. - The performance of the Case Switching optimization (in terms of compilation time) has been significantly improved.
- Small improvements to the
printExactHexandprintExactFastfunctions in theprintinglibrary.
- Added a
legacyattribute to the Blocks metadata. - Added new types of metadata corresponding to all opcode selectors.
- Updated the BE version metadata to the latest available BE build.
- Added automatic test for verifying that existing instruction opcodes correspond one-to-one to the known metadata.
- Fixed the compiler refusing compile-time expressions with unrepresentable values (#262).
- Fixed the Data Flow optimization producing unrepresentable mlog values (#263).
- Fixed the Print Merging optimization merging prints across function calls (#264).
- Fixed wrong evaluation of compile-time expressions with character literals (#265).
- Fixed erroneous loop unrolling optimization (#266).
- Fixed internal error in Schemacode builder on missing link name (#267).
- Added support for the
>>>(unsigned right shift) operator to the compiler for targets preceding8. In these earlier targets, the operation is emulated by a sequence of up to seven instructions. - Several compiler-defined constants were added.
- The
printExactBinaryandprintExactHexfunctions were added to theprintingsystem library. The functions print all digits (64 or 16, respectively) of the input number, without a prefix. Negative numbers are printed without a minus sign, but with the sign bit set. - Added missing support for new Mindustry 8 blocks to Schemacode (e.g.,
@landing-padincluding support for configuration, and@tile-logic-display).
- Inactive branches in
ifexpressions with compile-time constant conditions are now omitted from compiling, effectively amounting to conditional compilation. Note: this feature was already implemented in past versions, but got meanwhile deactivated due to a bug. - The
formatBinaryNumber,printBinaryNumber,formatHexNumberandprintHexNumberfunctions in theprintingsystem library were updated to support formatting/printing negative numbers. A minus sign is printed in front of a negative number, including its prefix.
- Fixed the
sync()function not requiring a volatile variable as an argument (#260). - Fixed the Data Flow Optimization incorrectly removing a condition (#261).
- Breaking: added new
guardedkeyword. The keyword is a variable declaration modifier that ensures the generation of the guard code for linked variables. - Added support for the new
op lognMindustry BE instruction to the compiler and processor emulator. - Added the
logn()function to themathsystem library. This function corresponds to the Mindustry Logic 8 instructionop logn, and when target8is selected, the instruction is used instead of the library implementation. - Added the
%%(positive modulo) operator to the compiler and processor emulator. When target8is selected, the native Mindustry Logic instruction is used; for lower targets, the operation is emulated by a sequence of three instructions. - Added the
>>>(unsigned right shift) operator to the compiler and processor emulator. Only available for target8or higher. - Added the ability to declare new keywords, built-in variables, and linked block names through the
#declaredirective. - Added support for constant arrays. Elements of a constant array aren't stored in processor variables but are used directly in the generated mlog program.
- Added the
scaleDisplayfunction to thegraphicssystem library. The function compensates for rounding errors in Mindustry Logicdraw scaleinstruction. - Added the
noControlWithinfunction to theunitssystem library. The function determines whether the current unit lies within a given radius without taking control of the unit.
- Updated the
scaleSmallToLarge()andscaleLargeToSmall()functions to compensate for rounding errors in Mindustry Logicdraw scaleinstruction. - Updated the
log2()function to useop lognwhen possible. - Updated all conditional operators to support string arguments (e.g.,
name == "Phillip"is now a valid expression). - The
noinitkeyword has no longer any effect inlinkedvariable declarations. Guard code is not generated unless theguardedmodifier is used to explicitly request it. - Changed the Case Switching optimization to generate many different ways to compress a jump table, selecting the most efficient one for the given optimization goal and instruction-space constraints.
- Removed the optimization goal
autoand addedneutral. Implemented new optimization selection according to the optimization goal. The Case Switching optimization is capable of generation optimizations for thesizeandneutralgoals.
- Added an explanatory message to the web app when an internal error is encountered.
- Added a case switching optimization-specific test suite to the Extended Testing framework. The tests serve to verify the size and execution costs calculations for the Case Switching optimization are correct.
- Fixed function calls with missing arguments causing compiler error (#259).
- Fixed an internal error compiling loops containing a function call (#258).
- Fixed wrong
unsafe-case-switchingoptimization for small jump tables (#253). - Fixed wrong handling of side effects by the Case Switching optimization (#254).
- Fixed incorrect IDs produced by the
sensor ... @idinstruction (#255). - Fixed unrecognized keywords for some instructions (#256).
- Fixed incorrect block type obtained through the
lookupinstruction in compile-time evaluation and the processor emulator for zero logic ID.
- Added support for the new
op sign,op roundandunpackcolorMindustry BE instructions to the compiler and processor emulator. - Added the
output-profilingcompiler option, which causes the profiling output (number of times each instruction was executed) to be written to the log file.
- Added support for using
nullliterals in case expression. When used in case expressions involving Mindustry content,nullvalues in thewhenclauses are supported by the Case Switching optimization too.
- Breaking: The system library was changed to accommodate the new logic instructions:
- The
signfunction in themathlibrary was renamed tosignInexact. - The
signExactfunction in themathlibrary was renamed tosign. This function corresponds to the Mindustry 8 instructionop sign, and when target 8 is selected, the instruction is used instead of the library implementation. - The order of parameters of the
unpackcolorfunction in thegraphicslibrary was changed to match theunpackcolorinstruction in Mindustry 8. When target 8 is selected, the instruction is used instead of the library implementation.
- The
- When splitting jump tables into multiple segments during jump table compression, the instruction jumping to the next segment is always placed first to make the overall execution of the optimized case expression faster.
- Other improvements to the Case Switching optimization: better optimization, more precise cost and benefit calculation, support for
nullvalues.
- Logic functions take precedence over functions defined in the system library. This allows system libraries to contain functions that can be used when a corresponding Logic function doesn't exist in the current target.
- A list of supported keywords and built-in variables for instruction parameters are now provided by mimex-generated metadata.
- Added a list of accepted built-in variables to the description of functions in the function reference.
- The docker definition was updated to avoid unnecessary recompilations (courtesy of 3bd).
- Updated metadata corresponding to the BE version to the latest available BE build.
- Added new metadata types, fixed zero logic IDs problem.
- Removed unnecessary condition duplication for empty loops (#252).
- Added new functions to the
graphicslibrary:- Added
setAlpha()function which takes a packed color as an argument (including e.g., named color literals) and returns a packed color with an updated alpha channel. - Added
packHsv()function which creates a packed color value out ofhue,saturation,valueandalphacomponents.
- Added
- Expanded the Case Switching optimization:
- Range checking of the input values may be suppressed using
unsafe-case-optimizationcompiler directive. - Case expressions based on Mindustry content (e.g., items, block types, and so on) can be optimized by converting the values to logic IDs and building jump tables using these numerical values.
- Large jump tables containing a lot of unused values may be compressed to save space.
- Range checking of the input values may be suppressed using
- Added module signatures to the remote call mechanism to prevent binding to an incompatible remote module.
- Added support for using the same module in multiple remote processors.
- Added an optional output parameter to the
finished()function, which receives the resulting value of the remote function call if it is already finished.
- Breaking: changed the command-line arguments of the offline compiler:
- The
-ocommand-line option no longer sets the optimization level, but specifies the name of the output file. - The output file needs to be specified using the
-oor--outputnamed argument. - There's a new
-Ooption taking a numerical value (optimization level). Values0to3correspond to optimization levelsnone,basic,advancedandexperimental.
- The
- Breaking: the remote call mechanism was redesigned. When recompiling code in a processor which uses remote calls, all related processors need to be recompiled too.
- The mlog decompiler replaces illegal characters in mlog variable names with underscores. If the names of some variables collide due to these conversions, a numeric index is appended to some of them until a unique name is found.
- Added an instruction index to the function reference.
- Added a list of possible keywords to the description of functions in the function reference.
- Added references to the relevant portion of Yruei's documentation to function reference.
- Fixed an internal error when compiling unused functions (#247).
- Fixed a whitelabel error in the web application when an internal compilation error occurs. The error is reported as a standard error message instead.
- Support for dark mode in the web application (courtesy of 3bd). Light/dark mode follows the browser preference.
- Support for named color literals (e.g.,
%[red]) in target 8.
- Hexadecimal and binary literals can be specified as 64-bit unsigned numbers (e.g.,
0xFFFFFFFFFFFFFFFFrepresents-1). These literals are encoded to mlog as is when possible. If the literal cannot be properly parsed by the target Mindustry version, it is encoded as a signed decimal literal. - Negative hexadecimal and binary literals are encoded to mlog as is (with possible conversion to lower case). If the literal cannot be properly parsed by the target Mindustry version, it is encoded as a signed decimal literal.
- Fixed (hopefully) Discord links in the Readme.
- Fixed the logic ID translation from blocks to IDs and back not handling all types of blocks (#246).
- Fixed a small bug in jump tables generation for unused arrays.
- A document offering some tips on writing a better performing Mindcode.
- Improved list iteration loops generation for symbolic labels to perform the same as a code compiled without symbolic labels.
- Small improvements in chained random array access optimizations.
- Updated metadata corresponding to the BE version to the latest available BE build.
- Fixed some command-line options not having an effect in the command-line tool (#231).
- Fixed wrong handling or hoisted set instruction setting up the return address in later loop unrolling (#234).
- Fixed optimizations removing the
spawninstruction when the output value was not used (#236). - Fixed Condition Optimization not performing the optimization in unrolled loops.
- Fixed an error in compile-time evaluation of an expression involving a character literal (#240).
- Fixed incorrect compile-time evaluation of some logic IDs (#242).
- Fixed possible incorrect handling of arguments passed to the
print()and other output functions (#243).
- Breaking: new
refkeyword was added to the language. Code that uses this keyword as a function or variable name will not compile, and the variable or function will have to be renamed. - Added the
char()function. The function returns the ASCII value of a character at given index from a string value using thereadinstruction, as supported in the latest BE version. - Added support for invoking properties and the
sensorfunctions on string values to support latest BE Enhancement of sensing string lengths using@size. - Added the
strlen()function returning the length of a string determined at runtime. - Added support for compile-time evaluation of the
length()function, allowing to specify offsets relative to the end of the array in subarrays (e.g.,array[0 ... length(array) - 1]). - Added compile-time evaluation of either stable, or all built-in numerical variables (such as
@pior@unitCount). - Added a new remarks mode,
comments, to compile remarks as mlog comments (# comment). - Added support for generating runtime boundary checks for explicitly declared external arrays.
- Added new
printLines()function to theprintinglibrary. The function prints each of its arguments on a new line. - Loop Hoisting optimizer enhanced with an ability to optimize instructions setting up return addresses of function calls.
- Added handling of numerical literal values unsupported by Mindustry Logic version 7 and earlier (namely,
-2147483648). When a numerical literal or constant expression has this value, a compile-time error is generated. - Added support for strings in
readandsensorinstructions to processor emulator. - Added a new
--file-referencescommand-line option. - Added a suggestion of the closest matching alternative when an unknown compiler directive or option value is found.
- Added support for mlog syntax highlighting into the provided IntelliJ file type settings.
- Added support for passing arguments to inline functions by reference. It is possible to pass variables and arrays this way.
- Added new
target-optimizationcompiler directive/command line option. Thespecificoption generates code for the specific compilation target only, thecompatibleoption generates code intended for the compilation target and future versions of Mindustry Logic. - Added array-specific optimizations for speed (available on
experimentallevel). - Added new
arrayssystem library with some basic array functions. The size calculations for the library functions are possibly incorrect, as new means for determining code size of functions taking an array as a ref argument needs to be developed. - Added support for generating symbolic labels instead of instruction addresses in jump instructions, through the
symbolic-labelscompiler directive/command line option. - Added support for applying indenting to the generated mlog code based through the
mlog-indentcompiler directive/command line option.
- Breaking: underscores in multi-word command-line options were changed to hyphens.
- The metadata used by Mindcode compiler and processor emulator now correspond to the compilation target. Schemacode still uses the latest version of the metadata for both building and decompiling schematics.
- Compile-time evaluation cache is cleared when exiting a function context. This forces primarily the
length()function to be reevaluated in each call to an inline function, as its value depends on the actual arguments passed to the function. - Improved optimization of jumps by making multiple passes over jump-related optimizers, up to the optimization passes limit.
- Volatile built-in variables used an upper or lower bound in a ranged for-loop statement are used directly in the condition, without storing them in a temporary variable.
- Stripped unnecessary
.0distinctions from local variable prefix. - The
noinitmodifier is no longer disallowed for local variables. - The processor emulator uses numerical values provided by metadata for built-in variables (such as
@pior@unitCount). The metadata version corresponds to the compilation target.
- Fixed errors when trying to invoke properties on internal array elements (#228).
- Fixed a wrong optimization of list iteration loops (#229).
- Fixed incorrect optimization of
ifexpressions (#230).
- Added a warning when a variable declared volatile is not used anywhere in a program, which would preclude remote access to such a variable.
- Enhanced Temporary Variables Elimination to remove superfluous temporary variables generated by the compiler for volatile variables.
- Updated Dead Code Elimination so that it does not remove dead writes to volatile variables.
- Fixed the Start with a new schematic button causing HTTP 404.
- Fixed the Schematic Decompiler incorrectly processing factories with no unit plan selected.
- Fixed wrong values of
@blockCount,@unitCount,@itemCountand@liquidCountvariables in processor emulator (currently assigned values correspond to Mindustry Logic 8 regardless of the compiler target).
- Added mlog keywords as a preferred way to specify mlog keywords to Logic functions (#215).
- Added support for passing mlog keywords and formattable string literals as arguments to inline functions.
- Added support for creating constants out of mlog keywords.
- Added known mlog keywords to the file type definitions of the provided IntelliJ IDEA IDE settings.
- Added new
mlogText()function for direct encoding of mlog instructions. - Added support for descending iteration order to Range Iteration Loops and List Iteration Loops (#174).
- The description of the storage clause added in Mindcode 3.1 was added to the documentation.
- Added a new Item Transport sample. The sample demonstrates the use of a simple remote call scheme for acquiring units.
- Added support for remote functions and variables (#218).
- Breaking: new keywords were added to the language:
descending,moduleandremote. Code that uses any of these keywords as a function or variable name will not compile, and the variable or function will have to be renamed. - All reads from and writes to variables declared
volatileare preserved now. Volatile variables can be accessed from a remote processor safely. - Prefixes for local variables are created from the function name by default. Use the function-prefix option or command-line argument to generate shorter prefixes.
- Changed the
sort-variablesoption to usedraw triangleinstructions to create variables in a defined order.
- Deprecated the
loopkeyword indo whileloop. - Deprecated specifying mlog keywords without the
:prefix in Logic function calls.
- Fixed the web app page not loading (#227).
- Fixed some syntax errors reported at wrong places (#214).
- Fixed wrong block/unit logic IDs (#224).
- Fixed an error decompiling schematics with Air Factory (#225).
- Added support for internal and external arrays/subarrays (closes #213).
- Added parallel iteration through arrays/lists in list iteration loops.
- Added support for the new
printcharinstruction in compiler, optimizer, and processor emulator. - Added character literals (e.g.,
'A'). The value of the literal is the ASCII value of the character in quotes. - Added the
ascii()function. The function takes a string literal or constant and returns the ASCII value of its first character. - Added the possibility to specify storage different from the heap when declaring external variables.
- Added the "backpropagation" optimization to Data Flow Optimization (closes #151).
- Added support for compiling-in runtime checks for checking internal array elements are not accessed out of bounds. One of the methods uses the MlogAssertions mod, which is currently only available for Mindustry 7.
- The default optimization level in both the web application and command line compiler is now
experimental.
- Fixed functions called using varargs potentially not being recognized as used (#203).
- Fixed an incorrect implementation of the strict equality operator (#206).
- Fixed a wrong reference counting for inline functions (#207).
- Fixed compiler errors when placing enhanced comments into loops.
- Fixed wrong compile-time and emulator evaluation of
asin,acosandatanfunctions (#209). - Fixed compile-time evaluation potentially processing functions not available in the current target. The only affected target was 6, where non-existent functions
asin,acos,atanandpackcolorcould be compile-time evaluated instead of reported as non-existent.
- Added support for encoding the results of compile-time expressions as color literals.
- Added functionality to automatically add a
printflush message1instruction at the end of the main program body if missing from program. - Added the
auto-printflushcompiler directive and--auto-printflushcommand-line option to control the addition of theprintflush message1instruction. - Added explanatory messages to the web app when compiling the source yields an empty program.
- More precise calculations of the optimization benefits in loop unrolling and call inlining.
- The
sensorinstruction is considered deterministic if a deterministic property of a non-volatile value, which is not a linked variable, is being queried. - When clicking on an error or warning in the web application, the entire portion of the source code causing the error or warning is selected.
- Most advanced optimizations were moved to the
basiclevel. Only optimizations that might be incorrect in some contexts (such as optimizations replacing computed IDs of Mindustry items with IDs known to the compiler) are left on the advanced level. - The default optimization level in the web application is now
advanced.
- Renamed virtual instructions to better match their actual use.
- For-each loop reworked to use MultiJump/MultiLabel instructions instead of (former) goto. Goto was renamed to Return, as it is now used solely for returning from stackless calls. Markers are no longer used with Return to bind it with possible return targets.
- Fixed errors when compiling empty bodies of functions and statements (#99).
- Fixed errors when compiling unary plus and minus operators (#175).
- Fixed execution errors not being displayed in the web application (#185).
printflush()anddrawflush()didn't compile when called as methods on blocks (#190).- Fixed Single Step Elimination mistakenly removing some conditional jumps (#199).
- Fixed inaccurate precision loss handling (#202).
- Fixed Data Flow Optimization crashing on a return statement containing conditional expressions (#205).
- Fixed the Web Application not working inside the Docker container.
- Added support for embedding expression in formattable String literals (e.g.,
println($"Items: ${localItems + computeRemoteItems()}.")). - Added support for color literals in the form of
%rrggbbor%rrggbbaa, e.g.,%ff0000is bright red.- The
packcolor()function taking constant arguments is evaluated at compile time or during optimization. - Processor emulator supports color literals.
- The
- Added increment/decrement operators (
++and--) in both prefix and postfix form (e.g.,i++,--total). - Added support for code blocks (delimited by
beginandend). - Added a mechanism for invoking properties on expressions (#92).
- Added support for using external variables and properties wherever "normal" variables can be used (e.g., as output arguments to function calls).
- Added an ability to report errors and warnings in unused functions.
- Added several new library functions
graphicslibrary:- Added
drawflush()function which empties the draw buffer - Added
unpackcolor()function which decomposes a packed color into individualr/g/b/acomponents.
- Added
printinglibrary:- Added
printflush()function which empties the text buffer - Added functions for outputting numbers in binary and hexadecimal base:
formatBinaryNumber(),printBinaryNumber(),formatHexNumber(),printHexNumber().
- Added
mathlibrary:- Added
boolean()function which converts a number to a boolean value (0ifnullor zero,1otherwise) - Added
integer()function which converts a number to an integer by truncating the fractional part - Added
log2()function returning a base 2 logarithm of a number - Added
lerp()function for linear interpolation between two values
- Added
- Added new
--excerptcommand-line option, allowing to specify only a part of the input file to be compiled.
- Added support for explicit variable declarations.
- Newly defined
relaxed,mixedandstrictsyntax modes.
- Breaking: new keywords were added to the language:
begin,cached,external,linked,noinit,varandvolatile. Code that uses any of these keywords as a function or variable name will not compile, and the variable or function will have to be renamed. - Breaking: statements and declaration no longer provide any value, and using them where an expression providing a value is expected causes compilation errors. In the past even statements and declarations were considered expressions, albeit they always evaluated to
null. - Removed
sensorfrom the list of keywords. - The
loopkeyword indo loop whileloops is optional. The keyword will be deprecated and eventually dropped. - Special types of variables (external variables and properties) can be used in the same way as normal variables, e.g., as function output arguments.
- When enhanced comments are used on a line which contains a beginning of a new statement or expression, the output generated by the enhanced comment precedes the first such statement/expression (#185).
- Better reporting of errors and warnings produced during compilation.
- Changed the mechanism of mlog variable names generation.
- Optimization of bitwise and boolean expressions which are incorrect for nonintegers are only performed on
advancedlevel. - Any compile-time constant expression can be used as a value for a program parameter.
- Fixed wrong definition of
control colorinstruction (#194). - Fixed wrong definition of
fetch unitandfetch unitCountinstructions (#197). - Fixed wrong expression optimization of
op subinstruction (#198).
- Fixed the If Expression optimization wrongly applying forward assignment to some instructions. This particular optimization was also moved to the
advancedoptimization level. (#193).
- Fixed a wrong compile-time evaluation of trigonometric functions (radians were assumed instead of degrees used by Mindustry - #192).
- Fixed the documentation stating that
doin loops is optional (#191). - Fixed decompiler output missing the
#set targetdirective (#188).
- Changed Mindcode to recognize new properties supported in Mindustry Version 8:
@currentAmmoType,@armor,@velocityX,@velocityY,@cameraX,@cameraY,@cameraWidth,@cameraHeightand@solid(#187). - The decompiler now produces a function call syntax instead of method call syntax for
printflushanddrawflushinstructions.
- Fixed Function Inlining optimization incorrectly processing functions with output parameters (#183).
- Changed the Print Merger optimization and processor emulator to correctly round numbers in print instructions in accordance with Mindustry Logic update.
- Fixed a wrong Jump Threading optimization in out-of-line functions (#177).
- Fixed bugs in the Data Flow Optimization:
- The virtual
setaddrinstruction, unused due to the corresponding jump being unreachable, wouldn't be removed from code. This caused errors referencing a non-existent label. - Data Flow Optimization would sometimes corrupt the expected code structure when removing unneeded instructions, causing bugs or runtime errors during subsequent optimizations.
- The entry condition to a loop might be incorrectly evaluated, leading to wrong optimizations of some loops.
- A variable read in an unreachable part of code might be reported as uninitialized. This might lead to a compilation error for compiler-generated uninitialized variables.
- The virtual
- Fixed the If Expression Optimization mistakenly propagating a jump into the bodies of the if/else statement, causing errors during subsequent optimizations.
- Fixed the Single Step Elimination occasionally crashing when removing a superfluous jump.
- Fixed the Loop Unrolling Optimization possibly unrolling an incorrect number of iterations on loops with no exit condition.
- Fixed a bug in the implementation of the
median(x...)function in themathsystem library.
- Added a separate Testing Framework command-line tool. The tool allows compiling and running Mindcode source files under various optimization settings, helping to detect bugs in Mindcode.
- Added limited Unit testing support.
- Breaking: changed the default language target from ML7 to ML7A. The following functions are affected:
getBlock: previously, the building at given coordinates was returned through an output parameter. In ML7A, the building is returned through function return value. SeegetBlock().ulocate: previously, the function returned a boolean value (truewhen the building was found,falseotherwise). In ML7A, the function returns a building (if found), and thefoundflag is returned through an output parameter. SeegetBlock().
- Changed automatic generation of IntelliJ IDEA settings files to only modify the zip files when the content of the contained files changes.
- Changed Loop Unrolling Optimization to handle more cases of loop control variable modification run on the
advancedlevel.
Breaking: This release comes with a new keyword in Mindcode syntax (require), which break existing code where this keyword was used as a variable or function name.
- Fixed the
findLinkedBlockslibrary function not to produce a warning about uninitialized variables. - Fixed the mlog decompiler crashing on
jumpinstructions targeting instructions outside valid range. - Fixed an unhandled error when decompiling invalid code from mlog by the web application.
- Fixed
oroperator being evaluated the same as||instead of|by the processor emulator.
- Added warnings for unrecognized built-in variables. An unrecognized built-in variable might be invalid or mistyped.
- Added the built-in math constants
@pi,@e,@degToRadand@radToDegto the processor emulator. - Added automatic generation of IntelliJ IDEA settings files to keep them up to date with the language definition.
- Added a new
requirekeyword for adding a system library or another external file (for command-line compilers) to the compiled code. - Added information about the compiled code size of individual functions to the system library documentation.
- Added new functions to the
printingsystem library (printExactFastandprintExactSlow). - Added new functions to the
mathsystem library (round,frac,sign,isZero,isEqual,nullToZero,sum,avg,median). - Added configurable execution flags governing the behavior of the processor emulator.
- Breaking: changed the system library to several separate files that can be included in the compiled code using the
requirekeyword. The system libraries are no longer automatically loaded when compiling forML8Atarget, and most of them can be used with earlier targets as well. - Changed rules for function overloading: a vararg function doesn't conflict with a non-vararg function. When a function call matches both a vararg function and a non-vararg function, the non-vararg function will be called.
- Changed all variables within system libraries to use the
_prefix, to avoid possible clashes with constants and program parameters declared in the main file. - Changed existing examples to use functions from the system library where one is available.
- Changed processor emulator to output all existing variables and their values when encountering the
stopinstruction. - Changed the Condition Optimization to handle cases where the jump instruction contains a value produced by a function.
Breaking: This release comes with new keywords in Mindcode syntax (begin, var and void), which break existing code where those new keywords were used as a variable or function name.
- Fixed an incorrectly processed case expression passed into functions (#107).
- Fixed arguments incorrectly passed to recursive calls (#169).
- Fixed output function parameters incorrectly accepting expressions as arguments (#170).
- Fixed an error when allocating a stack using the ML8A target (#171).
- Fixed optimization not recognizing all interactions with Mindustry World (#172).
- Fixed wrong optimization of List iteration loops with output iterator variables (#173).
- Added a new
voidkeyword for declaring functions not returning any value. - Added a new
beginandvarkeywords reserved for future use. - Added support for omitting optional arguments in the argument list.
- Added support for the special
@waitargument of themessage()function.
- Added output and input/output parameters of user-defined functions.
- Added vararg (variable arity) functions.
- Added function overloading.
- Added the possibility to specify custom instructions not known to Mindcode through the
mlog()function. - Added the
findLinkedBlocksfunction to the system library.
- Changed the Loop Unrolling optimization to replace output iterator variables with the variable assigned to them.
- Changed the Single Step Eliminator to remove a jump is if there is an identical jump preceding it and there are no other jumps or labels between them. Active on
experimental. - Changed the expression evaluator to evaluate operations over known built-in values. The change enhances the Data Flow and Jump Normalization optimizations.
- Changed the Schemacode compiler to correctly output positions of error messages generated by both the Schemacode and Mindcode compilers, taking into account both the source file and/or position of the Mindcode program or program snippet within the source file.
- Deprecated the syntax of properties omitting the
@prefix for Mindustry built-in variables (e.g.,vault1.coalinstead ofvault1.@coal). - Deprecated the syntax of Mindustry Logic function calls not requiring the
outmodifier when passing in an output argument.
- Improved the command-line tool output of the Compile Schemacode action.
- Fixed Copy to clipboard button not working (#168).
- Fixed an unhandled error when decoding a malformed Schematic file string by the web application.
- Fixed Schemacode samples to not use deprecated syntax.
- Added support for partially decompiling existing mlog code into Mindcode.
- Fixed a wrong compilation order of appended files (#155).
- Fixed inadequate reporting of syntax error (#156).
- Fixed wrong handling of comparison operators by Data Flow Optimization (#158).
- Fixed wrong parsing of formattable string literals.
- Fixed inadequate handling of unsupported expressions embedded in formattable string literals.
- Breaking: Added support for syntax variants (
strictandrelaxed) to Mindcode. The Strict syntax is the default now; to be able to compile existing Mindcode the Relaxed syntax needs to be activated using the#relaxed;directive. - Added support for the Mlog Watcher Mindustry mod integration to both the web app and the command-line tool. This mod allows the compiled code to be automatically injected into a selected processor in a running Mindustry game.
- Added variable name validation: when inserting mlog into Mindustry processor, variables named
configureare silently renamed toconfig. For this reason, usingconfigureas a name for any variable in Mindcode causes an error. - Added navigable compiler error messages to the web app. Clicking on a message with a known position in the source code selects the corresponding position in the editor.
- Added support for outputting the error messages by the command line tool in a format which allows IDEs to parse the position and navigate to the error location in the source code.
- Added a variety of new optimizations to the Expression Optimization.
opinstruction: many new optimizations when one of the two operands is known.lookupinstruction: when possible, the instruction is replaced by asetinstruction setting the item, liquid, building, or unit directly to the target variable, allowing further optimizations to take place. Effective onaggresiveoptimization level.
- Added warning messages when deprecated features are detected in the source code.
- Added support for creating constants from formattable string literals.
- Added full support for the
sync()function: a variable passed as an argument to this function becomes automatically volatile.
Schemacode
- Added support for block comments, delimited by
/*and*/. These comments can span multiple lines.
- Added support for Mindustry Logic from upcoming version 8. The features supported correspond to the current implementation in Mindustry and might therefore still change. All new features are described in separate documentation.
- Added a system library, automatically included when the language target is
8Aor later. - Added support to the If Expression Optimization to propagate values in
ifexpressions not just into thesetinstruction, but into any instruction taking an input parameter. Available on theexperimentaloptimization level.
- Breaking: Changed the implementation of the
printf()function under language targetML8A. Instead of compile-time formatting of passed parameters, the function usesprintandformatinstructions for run-time formatting. - Changed the definition of the
&&and||operators: they are guaranteed to always evaluate to either0or1. - Changed the
min()andmax()functions to accept more than just two arguments. - Changed the Temporary Variables Elimination optimization to replace unused output variables in instructions with
0, to ensure no unnecessary variable gets created by the instruction, reducing clutter. Closes #154. - Changed the If Expression Optimization to support value propagation for all instructions having one output parameter (based on instruction metadata), instead of just a subset of specifically handled instructions.
- Changed—yet again—the way the Single Step Elimination optimization removes the last instruction, which is a jump to the beginning of the program, so that it doesn't leave behind any jump that might have targeted the removed instruction. Such a jump was harmless, but unnecessary and looked strange in the mlog.
- Changed the text buffer handling in the processor emulator to recognize identical outputs produced by consecutive
printflushoperations and avoid creating duplicate outputs. - When a compiler-generated variable is evaluated as uninitialized (this situation generally indicates an optimization bug), an internal error is thrown.
- Deprecated the original Mindcode syntax.
- Deprecated the usage of parentheses around the list of values in list iteration loops.
- Deprecated escaped double quotes in string literals.
- Deprecated kebab-case identifiers (note that built-in mlog variables, such as
@blast-compound, will continue to be supported). - Deprecated the
printf()function in language targetML7Aand earlier. - Deprecated the
configureproperty. This property from Mindustry Logic 6 was replaced byconfigin Mindustry Logic 7.
- Added parallel execution of unit tests.
- Renamed the command-line tool module from
compilertotoolapp, and the Mindcode compiler module frommindcodetocompiler. - Renamed the files in
bindirectory frommcc/mcc.battomindcode/mindcode.bat.
- Fixed the layout of the web page not rendering well on smaller screens and mobile devices.
- Changed the Single Step Elimination optimization to remove the last instruction if it jumps to the start of the program (not just
end, but also unconditional jump) onadvancedoptimization level.
Breaking: This release comes with three new keywords in Mindcode syntax (noinline, out and param), which break existing code where those new keywords were used as a variable or function name.
- Fixed wrong size computation of code generated by the
remark()function if theremarksoption was set tononeoractive. - Fixed Data Flow optimization incorrectly handling equality and inequality comparisons (#146).
- Fixed Data Flow optimization incorrectly processing execution paths through a case expression (#147).
- Fixed Function Inlining optimization missing some opportunities to inline a function.
- Fixed the
webapp.batfile not working on Windows due to classpath being too long.
- Added a secondary set of icons representing constants with dashes in identifiers replaced by underscores (e.g.,
ITEM_COALinstead ofITEM-COAL). Kebab-case identifiers (with dashes) are deprecated in Mindcode and will be desupported in a future release. (In Schemacode, there are currently no plans to remove support for kebab-case identifiers.) - Added support for declaring program parameters using a new
paramkeyword. Using global variables for program parametrization is deprecated, program parameters should be used instead. Support for program parametrization through global variables will be removed in a future release. - Added a new
noinlinekeyword, which will prevent a function from being inlined even when called just once, and by the Function Inlining optimization. The keyword can only be used when declaring a function. - Added support for block comments, delimited by
/*and*/. These comments can span multiple lines. - Added a new schematic sample with quite a sophisticated code on the Schematics page. It consists of an overdrive dome supplied by units controlled by a microprocessor. The microprocessor searches for available units among a list of supported types, switches to the preferred unit type when it becomes available, and rebinds units (possibly switching the type again) if units in use are destroyed or taken over by the player or a rogue processor.
Experimental features may contain bugs, break existing code or produce suboptimal code, and are subject to change.
- Added support for multiple loop variables in list iteration loops. Each iteration processes as many elements from the list as there are loop variables.
- Added an
outkeyword to be used with loop control variables in list iteration loop, allowing list elements to be modified. - Added a new GUI option to choose an optimization level in the web app when compiling Mindcode or building Schemacode.
- Added a capability to run the compiled code on an emulated processor, by using a
Compile and Runbutton in the web app, or the--runcommand line option. The output is shown in a separate control in the web app or written to the log when using the command line tool. - Added a capability to the command line tool to compile several source files at once using the
--appendcommand line argument. - Added new optimization level,
experimental. When using this setting, the Data Flow optimizer doesn't assume the assignments to global variables might be changed by editing the compiled code, allowing performing more optimizations on them. Program parameters must be used instead of global variables for program parametrization if this optimization level is used. - Added formattable string literals, which allow formatting outputs of the
printandprintlnfunctions the same way asprintfdoes. - Added enhanced comments, an alternative way to enter remarks.
- Added new
sort-variablescompiler directive which ensures that user variables will be accessed in a well-defined order, to make inspecting the variables in the Mindustry processors Vars screen easier. - Added generation of signature at the end of the compiled code. The signature is a
printinstruction (which is not executed) with the textCompiled by Mindcode - github.com/cardillan/mindcode. The signature is not added should the instruction limit be exceeded or when the program doesn't naturally end in an unconditional jump. Adding the signature can be disabled in the command line tool by the--no-signaturecommand line argument.
- Changed the names of optimization levels from
offandaggressivetononeandadvanced. The former names are still supported in the#setcompiler directive, but not in the command-line options. - Changed the Loop Hoisting optimization to analyze functions modifying variables inside loop instead of a blanket assumption that all global variables may be changed by a function.
- Changes to the web app
- A button was added to the web app to copy the output code to the clipboard with a single click.
- It is now possible to select the optimization level directly in the web app user interface. The default optimization level is now
basicfor Mindcode compiler andadvancedfor Schemacode builder.
- Changed the syntax to allow an optional
dokeyword in allforandwhileloops, and optionalthenkeyword inifandelsifstatements. - Changed the Single Step Elimination optimization to remove the
endinstruction at the very end of the program onadvancedoptimization level. - Changed the command line tool to output final instruction numbers when printing out the unresolved code, for easier localization of errors reported when running the compiled code on an emulated processor.
- From this version (
2.2.0) on, Mindcode will use semantic versioning (the major version will be increased for significant changes to the syntax). The command-line tool now reports the version when passed in-vor--versionas a parameter. - Replaced pattern matching in switch cases (JDK17 preview feature) with
ifand other constructs to remove the dependency on the--enable-previewswitch. - Updated existing Mindcode and Schemacode samples further to adapt for upcoming changes in syntax (optional keywords were added). Some samples were reworked.
- Fixed a slightly wrong (too low) cost estimation in the Case Switching optimization.
- New
remark()function, as described here.
- Slightly improved the Case Switching optimization -
instead of expanding the jump table range by one on each side and limiting the input value using the
op minandop maxinstructions, the jump table covers only the existingwhenbranches and values outside the supported range are handled using conditional jumps. This change saves two instructions and potentially speeds up the execution for input values lying outside the jump table.
- Some of the Mindcode samples used during unit tests were updated to use semicolons in anticipation of planned Mindcode changes.
- Fixed wrong expression handling in loops by Data Flow Optimizer (issue #131).
- Fixed Data Flow Optimizer not removing some superfluous variables when using
caseexpressions (issue #133). - Fixed Data Flow Optimizer incorrectly applying common subexpression optimization in some cases (issue #133).
- Added support for specifying processor code (both Mindcode and mlog) as a concatenation of multiple code snippets from various sources (string literal, string constant, or external file).
- Added a new Mandelbrot Generator schematic example.
- Starting from this release, releases will be published in GitHub
including the Mindcode compiler provided as a
.jar(binary) file.
- Fixed incorrect handling of inlined function return values (issue #130).
- Fixed the Data Flow Optimizer incorrectly reporting variables initialized inside an infinite
whileloop as uninitialized (issue #127). - Fixed the Loop Hoisting Optimizer incorrectly hoisting assignments from a function return variable (issue #129).
- Added support for block type, unit type for payload-source and unit command configurations to Schemacode compiler and decompiler. This definitely resolves issue #122.
- Added support for handling list iteration loops and loop invariant
ifexpressions to the Loop Hoisting optimization.
- Fixed comments on the last line of source code causing compilation errors (#110).
- Schemacode compiler and decompiler now use mimex-generated metadata for lists of items, liquids, and unit commands. All Mindcode object definitions are now loaded from extracted metadata and not from separate definitions, in Mindcode as well as in Schemacode.
- The documentation of Loop Hoisting optimization now uses diff-style mlog code listings to demonstrate the effects of optimizations on emitted code. The goal is to gradually replace all suitable optimization examples to this format.
- Added Loop Hoisting optimization. This optimization moves invariant code out of loops.
- Added new reserved keywords
elseifandelif. Using these keywords will result in a compilation error (see #121).
- Schemacode decompiler now ignores some block-specific configurations that aren't supported yet (see #122). This is a temporary measure to prevent the decompiler crashing on such schematics until these configurations are fully supported.
- Fixed wrong optimization of side effects in the
whenexpressions (#119).
- Changed AstContext to store
CallGraph.Functioninstances instead of a function prefix (String) to identify functions. All other classes that handle functions now operate on functions themselves instead of the prefixes. Avoids function lookups from local prefixes and increases type safety.
- Added limited support for the new
syncinstruction through thesync()function. The function requires a global variable as a parameter (see thesync()function for the description of the function and the limitations imposed on it). - Added support for the
effectinstruction. - Added more capabilities to the
Expression Optimization:
- Replacing
@this.xand@this.yexpressions by the@thisx/@thisybuilt-in constants. - Replacing
@constant.idexpressions by an integer value of the ID assigned to the@constant, assuming it is a known item, liquid, block type, or unit type. This optimization is only active onaggresiveoptimization level. For example,id = @graphite.idgets compiled down toset id 3, allowing further optimizations on the constant value (3) to take place. - Replacing multiplication by literal zero by an instruction setting the target variable to a zero directly, and replacing multiplication/division by one and addition/subtraction of zero by an instruction setting the target variable to the other operand directly.
- Replacing
Note
Mindustry 7.0 build 146 added—among other improvements - the id property that provides an id of given
block, unit, item, or liquid (basically the inverse of the lookup operation). Since Mindcode has a generic support
for properties and built-in constants, this property can be used right away; no explicit support from Mindcode is
needed. For example:
item = sorter1.config
numericId = item.id
print(numericId)
property = @id
value = item.sensor(property)
print(value)
id = @graphite.id
print(id)
Among the new logic instructions, autoPathfind is already supported. Support for the new world-processor
instructions is yet to be added.
- Added support for the
ucontrol autoPathfindinstruction through theautoPathfind()function (PR #113).
- Fixed Loop Unrolling failing on loops that do not have a loop control variable (#109).
- Fixed Function Inlining optimization incorrectly inlining some functions containing a return statement (#116).
- Fixed Function Inlining optimization incorrectly inlining functions used in expressions (#118).
- Fixed
turretnot being recognized as a block name (#117).
- Mindcode compiler now uses metadata extracted by mimex to obtain a list of possible block names.
- Function Inlining optimizer now replaces the function return variable with the receiving variable when inlining a function call. The protection granted to function return variables is not necessary after inlining the call, and this replacement allows the receiving variable to be handled by further optimization.
- Small documentation improvements.
- No-op instructions are removed before the final optimization phase, avoiding the need to handle no-op by the final phase optimizers.
- Fixed a bug in the code duplication routine that sometimes prevented Unreachable Code Elimination from removing unreachable portions of optimized case statements and inlined functions. The bug sometimes caused runtime exceptions when optimizing for speed, usually under tight instruction space restrictions only.
- Fixed #108 Compilation errors are not properly reported.
- Changed weight computation of user-defined functions. Weight of a function is computed as a total weight of all
its
CALL, resp.CALLRECinstructions.
- Added Case Switching optimization. This optimization converts suitable case expressions to use jump tables.
- Added Return Optimization improving some very specific cases sometimes arising in recursive functions.
- Added compiler option to alter the instruction limit for speed optimizations.
- Fixed a wrong cost estimation in Loop Unrolling. The cost estimates were too high, potentially preventing some eligible loops from being unrolled.
- Fixed the compiler not recognizing integer values in compiler option directives (
#set).
- Changed Jump Threading to also replace jumps leading to
gotoinstructions with thegotoinstruction itself onaggressivelevel. There's a possible speedup in some stackless function calls and list iteration loops. - Changed Single Step Elimination to also remove two consecutive jumps that are identical. Such sequences were sometimes produced as a result of other optimizations.
- Changed Data Flow Optimization to use a single instruction iterator instance instead of making an instruction list from each AstContext being processed. Significantly speeds up processing.
- Additional optimizers converted to adding no-op instruction instead of removing them; updated other optimizers to correctly handle such code.
- Fixed a bug in Function Inlining that caused runtime exception in some circumstances.
- Fixed a bug in Data Flow Optimization that may have removed instructions that were actually used by the program.
- Changed Data Flow Optimization to perform fewer iterations in certain situations. The reduction is significant (up to fivefold in tested scenarios) and translates into faster compilation times in these scenarios.
- Changed optimizers that need to be compatible with AST context structure to replace instructions with a no-op instead of removing them, preserving the AST context structure. Prevents potential bugs in optimizers relying on AST context structure.
- Added list iteration loop unrolling to Loop Unrolling optimization.
- Added Function Inlining. Stackless functions and even individual function calls may be selected for inlining based on expected benefit and available instruction space.
- Fixed incorrect weight computation of user-defined functions. Currently, weight is based on the number of times a function is called in the program. This is still not quite correct, though—the weight should be computed by tracking call hierarchy and weights of contexts containing the calls.
- Fixed incorrect weight computation of list-iteration loops. The weight was set to the actual number of loops instead of the unified loop weight.
- Changed option name
conditional-condition-optimizationtocondition-optimizationto conform with documentation.
- Eliminated
STORED_RETVALvariable type. Values returned from user-defined function calls are now assigned to standard temporary variables, as their usage is correctly tracked by Data Flow Optimizer and no longer requires special handling.
- Fixed main variables being mistakenly reported as uninitialized by Data Flow Optimization on
basicoptimization level.
- Changed Unreachable Code Elimination to perform actual control flow analysis and remove all unreachable regions of code, instead of relying on active labels to detect reachable instructions. This change eliminates some unreachable code not recognized before, such as loops inside unreachable regions of code.
- Changed Data Flow Optimization to protect assignment to uninitialized variables made before calling an out-of-line
or recursive function that might call the
end()function. Hopefully all possible means of calling theend()function are finally covered. - Changed the printout of the unresolved instruction (activated by the
-ucommand line option) to omit inactive labels.
- Added a general optimization for speed mechanism. Various opportunities for optimizations that improve execution speed at the price of code size increase are identified and realized in the order of decreasing efficiency until the opportunities or the available instruction space are exhausted.
- Added Loop Unrolling optimization.
- Added compiler option to limit the number of performed optimization passes.
- Fixed If Expression optimization failing to preserve variable value (#101).
- Fixed
mcc.batandwebapp.batfiles missing in thebindirectory.
- Changed Data Flow Optimization to optimize main
variables even on
basiclevel. Only final assignments to main variables are preserved onbasiclevel, other assignments can be optimized away. This change allows the Loop Unrolling optimization to be functional even onbasicoptimization level. - Changed condition duplication by Loop Optimization to use the general optimization for speed mechanism.
- Changed various optimizations for minor improvements:
- The number of times the Data Flow Optimization has to process loops was reduced.
- Jumps Normalization now recognizes always true/always false conditional jumps based on known variable values.
- Improved handling of complex conditions in Loop Optimization.
- Print Merging can merge print instructions across inactive jump labels.
- Added support for executing multiple optimization passes. This allows individual optimizers to incrementally improve the code while benefiting from changes made by other optimizers.
- Fixed incorrect handling of chained assignments (#100). Two
separate problems were fixed:
- Chain-assigning a result of ternary operator/if expression could be compiled incorrectly.
- Chain-assigning a volatile value (such as
@tickor@time) could result in different values being written to variables.
- Fixed a bug in the processor emulator that incorrectly assigned some values to variables. New unit tests uncovered the bug; processor emulator is not used in production code at the moment.
- The Data Flow Optimization now properly handles
assignments to uninitialized variables made before calling the
end()function.
- Removed Return value optimization and Temporary inputs elimination. These optimizations were completely superseded by the Data Flow Optimization.
- Removed the old command-line compiler and the
mindcode/mindcode.batfiles in thebindirectory.
- Added support for the
unitHealthfunction.
- Fixed Data Flow Optimization incorrectly handling
break,continueandreturnstatements (#98).
- Statistics about executions of processor-based unit tests are now collected and committed to the repository, allowing to track the evolution of the efficiency of generated code over time.
- Added support for the new
angleDiffoperation in Mindustry v145.
- Added elimination of useless
setinstructions (such asset x x) to Expression Optimization. Optimizes recursive function calls passing unchanged value of a function argument to the next function call. - Added elimination of variables never modified by a function from stack in Stack Optimization.
- Added specific optimization for recursive function calls to the
Data Flow Optimization:
- The optimizer is aware when a variable value is preserved on the stack and can reuse the variable state when optimizing code following a recursive function call.
- Streamlining expressions when passing value derived from the current value of the function argument to the
recursive call (e.g., calling
foo(n - 1)in functionfoo(n)).
- Fixed Data Flow Optimization crashing when source code contained unused user-defined functions (#97).
- Fixed misspelled name of the
case-expression-optimizercommand-line and compiler directive option (wasease-expression-optimizerbefore).
- Docker configuration updated to not expose the PostgreSQL port to the host machine. It is now possible to run Mindcode in Docker even when PostgreSQL is also installed and running on the host machine.
- Added processor unit tests based on Project Euler problem solutions.
- Added statistics generation for processor unit test (captures size of the compiled program, number of steps to reach the solution, and code coverage in terms of mlog instructions). These should document improvements in the quality of the generated code.
- Added Constant folding to Data Flow Optimization.
- Added Common subexpression optimization to Data Flow Optimization.
- Removed Function call optimization. This optimization was completely superseded by the Data Flow Optimization, which handles all cases previously optimized by Function call optimization and is able to identify more opportunities for optimization. The old optimization was removed because it became incompatible (i.e., produced wrong results) with the code produced by Data Flow Optimization.
- Deprecated Return value optimization. This optimization was completely superseded by the Data Flow Optimization, which handles more cases than the old optimization. The Return value optimization will be removed when it becomes incompatible with further changes to code generation/optimization.
- Deprecated Temporary inputs elimination, for the same reasons as above.
- Added Data Flow Optimization. This optimization could remove user-defined variables from compiled code—see the documentation for details.
- Fixed some syntax errors in source programs not being properly reported. Some syntax errors were ignored, others might have caused unhandled exceptions in the web or command line application. When a syntax error occurs, partially generated code is no longer displayed in the web application.
- Fixed the compiler not producing any code when optimizations were switched off.
- Fixed an incorrect creation of schematics containing bridges. Configuration for bridges and other blocks that connect
to a single other block was mistakenly written as an array of connections into a
.mschfile, which are ignored by Mindustry.
Note: the bug fixed in this release only affects the command line tool. The web app hasn't been redeployed.
- Fixed the command line tool application not properly recognizing actions.
- Added If Expression Optimization. Sometimes it only decreases the number of instructions by rearranging them, in other cases it can decrease the number of executed instructions. Only ternary expressions and if statements containing both true and false branches are affected.
- Fixed the range iteration loops not having the upper boundary fixed under some conditions. The feature announced in release 2023-05-03 wasn't fully implemented until now.
- Fixed bugs in the stack optimization. In some cases,
push/popinstructions were mistakenly removed, in other cases unnecessarypush/popinstructions were left in the code. The current implementation uses AST structure metadata to identify and protect variables used in loops.
- Generated mlog instructions are now linked to the AST nodes they were created from (via instances of AstContext),
and through them to the parser tokens (for now in somewhat coarse granularity).
- This allows optimizers to inspect source AST nodes of individual instructions, obtaining information about code structure. Optimizations based on these metadata should be easier to write and understand, once necessary support tooling is in place.
- It is necessary to update the AST context structure after each optimization iteration. These updates aren't done of the fly—optimizers must understand that the changes they make to the program in a single iteration aren't reflected in the AST context structure.
- Optimizers need to be careful to create newly generated instructions using the right (already existing) AST context, otherwise the following AST context-based optimizers can misunderstand the code structure. There are means to duplicate existing code while deep-copying the context structure.
- Instructions can be linked to source code. At this moment it can be only displayed using the
-f sourcecommand line argument, hopefully in the future a better error reporting will be built using these metadata.
- Added option for code generation goal. Allows specifying whether to aim for a smaller code or a faster code.
- Added basic loop optimization.
Note: the bug fixed in this release only affects the command line tool. The web app hasn't been redeployed.
- Fixed the command line tool application crashing when decompiling a schematic.
- Added language target
7A, i.e., Mindcode Logic version 7, revision A. Uses the same instruction set as7, except thegetBlockandulocatefunctions returning the located block/building. SeegetBlock,ulocate. Target7is still default both in webapp and in the command line tool, so the change doesn't break existing code. - Added support for the reintroduced
ucontrol pathfindinstruction. When issued, navigates the current unit to a given location using AI to avoid obstacles. Seeucontrol. - Added command line options for Schematic Decompiler
to specify order in which blocks are written to the schematic definition file and when to generate the
facingdirective. - Added support for color configuration and unit configuration in Schemacode.
- Added overlapping blocks detection. Overlapping blocks now cause compilation errors.
- Added support for non-zero schematic origin.
- Added validation of bridge and mass driver connections. Invalid links now cause compilation errors.
- Added validation of power node connections. Invalid links now cause compilation errors.
- Added support for unidirectional declaration of connections between power nodes: it is no longer necessary to declare a connection between two power nodes in both directions to have it reliably created when building the schematic.
- Fixed the handling of block label reuse in schemacode. Reusing the same label for multiple blocks now causes an error.
- Fixed #93: Mindcode compiled wrong when using semicolons.
- Added Schematics Builder tool with a new Schemacode language.
- Added a new command-line interface for the Mindcode Compiler, Schematic Builder, and Schematic Decompiler.
- Added Schematics Builder and Schematics Decompiler interface to the web application.
- Breaking: changed names of
individual optimization options from
camelCasetokebab-case. The same option names are now used with the new command line tool as in the#setdirective.
- Deprecated the old command-line compiler, it was replaced by the new command line tool and will be removed in one of the future releases.
- Created Mindustry Metadata Extractor, a Mindustry mod. The mod, when loaded into the game, extracts various Mindustry metadata and writes them into external files to be used by Mindcode. At this moment, only block types for Schematics Builder are extracted, but more metadata will follow.
- Created Schematics Refresher, another Mindustry mod. The mod
refreshes schematics stored in the
/schematicssubdirectory whenever the game loads or the Refresh button in the Schematics screen is used. The mod allows refreshing schematics after they were rebuilt by Schematics Builder.
- Added support for using Mindustry built-in icons in
printfunctions. - Added support for compile-time string concatenation.
Allows—among other things—to embed icons into string constants at compile time, such as
const HEADER = "Using unit: " + UNIT-MEGA
- Breaking: changed range iteration loops to evaluate the upper boundary only once, before entering the loop for the first time. The previous version evaluated the upper bound at each iteration and reflected possible changes in the upper bound. The documentation was expanded to specify the evaluation of the upper bound. Use a while loop or a C-style loop if you want to fully evaluate the loop condition at each iteration.
- Changed handling of non-constant string expressions: when detected, a compilation error occurs (see also string concatenation).
- The
compilermodule has been renamed tomindcode. Thecompilermodule name will be repurposed for a new command-line interface to themindcodemodule and an upcomingschemacodemodule.
- Enhanced print merging optimization to merge non-string literals (e.g., numeric constants) on aggressive optimization level.
- Changed handling of hexadecimal and boolean literals to include range checks and refuse literals outside the valid range (signed 64-bit integer; note that Mindustry Logic variables cannot represent the full range of possible values without loss of precision).
- Logic instructions arguments are represented by objects with proper attributes and type information instead of plain strings.
- Added Return value optimizer. Improves processing return values from function calls.
- Added section about using units to Mindustry Tips and Tricks.
- Added warnings when constant expression evaluation or Mindcode numeric literal cannot be compiled to mlog without a loss of precision.
- Changed
ubindfunction to return the freshly bound unit. - Changed encoding of numeric values to mlog.
- Fixed constant expression evaluation crashing on binary numeric literals.
- Fixed constant expression evaluation producing values not representable in mlog source code.
- Fixed the function call optimization not processing numeric literal arguments in some cases.
- Added support for using binary numeric literals
(e.g.,
0b00101) in a Mindcode source code. - Added support for using
scientific notation in numeric literals
in a Mindcode source code. Literals compatible with mlog are kept unchanged, literals unrecognized by mlog (e.g.,
1.5e-5) are converted to mlog-compatible representation (in this case,15e-6). - Added simple expression optimizer.
Current implementation replaces
mulby a constant or anidiv/divfollowed by afloorwith a singleidivinstruction.
- Updated the project to use Java 17.
- Fixed constant expression evaluation creating numeric literals incompatible with mlog. (Mlog recognizes
decimal point and an exponent, but not both in the same literal;
1.5e-5is not a valid mlog number.)
- Fixed optimizer incorrectly merging instructions across
printflush()calls (#91).
- Added limited support for compile-time constant expression evaluation.
- Added support for constant declaration (
const foo = 1 / 3). The value assigned must be a compile-time constant expression. - Added compiler directives (
#set): optimization and target instruction set can be now set from the web app compiler. - Support for the new
setpropworld processor instruction available in Mindustry v143.
- Numeric literals are now placed directly into code without intermediate temp variable allocation. Produces better unoptimized code (optimization would remove the variables anyway).
- String constants, in addition to string literals, are accepted as the first printf() argument.
- Numeric constants, in addition to numeric literals, are accepted in stack and heap declarations.
- Minor optimization improvements.
- Syntax documentation overhauled.
- Fixed lots of typos both in produced outputs and supporting documentation.
- Warning and information messages from the compiler/optimizer are now shown in the web app.
- Fixed parameters not being passed to inline functions (#89).
The full changelog wasn't kept for earlier releases. What we know is documented separately here (click the date for fuller description):
- Several breaking changes were made: new keywords, different handling of variables corresponding to linked blocks, significant changes to functions, stricter instruction argument validation.
- Full support for Mindustry Logic 7.
- Overhaul of user-defined functions: inline, stackless and recursive, local scope for function variables and parameters, return statement.
- Improved case expressions
- Do-while loops and list iteration loops
- Break/continue statements for loops
- printf() and println() functions
- All known bugs fixed
- User-defined functions
- More examples
- ...
- Added syntax documentation
- Added full support for drawing,
uradarandulocate - Added support for heaps, meaning auto-allocated global variables
- Added case / when expressions
- For loops
- Added support for the ternary operator, a more compact form of if/else expression:
self = @unit == null ? bind(@unit) : @unit - Added a new sample: patrol around a building and heal any damaged ones
The first release.