diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index b4f9d5f82..8d8055467 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## Unreleased +## 2024-01-22 ### Added @@ -12,14 +12,14 @@ All notable changes to this project will be documented in this file. * Added support for the [`effect` instruction](doc/syntax/FUNCTIONS_V7A.markdown#instruction-effect). * Added more capabilities to the [Expression Optimization](doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown#expression-optimization): - * Replacing `@this.x` and `@this.y` expressions by `@thisx`/`@thisy` built-in constants. - * Replacing `@constant.id` expressions 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 on `aggresive` optimization level. + * Replacing `@this.x` and `@this.y` expressions by the `@thisx`/`@thisy` built-in constants. + * Replacing `@constant.id` expressions 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 on `aggresive` optimization level. For example, `id = @graphite.id` gets compiled down to `set id 3`, allowing further optimizations on the constant value (`3`) to take place. - * Replacing multiplication by literal zero with setting the target variable to a zero directly, and replacing - multiplication/division and addition/subtraction of a zero with setting the target variable to the other operand - directly. + * 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. ## 2024-01-19 diff --git a/README.markdown b/README.markdown index d49473f03..2d81f9b07 100644 --- a/README.markdown +++ b/README.markdown @@ -15,6 +15,7 @@ The main focus of Mindcode design is two-fold: Some of the latest enhancements to Mindcode are: +* All instructions added in Mindustry 7 build 146 are now supported. * A number of powerful code optimizations: [Data Flow Optimization](doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown#data-flow-optimization), [Loop Unrolling](doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown#loop-unrolling), diff --git a/ROADMAP.markdown b/ROADMAP.markdown index 1ca0e9174..57f1d0851 100644 --- a/ROADMAP.markdown +++ b/ROADMAP.markdown @@ -14,10 +14,14 @@ This documents servers as a scratch pad to track ideas and possible enhancements # Incremental improvements -* Expand Data FLow Optimization to handle multiplication by zero, multiplication/division by one, and - addition/subtraction of zero directly. +* Expand handling of expressions by the Data Flow Optimization: + * handle multiplication by zero, multiplication/division by one, and addition/subtraction of zero directly (i.e. + independently of the Expression Optimization). + * When there are two subsequent MUL/DIV or ADD/SUB instructions, the first one not being used by any other + instruction and the second one containing a constant, move the constant to the first instruction. Would facilitate + constant folding for more complex expressions. + * Add factoring-out capability to more complex expressions. * Utilizing the new `id` property: - * Add built-in constants to the documentation, ensure uniform terminology. * Schemacode * replace the `Item` and `Liquid` enums with metadata, possibly utilize units). * Mindcode diff --git a/doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown b/doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown index 4b9335103..7b93f3fb8 100644 --- a/doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown +++ b/doc/syntax/SYNTAX-6-OPTIMIZATIONS.markdown @@ -117,6 +117,9 @@ optimizations are available: * `sensor var @this @x` and `sensor var @this @y` are replaced by `set var @thisx` and `set var @thisy` respectively. Data Flow Optimization can then apply [constant propagation](#constant-propagation) to the `@thisx`/`@thisy` built-in constants. +* Multiplication by literal zero is replaced by a `set` instruction setting the target variable to a zero. +* Multiplication/division by one and addition/subtraction of zero are replaced by a `set` instruction setting the + target variable to the other operand. * All set instructions assigning a variable to itself (e.g. `set x x`) are removed. If the optimization level is `aggressive`, the following additional expressions are handled: diff --git a/mindcode/src/test/java/info/teksol/mindcode/compiler/functions/StandardFunctionsTest.java b/mindcode/src/test/java/info/teksol/mindcode/compiler/functions/StandardFunctionsTest.java index a18e87f32..2c5dc49b7 100644 --- a/mindcode/src/test/java/info/teksol/mindcode/compiler/functions/StandardFunctionsTest.java +++ b/mindcode/src/test/java/info/teksol/mindcode/compiler/functions/StandardFunctionsTest.java @@ -174,4 +174,14 @@ void generatesNewPathfind() { createInstruction(END) ); } + + @Test + void generatesNewAutoPathfind() { + assertCompilesTo(""" + autoPathfind() + """, + createInstruction(UCONTROL, "autoPathfind"), + createInstruction(END) + ); + } } diff --git a/webapp/src/main/resources/templates/common.ftlh b/webapp/src/main/resources/templates/common.ftlh index aade0c8e4..2cb5f934a 100644 --- a/webapp/src/main/resources/templates/common.ftlh +++ b/webapp/src/main/resources/templates/common.ftlh @@ -42,7 +42,7 @@ <#macro footer>