WingedSeal / jmc

A compiler for JMC (JavaScript-like Minecraft Function), a mcfunction extension language for making Minecraft Datapack
https://jmc.wingedseal.com
MIT License
64 stars 10 forks source link

[BUG] Extraneous `run execute` #102

Closed Nico314159 closed 4 months ago

Nico314159 commented 6 months ago

Describe the bug

The following code segment will have a run execute in the compiled output, which should be optimized out.

To Reproduce [Steps to reproduce the behavior]

Compile the following code in JMC or on try-out

execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] expand {
    tf2.batch_number:@s = execute on passengers 
                          run tf2.batch_number:@s 
                        = index::i * 1.0;
    team join player_motion.no_collide;
    tag @s remove tf2.new;
}

Expected behavior [A clear and concise description of what you expected to happen.]

I expected it to compile to

execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] store result score @s tf2.batch_number on passengers store result score @s tf2.batch_number run data get storage tf2:index i 1.0
execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] run team join player_motion.no_collide
execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] run tag @s remove tf2.new

Actual behavior

Instead, it compiles to

execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] run execute store result score @s tf2.batch_number on passengers store result score @s tf2.batch_number run data get storage tf2:index i 1.0
execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] run team join player_motion.no_collide
execute as @e[type=axolotl,tag=tf2.new,tag=tf2.no_respawn] run tag @s remove tf2.new

Note how the first line contains a useless run execute.

Screenshots

Screenshot 2024-05-27 at 13 18 10

Desktop

WingedSeal commented 4 months ago

Fixed in 76990b04a57c2be59061e83c10d4ca55a84ca848