armoha / euddraft

System for pluginizing eudplib codes.
Other
29 stars 4 forks source link

[epScript] Reduce temporary variable for argument #95

Open armoha opened 1 year ago

armoha commented 1 year ago

Example 1

if (!MemoryEPD(epd + 0x5C/4, Exactly, 0)) {
}

Current behavior (~5T 1C 9A)

  1. Create temporary variable for epd + 0x5C/4 (2T 5A)
  2. Patch condition by substituting temporary (2T 4A)
  3. Run if statement (1T 1C 0A when target exists, 2T 1C 2A when target is empty)

Ideal behavior (~3T 1C 5A)

  1. Patch condition by substituting constant and adding variable VProc(epd, list(SetMemory(cond + 4, SetTo, 0x5C/4), epd.QueueAddTo(EPD(cond + 4)))); (2T 5A)
  2. Run if statement (1T 1C 0A when target exists, 2T 1C 2A when target is empty)

Example 2

const target = epdcunitread_epd(epd + 0x5C/4);

Current behavior (~4T 12A)

  1. Create temporary variable for epd + 0x5C/4 (2T 5A)
  2. For function call, set parameter by substituting temporary (~2T 7A)
  3. Run function body

Ideal behavior (~2T 8A)

  1. For function call, set parameter by substituting constant and adding variable VProc(epd, list(param.SetNumber(0x5C/4), epd.QueueAddTo(EPD(param.getValueAddr())))); (~2T 8A)
  2. Run function body

Similar to https://github.com/armoha/euddraft/issues/74 , this kind of optimization is only possible on epScript side.