Skip to content

Commit

Permalink
Fixes #197 Cannot Fetch unitCount
Browse files Browse the repository at this point in the history
  • Loading branch information
cardillan committed Jan 4, 2025
1 parent d1fd698 commit 376b8a0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Fixed

* Fixed wrong definition of `control color` instruction ([#194](https://github.com/cardillan/mindcode/issues/194)).
* Fixed wrong definition of `fetch unit` and `fetch unitCount` instructions ([#197](https://github.com/cardillan/mindcode/issues/197)).
* Fixed wrong expression optimization of `op sub` instruction ([#198](https://github.com/cardillan/mindcode/issues/198)).

## 2.7.3 - 2024-12-28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ private List<OpcodeVariant> initialize() {

add(list, V7, MAX, W, FUNC, Opcode.SETRATE, in("ipt"));

add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("unitCount"), res("result"), in("team"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("unitCount"), res("result"), in("team"), unused("0"), in("type"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("playerCount"), res("result"), in("team"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("coreCount"), res("result"), in("team"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("buildCount"), res("result"), in("team"), unused("0"), in("type"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("unit"), res("result"), in("team"), in("index"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("unit"), res("result"), in("team"), in("index"), in("type"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("player"), res("result"), in("team"), in("index"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("core"), res("result"), in("team"), in("index"));
add(list, V7, MAX, W, FUNC, Opcode.FETCH, fetch("build"), res("result"), in("team"), in("index"), in("type"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,24 @@ void generatesSetrate() {
@Test
void generatesFetch() {
assertCompilesTo("""
result = fetch(unitCount, team);
result = fetch(unitCount, team, type);
result = fetch(playerCount, team);
result = fetch(coreCount, team);
result = fetch(buildCount, team, type);
result = fetch(unit, team, index);
result = fetch(unit, team, index, type);
result = fetch(player, team, index);
result = fetch(core, team, index);
result = fetch(build, team, index, type);
""",
createInstruction(FETCH, "unitCount", var(0), "team"),
createInstruction(FETCH, "unitCount", var(0), "team", "0", "type"),
createInstruction(SET, "result", var(0)),
createInstruction(FETCH, "playerCount", var(1), "team"),
createInstruction(SET, "result", var(1)),
createInstruction(FETCH, "coreCount", var(2), "team"),
createInstruction(SET, "result", var(2)),
createInstruction(FETCH, "buildCount", var(3), "team", "0", "type"),
createInstruction(SET, "result", var(3)),
createInstruction(FETCH, "unit", var(4), "team", "index"),
createInstruction(FETCH, "unit", var(4), "team", "index", "type"),
createInstruction(SET, "result", var(4)),
createInstruction(FETCH, "player", var(5), "team", "index"),
createInstruction(SET, "result", var(5)),
Expand Down
4 changes: 2 additions & 2 deletions doc/syntax/FUNCTIONS_V7.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ Lookup units, cores, players or buildings by index. Indices start at 0 and end a

|Function&nbsp;call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Generated&nbsp;instruction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
|-------------|---------------------|
|`result = fetch(unitCount, team)`|`fetch unitCount result team 0 0`|
|`result = fetch(unitCount, team, type)`|`fetch unitCount result team 0 type`|
|`result = fetch(playerCount, team)`|`fetch playerCount result team 0 0`|
|`result = fetch(coreCount, team)`|`fetch coreCount result team 0 0`|
|`result = fetch(buildCount, team, type)`|`fetch buildCount result team 0 type`|
|`result = fetch(unit, team, index)`|`fetch unit result team index 0`|
|`result = fetch(unit, team, index, type)`|`fetch unit result team index type`|
|`result = fetch(player, team, index)`|`fetch player result team index 0`|
|`result = fetch(core, team, index)`|`fetch core result team index 0`|
|`result = fetch(build, team, index, type)`|`fetch build result team index type`|
Expand Down
4 changes: 2 additions & 2 deletions doc/syntax/FUNCTIONS_V7A.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ Lookup units, cores, players or buildings by index. Indices start at 0 and end a

|Function&nbsp;call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Generated&nbsp;instruction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
|-------------|---------------------|
|`result = fetch(unitCount, team)`|`fetch unitCount result team 0 0`|
|`result = fetch(unitCount, team, type)`|`fetch unitCount result team 0 type`|
|`result = fetch(playerCount, team)`|`fetch playerCount result team 0 0`|
|`result = fetch(coreCount, team)`|`fetch coreCount result team 0 0`|
|`result = fetch(buildCount, team, type)`|`fetch buildCount result team 0 type`|
|`result = fetch(unit, team, index)`|`fetch unit result team index 0`|
|`result = fetch(unit, team, index, type)`|`fetch unit result team index type`|
|`result = fetch(player, team, index)`|`fetch player result team index 0`|
|`result = fetch(core, team, index)`|`fetch core result team index 0`|
|`result = fetch(build, team, index, type)`|`fetch build result team index type`|
Expand Down
4 changes: 2 additions & 2 deletions doc/syntax/FUNCTIONS_V8A.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ Lookup units, cores, players or buildings by index. Indices start at 0 and end a

|Function&nbsp;call&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Generated&nbsp;instruction&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
|-------------|---------------------|
|`result = fetch(unitCount, team)`|`fetch unitCount result team 0 0`|
|`result = fetch(unitCount, team, type)`|`fetch unitCount result team 0 type`|
|`result = fetch(playerCount, team)`|`fetch playerCount result team 0 0`|
|`result = fetch(coreCount, team)`|`fetch coreCount result team 0 0`|
|`result = fetch(buildCount, team, type)`|`fetch buildCount result team 0 type`|
|`result = fetch(unit, team, index)`|`fetch unit result team index 0`|
|`result = fetch(unit, team, index, type)`|`fetch unit result team index type`|
|`result = fetch(player, team, index)`|`fetch player result team index 0`|
|`result = fetch(core, team, index)`|`fetch core result team index 0`|
|`result = fetch(build, team, index, type)`|`fetch build result team index type`|
Expand Down

0 comments on commit 376b8a0

Please sign in to comment.